Alphanumeric sorting

iaian7 » blog   John Einselen, 8.10.09    

I came across a dark realisation last month – Javascript sorts lexicographically, not alphanumerically. After days of failed attempts and scouring the web for snippets, I finally came up with my own solution.

The first few lines are designed to prep results from an OS X file array (quite useful for developing Dashboard widgets in Dashcode!), but can be easily modified for other situations. The most important part to note is the .split(/(\d+)/) regular expression. This both splits and returns the string at every numeric section, giving us an array of alpha and numeric chunks. Each chunk is then compared; if one is greater or less than the other, the function returns the sorted value. If not, it keeps on checking to the end of (in this case) the file name. Not only does it allow for very specific alphanumeric sorting, but easily customizable results as well. For example, OSX places file names with a longer alphabetical string at the end before those with the same, but shorter, titles. This script accurately mimics the same behaviour.

function sortAlphaNum(a, b) { var x = a.split("/"); var y = b.split("/"); x = x[x.length-1].replace(/\\\s/g," ").split(/(\d+)/); // the split formatting is imperative, everything else can change y = y[y.length-1].replace(/\\\s/g," ").split(/(\d+)/); // the split formatting is imperative, everything else can change for (var i in x) { if (x[i] && !y[i] || isFinite(x[i]) && !isFinite(y[i])) { return -1; } else if (!x[i] && y[i] || !isFinite(y[i]) && isFinite(y[i])) { return 1; } else if (!isFinite(x[i]) && !isFinite(y[i])) { x[i] = x[i].toLowerCase(); y[i] = y[i].toLowerCase(); if (x[i] < y[i]) return -1; if (x[i] > y[i]) return 1; } else { x[i] = parseFloat(x[i]); y[i] = parseFloat(y[i]); if (x[i] < y[i]) return -1; if (x[i] > y[i]) return 1; } } return 0; }

Lastly, we ask Javascript to sort an array using the above function, like so:

array = array.sort(sortAlphaNum);

Let me know if you use this in any projects, I’d love to know! emoticon

bookmark  

Widget.System Limitations

iaian7 » blog   John Einselen, 26.09.09    

Development of the Chroma dashboard widget has been moving along nicely, but I hit a pretty catastrophic error today; the library file was getting truncated. A lot of changes have been made recently to the formatting of the data, so the most plausible culprit was myself. Surely, somewhere in the reading, modifying, and writing back to the library file via command line interface, I’d screwed something up.

After 4 hours trying innumerable possibilities, hacks, tests, and workarounds (all of them failed), I discovered it wasn’t me at all; my macbook was limiting the outputString from widget.system to 4096 bytes. What truly makes this bizarre is that the Mac Pro at work does not have this same limitation, and they’re both Intel 64bit processors running the same version of OS X. I still don’t know how this is even happening; most online sources claim running widget.system asynchronously removes the limits. Well, I now have plenty of proof that says otherwise!

The good news? I finally worked out a solution. Using the myCommand.onreadoutput function, I was able to add each block of 4096 bytes back into a full length javascript string. Perhaps not the most elegant solution, but should work across all systems.

var libString = "";
var commandString = "cat /directory/file.txt";

function getLibrary(event) {
	var myCommand = widget.system(commandString, processLibrary);
	myCommand.onreadoutput = processLibraryConcat;
}

function processLibraryConcat(event) {
	libString = libString+event;
}

function processLibrary(event) {
	// library processing should use libString (full length output)
	// instead of event.outputString (truncated to 4096 bytes)
}
bookmark  

Dashboard Development

iaian7 » blog   John Einselen, 14.09.09    

Last summer I had been working on a project that required a rather large amount of lipsync animation in a short amount of time, and developed a workflow involving Papagayo, Lightwave endomorphs, and some custom javascripts to translate between the two.

Hobbled somewhat by the lack of system integration and javascript security limitations, I had to copy blocks of phoneme frames in, and copy out blocks of translated keyframe data. The project died down, and I didn’t need to revisit the workflow till early this summer. That’s when I finally gave widget programming another chance, and got into using Dashcode, part of Apple’s free Xcode development suite.

Let me preface by saying — Dashcode has issues. Long standing issues that haven’t been fixed for quite some time, even through several update cycles. Colour values inexplicably shift during editing object properties (degenerating into a completely different value headed inexorably south), objects loose properties, elements take on properties from other elements deleted the week before, etc. But once that’s out of the way (and you learn to watch out for disappearing styles), it’s a pretty cool system. Not only did it open up doors for interfacing with basic system events (dragging and dropping files, could it really be any easier to translate a .moho file?), it opened up full access to the OSX command line as well. All using a familiar javascript basis.

And that’s the back story to how I started developing a small collection of utilities for Mac OS X, and my earlier post introducing iaian7.com/dashboard. It’s mostly stuff I’ve needed at work — first the lipsync conversion utility, then a widget to help calculate screen resolutions and ratios.

Yesterday I finished up the the latest addition to my collection; first public release of Chroma, a basic colour conversion utility and swatch library. I also posted everything to macupdate.com I certainly didn’t expect such a dramatic response, but traffic has increased substantially with scores of downloads for each widget just within the first hour or two. I sure hope I don’t regret this, there simply isn’t time for me to keep taking on more projects like this! Even so, I really hope they prove useful to others, and plan on continued development as I have time. Hope you enjoy!

Prowler — interface for the Prowl push notification platform, letting you send notes instantly to your iPhone or iPod Touch.

Sheets — generate sprite sheets from image sequences or group selections. It requires an ImageMagick command line installation, but I have yet to find a good Photoshop solution for this, and Sheets doesn’t crash as often. Oh yeah, I went there!

Chroma — a colour management and conversion utility. The library is a little basic so far, but I’m hoping to continue developing the feature set to include more features and better management. The data is all there (swatches are given a group title and name when added), but how it looks and performs is yet to be defined. For now, I’m just excited to finally have a good solution for colour swatches and web development.

Feel free to head over to MacUpdate.com to rate and leave comments for Lipsync, Ratio, Prowler, Sheets, or Chroma.

bookmark  

Syncing via Dropbox

iaian7 » blog   John Einselen, 11.08.09    

I’ve been a long time fan of Dropbox. Not only does it let me sync files across computers, but it does it seamlessly and reliably (I’ve never once had a file corrupted or lost). A free account gives you 2Gb of cloud-synced storage space, with updates pushed to any connected computer running the menu bar app. Paired with Fruux for automatic address book, calendar, and bookmark syncing, you can get a fair bit of Apple’s expensive MobileMe service for free.

However, one problem with using Dropbox as a sync solution is that it doesn’t sync multiple locations – only a single Dropbox folder located, usually, in your user directory. Some applications have catered to this, such as 1Password’s development of the Agile keychain. Most, however, do not.

The answer? Symbolic links. Based on the excellent tutorial from SmileOnMyMac.net, this is a sample terminal command for setting up the Snippet database to sync using Dropbox (all one line):

ln -s ~/Dropbox/Sync/SnippetDB.plist ~/Library/Preferences/SnippetDB.plist

Make sure you copy the actual plist file to your Dropbox/Sync/ folder first, but that should take care of it. I’ll be running through a few tests in the next few days to make sure it operates smoothly. If my past experience with Dropbox holds true, it’ll be completely painless. It should also work with any similar application setup, just update the above directory links with the appropriate file locations (keeping in mind that not all apps play nicely when files are updated while still opened on another computer).

Addendum 2010: Microsoft’s Live Mesh offers 5Gb free storage, and syncs any folder you select. However, it’s exceedingly cumbersome, requires a full dock-based app to be running at all times, and is easily confused when content changes. I’ve never used it for syncing preferences or databases across computers, because it’s nearly unusable just for storing files.

Addendum 2012: Dropbox has added the ability to sync specific folders, but to keep things simple, I actually still use the symlink method! It lets me overview every pieces of synced data rather quickly in the same directory, and keeps things simple to set up on a new computer (I just keep a text document of the terminal commands needed to set up each folder).

Also, Google released Google Drive, in case you’re interested. Similar concept, different company.

Iaian7, 13.08.09

My elation was short lived when I discovered Snippet does not play well with a db.plist file that is changed outside of the app itself. The Dropbox sync technique holds true, Snippet just can’t take advantage of it.

Iaian7, 27.10.09

Here’s an example command line for syncing YummyFTP bookmarks:

ln -s ~/Dropbox/Sync/YummyFTP ~/Library/Preferences/Yummy\ FTP/Bookmarks

Iaian7, 4.12.09

Command line for switching Lightwave’s plugin folder to Dropbox:

ln -s ~/Dropbox/Sync/LightWave3D ~/Library/Application\ Support/LightWave3D

adijuh.com, 19.01.10

Dropbox is designed to simply sync files and folders, but you can use it to trigger other tasks by simply adding files

Iaian7, 26.02.10

To sync Quartz Composer plugins, move your Library/Graphics folder to your Dropbox, then enter the following in Terminal:

ln -s ~/Dropbox/Sync/Graphics ~/Library/Graphics

bookmark  

New Widgets

iaian7 » blog   John Einselen, 31.07.09    

I’m not much of a programmer; it’s a hobby from time to time (especially when I’m bored), but not exactly a talent. My dev cycle consists mostly of mashing together code till it stops crashing all the time. Not exactly the most efficient way to work, but the best I can hack together given my non-programmer logical processes and limited knowledge of javascript. That said, the past month I’ve been able to refine some basic utilities and expand my programming knowledge a bit; as of this evening, there’s a new section here on the site (iaian7.com/dashboard) and I’ve posted my first official widgets. Enjoy!

Ratio – an Apple OS X Dashboard widget for calculating common screen resolutions of various sizes. Includes presets for HD, NTSC, PAL, Apple iPhone, Microsoft Surface, Fullscreen and Widescreen PC, and more. My first actual widget, so it’s been redone a few times… certainly a learning experience, but I’ve found it pretty useful myself.

LipSync – a dashboard widget for converting Moho format phoneme animation files into Lightwave envelopes or After Effects keyframes. Preston-Blair and Simplified Flash phoneme sets are included along with user definable sets. If your lipsync needs are basic, this is one of the faster (and cheaper) solutions I’ve found so far.

bookmark  

On the art of writing, and Twitter

iaian7 » blog   John Einselen, 12.06.09    

140 characters demands of an author a certain degree of terse eloquence. Regrettably, it often ends as merely terse; eloquence forgotten. – @iaian7

Such grievous pomposity aside (who quotes themselves so brashly?), it’s an important topic as communication moves online, and oratory fades.

I often wonder if in the pursuit of brevity and clarity, Twitter’s limitations could spur greater creativity, or even mastery of a language?

While one might decry (and rightly so) the short-form nature of the internet’s vast inanity, does the meticulous word play prove profitable?

Far more should be said, but as show of form I’ve kept these paragraphs precisely 140 characters. Leave your thoughts in the comments below!

bookmark  

New server

iaian7 » blog   John Einselen, 23.05.09    

Maybe not much of a visible change, but I’m switching the site over to a new host. GoDaddy has been surprisingly good (especially considering the price I paid and the amount of traffic this site generates), but it’s time to consolidate my hosting plans, and I need a server that supports IMAP. GoDaddy doesn’t, and the IMAP access at HostNine isn’t remotely reliable (host for my other sites, such as symboleffects.com, johneinselen.com, and greenteadiary.com). At the suggestion of Ryan Keberly (The Snowsuit Effort) I’m giving DreamHost a try.

Iaian7.com will have some downtime this weekend, but should be back up and running by Tuesday!

Iaian7, 24.05.09

Amidst dismal DNS update speeds, and some pretty painful MySQL issues, the process went faster than I expected! The next few days will require a bit of testing, especially the new email system, but everything should be in place. Let me know if you come across any bugs.

bookmark  

Trailers

iaian7 » blog   John Einselen, 13.04.09    

Rian Johnson’s first full length film, Brick, made waves. It was a dark, brutal film noir based on, and filmed in, his old highschool – it also contained no foul language. Rian’s next film stars Adrien Brody, Mark Ruffalo, Rachel Weisz, and Rinko Kikuchi, in The Brothers Bloom. The trailers released so far hint at a similarly incredible mix; old-world characters, style, and panache, in a completely modern-world setting. I cannot recommend it enough, check out the latest international trailer on Apple.com!

Two foreign films have released trailers recently; The Lemon Tree is about a Palestinian widow and the Israeli official next door; the story, and performances, have won international accolades already. In Departures, a musician accidentally discovers (and grows to appreciate) the Japanese traditions of funeral preparation, in what is called an “astonishingly beautiful” and “sometimes comical” look at sacred Japanese heritage.

How could I not mention the long string of teasers and trailers for the upcoming Star Trek? While I’m still unsure of how it will all come together, there are some great actors involved (Zachary Quinto of the TV show Heroes and Simon Pegg of Shaun of the Dead,), and it promises to be a fantastic adventure ride.

On the animation front, Cloudy With a Chance of Meatballs and Astro Boy have both released trailers. Neither look likely to deliver the depth or richness of a Pixar film, and the latter seems to be milking the colours salmon-pink and cornflower-blue for more than they’re worth. I suppose I’m not the target audience here, but all the same, I’d rather kids see something of cinematic value (I probably shouldn’t be that harsh; Astro Boy has a chance at being good, and has had the decency to hop on the retro bandwagon).

Lastly, for fans of Office Space; director Mike Judge is tackling the workplace yet again, with the upcoming film Extract (fair warning; there’s a bit of language and even drug use in the trailer). Is it just me, or does Jason Bateman actually remind you of Ron Livingston in the former film?

bookmark  

Children's Heart

iaian7 » blog   John Einselen, 11.04.09    

Years ago in Indiana, I had the immense pleasure of learning from and working with the talented director Arthur Rasco. In 2005 his short film No Greater Love won awards across the country, including the International Family Film Festival: Best Dramatic Short and San Antonio Independent Christian Film Festival: Best of Festival (visit Ideal Images Entertainment for more on the film). He has a gift and passion for understanding a culture, even speaking the language, while working on productions like this. The past few years he’s been working with Samaritan’s Purse, travelling all over the world.

Well, he’s at it again; a new television series about the Children’s Heart Project! Started in 1997 to save two children in Bosnia with heart defects, the medical efforts of CHP quickly expanded to include Uganda, Nigeria, Mongolia, Honduras, and Kosovo; bringing children to the US for treatment, and providing state-of-the-art training and equipment overseas. Find out more and get the episode schedule on ChildrensHeart.tv

Play the trailer »

Jeanne Crumley, 16.06.09

I was very impressed with the program. I do feel it would be a good program to continue. Good Luck and God Bless you, this program, and your marriage as the two of begin your lives together as one in God’s will.

bookmark  

Religion vs. Spirituality

iaian7 » blog   John Einselen, 29.03.09    

More mature, insightful, and easily better read than myself, Sarah Wilson has posted an article this week titled The Deeper Side. Very interesting notes on the relationship between religion and religious rituals (which I’ve certainly seen as dead and lifeless!), and real, active faith. Essentially, the practice of discipline. Something I am sorely lacking, as any visitors to my apartment can probably tell you. Down to the most basic of life expectations, cleaning the bedroom, I fail. emoticon Discipline, like getting up in the morning (and the two are sadly linked), is exceedingly hard for me. Maybe someday I’ll grow up.

Today’s sermon, in continuation of the themes the past few weeks, was on… failure. Ever wonder why 120 people, after Christ’s death, resurrection, and ascension, would agree to wait patiently for an unknown event? Sure, they believed the promise that He would send something special, but it was because they knew they needed something special. They’d all failed. And knew it. It’s easy to pick on Peter (having so publicly denied Christ), but they’d all stumbled, fallen, and failed. Of course, the story ends (well, begins!) with the anointing of the Holy Spirit. Jesus keeps His promises, and it’s not because we’re good people… it’s because He loves us. Like in addiction counselling, recognising our failings, and truly desiring change, is the first step.

In my life, it’s easy to look back and see failure… lots of it. But it’s also easy to think it’s not that bad, and presume upon God’s grace. This will, I can only assume, be the topic of next weeks sermon!

In the meantime, I highly recommend reading When We Have Failed, What Next? by K. P. Yohannan. Truly someone I respect as a spiritual leader, having persevered through countless trials, and yet openly talks about his failings – weeping at the chances he passed up to minister to the untouchables of his home in India, and urging those around him to seek a deeper relationship with Christ. The book is markedly human, and rather comforting because of it.

bookmark