Using Objects like Arrays in JavaScript.

In some situations, there can be a lot of advantages of using Objects instead of Arrays in JavaScript.
But some of programmers just don’t like objects! Here I don’t want to enter this debate about why or what! I just want to show you how to use a JavaScript Object like an Array!

So one of the very useful methods of Arrays (in JavaScript! otherwise it’s just the opposite side let’s say in Java for example!) is that you can get and set the length of any array any-time you want! then you can iterate between items inside the array and do literally any thing you want (you can do this because you know the length!).

And you can do the exact (well in pragmatic point of view) same thing in new versions of JavaScript with Objects too! using the Keys function:

Object.keys(obj);

But you should know that: first of all this wasn’t there in older versions of JavaScript (So your code wouldn’t function properly in old IE browsers for instance) and secondary, in proprietary / customized versions of JavaScript that aren’t that fast to get up to date with the advances of JavaScript, you won’t probably have it even in the future! (for example in Adobe products they are still using VERY old versions of JS in their VERY modern products), so what can you do about it?

Here is the solution!
If your problem is old browsers / IE, you can use sophisticated Amazon solution which will make the functionality available in most of the older browsers /IE:

Please note that you can use this function in other environments as well, but it would be a little bit over-kill since in embedded systems for example you may know most of the times the version of JavaScript and if it’s available or not so you don’t need to and probably shouldn’t check it!

And for the environments, where you know that uses an older version of JavaScript and/or this function doesn’t exist, you can write a very simple function yourself that will tell you the length of the object properties and the key values (since knowing only the length won’t help you, since you can’t access properties by index!) like so:


Here by passing an object to this function you will get back an array of Object property keys and of-course you can get the length from it like a simple array as well!

As you see it is a super simple and very short function!

See you later, mim, 😉

An Icon set for my InDesign plugin!

An Icon-set for my InDesign plugin!
An Icon-set for my InDesign plugin!

Here is the Icon-set I designed for my InDesign plugin! I guess I like the last one on the right in the second row more! what you think?!

Also I am still thinking about the name of the plugin but sofar I guess I’ll stick with the one I picked from the beginning! “InDesign ToolKit!” 😉

PS: Ah! And I designed a title logo as well! I’ll post it later! I didn’t need to design this many logos and icons, but I like to! :))

How to change app Icon in Processing (for Windows)

Processing 2 logo (Processing.org)
Processing 2 logo (Processing.org)

For one of my projects I was looking up to see how and if I can change the exported application Icon from Processing and surprisingly found nothing!
In-fact looks like that you can change Icons easily in Mac OS:

by using “Show Package Contents” and editing Info.plist or replacing sketch.icns with something more exciting.

But you are out of luck in Windows! although you can change the title bar’s icon using frame object like:

Although even that doesn’t work perfectly since you are limited to a 16×16 px icon which looks horrible (when you use alt-tab for instance in Windows, etc.) But anyway I didn’t find anything explaining how to change the application icon itself (that means even before running it), then I tried a few resource hacker/ editor tool-kits, like Resource Editor by Anders Melander, XN Resource Editor by Colin Wilson, to edit embedded icons later-on (after exporting the app) which kind of work (you’ll be able to just edit a few icon resolutions and your pretty much limited to the tools you have access to in the toolkit, and you have to repeat the task every-time you want to rebuild the app!), hmm! yeah but not very convenient! so I started digging in processing source files and found out you have a better chance if you edit and build it yourself but then I found even an easier way to do it!

Solution:

1. Create your Multi-page / multi-resolution Icon file (I did a lot of research to find a way to do this too! and only “good” options available (to my knowledge) are 1. using ImageMagick command line tool, and  2. awesome free GIMP (Even Adobe CS doesn’t have this options!) (you need: 16×16, 32×32, 48×48, 64×64, 128×128, 256×256 px versions of it in one file with color depth of 32)

2. Duplicate your *.ico file and change the extension of one of them to *.icns then rename both of them to “sketch” ( sketch.icns and sketch.ico )

3. In your processing folder (where you installed/copied the software) navigate to these two address:
(processing-2.2.x)\modes\java\application
and:
(processing-2.2.x)\modes\java\application\template.app\Contents\Resources

4. make a back-up of sketch.ico and sketch.icns files and replace the original ones with your new files (please be aware that it will change the icons in all the exported apps forever and not just for the current sketch -if there is any!-  (as far as you don’t restore your backed-up icon files))

5. That’s it! now if you export your app it will have the new icons (the file icon viewable from the explorer) and of-course to change the title-bar icon you should still use the code mentioned above.

– Alright! Please let me know if you had any questions or if it didn’t work for you, 😉
,mim

Hard at work on an InDesign plugin! (wait for beta testing release!)

In-Design plugin preview (one of the few dialogs of the UI)
In-Design plugin preview (one of the few dialogs of the UI)

Once I said:

Developing software is like panning for gold, you may find something that shines to you, but before getting it to market you just don’t know if it is real!!

I’m hard at work on my first InDesign plugin! and that’s why I’m not that active for the moment here! It’s been more than two weeks already that I started working on it and it’s going very well so far!

So I think I’ll be able to announce a pre-release beta testing call for it in few days (or weeks perhaps!), I worked really hard on it and the plugin with all its options won’t be available for free ( will be free during beta testing) but I will release a free version as well for folks just like myself who can’t afford paying for these kind of stuff! After all I hope to be able to sell a few of it after all these nights staying awake and writing codes till morning!

Please let me know if you are interested in the beta release.
Also I have to pick a name for my plugin! so please let me know if you have an idea about it! :))

Ok, back to work! 😉 have a good day!