In praise of Smultron

Thu 14 Feb 08 21:58 | Tags: Mac, Programming, Software

I write this post in praise of what I think is one of the unsung heroes of development on the Mac; the Smultron text editor.

The shadow of TextMate looms large and dark, despite its ~$60 shareware fee. It's by far the most popular text editor among Mac coders, and it even has its own dead tree book. However, even though I'll occasionally go back and give it a try, I keep coming back to Smultron, and not only because it's free.

One document at a time? That's for sissies!

Smultron supports most of the features of competent text editors, such as tabbed editing (Smultron uses vertical drawers by default, but can be easily switched to use horizontal tabs), automatic line numbering, syntax coloring, integration with FTP programs such as Transmit, and so forth. But let me quickly run a couple reasons why I keep choosing it over others, including TextMate. (This list might not be totally fair, since it's been a while since I last tried TextMate.)

The most common uniquely Smultron feature I use is the Split Window feature. This lets you look at two documents, or possibly two different parts of the same document, in one window. The window is split horizontally if you just select the Split Window item from the View menu (or press Command-Apostrophe), but holding down the Option key while opening the View menu (or pressing Command-Option-Apostrophe) lets you split the window vertically, which I find much more handy in these days of triple-wide monitors. Editing a template, but can't remember what variables you've assigned to it? Open up the template in the left pane and the code where you've assigned the variables in the right. Made a complicated function and you can never remember the order of the parameters when you go to use it? Open the function definition in the right pane, and continue hacking away on the left. What a great feature!

Another great feature is the Advanced Find & Replace window. The regular Find feature (Command-F) just uses the simple standard Mac OS X find-and-replace tool, but the Advanced Find feature (Command-Shift-F) works with regular expressions. That in itself is not too fascinating, but what's cool is that it will build you a list of lines that match your pattern, and selecting the line will show you where that line appears in the document in the pane below. This is absolutely great for testing regular expressions before you do a replacement with them. It's also handy for testing a regular expression that I want to use in my code instead of on it; I just open up a new tab, paste or type in some sample data, then bring up the Advanced Find window and test and refine my pattern until it's perfect.

And did I mention it's free?

The Advanced Find window. Very cool.

It's lacking a few features, though, of course, most notably any auto-completion features of any sort -- though I personally don't miss 'em. Also, though it's possible to make your own syntax definitions for syntax coloring if one of the fifty or so included with the program doesn't suit your needs, or add one that someone else made, it's not very convenient; you have to literally use the Finder's Show Package Contents feature on the app itself and root around in there -- the process could be much easier.

Still, if TextMate isn't cutting it for you -- or maybe you just can't afford it -- it couldn't hurt to give Smultron a try. With my current job, I can now easily afford a more expensive, more feature-packed editor, but I'm still sticking with Smultron.

Get more great Ray Gun Robot content sent directly to your feed reader or email inbox! Subscribe today!
Feed icon Articles & LinksVia Email
Feed icon Articles OnlyVia Email

1 Comment | 0 Trackbacks | Digg this article | Bookmark with del.icio.us

 

Web hosting on Windows I: Not on my worst enemy

Thu 10 Jan 08 01:17 | Tags: Programming, Web Hosting, Windows

My new year's resolutions that I probably have no chance of not breaking are, in no particular order:

  1. Exercise more. This desk job isn't making me any thinner.
  2. Get my credit cards and student loan paid off and never go into debt again ever ever ever.
  3. Start posting regularly on Ray Gun Robot again.

But it's not like I've been lazy this whole time. Quite the contrary, I was working on the biggest web project of my entire life. Namely: the web site for The Eureka Reporter, a local newspaper.

Like all good projects of any size and substance, this was definitely a learning experience. We decided to go with the excellent Drupal content management system, which is made all the more amazing when you can code your own modules for it -- which I learned to do, with the help of a most excellent book entitled Pro Drupal Development. Maybe some time in the future I'll convert RGR to Drupal…

So the programming was not so much a challenge… it was just pretty voluminous, and learning the Drupal way of doing things was new. One particularly tricky thing was finding a way to convert the paper's printed pages to Flash files without cheating and just turning the pages into huge bitmaps (PDFs were nixed as being too easy to download). Well, we did it… I'm afraid just how is going to have to stay a bit of a trade secret.

There is one part of the project I'd like to talk about, however… The experience with getting the frickin' thing up and hosted and visible to the world. The Reporter's parent company is a rather large financial firm which has its own data center. (The newspaper is something of a pet project of the company's head honcho.) We were told (or, at least, had assumed that we were told) by our main contact at the Reporter that we would have access to a Unix- or Linux-powered server of some sort, but apparently there was a miscommunication somewhere, because very late in the project, once we finally got access to the parent company's IT department (the thickest stack of non-disclosure agreements I've ever seen and a few layers of corporate bureaucracy stood in our way), we found out they were a Microsoft-only operation; Windows 2003, Exchange email servers, MSSQL databases, IIS web servers, the whole bit -- the previous CMS that we were replacing had been written in ASP. So when they heard we wanted to run a PHP app with a MySQL backend running through LightTPD on some flavor of Unix or Linux, they were like, "you want to put what on our iron? Uh… no."

So then we scrambled to consider third-party hosting solutions, to which they replied, "you want to put our data on a server outside of our own four walls? Uh… no." Did I mention we were supposed to go live in less than a week at this point?

Well. At this point, I was expecting their IT guys to be real hard-you-know-whats, so I was pleasantly surprised when they got back to us with a compromise. For the initial launch, we could go ahead and use a shared hosting provider, just for the time being. However, they were going to set up a Windows 2003 server for us, and we were going to be expected to use that. Furthermore, we could install whatever software we wanted on it, but they would only be responsible for tech support to the extent of Windows itself; we were on our own as far as troubleshooting beyond that.

A fair compromise given the circumstances, I think; it meant we didn't have to rewrite Drupal in friggin' ASP or anything. However, it meant that I still needed to learn how to set up and run a Windows 2003 server, and fast.

I will go into detail into the trials and errors involved with this (and boy, were there a lot of errors), but I'll sum it all up here. In the Unix/Linux hosting world, I can use a mail server from here, a web server from there, a programming language from these people, a database by those people, and an operating system originally conceived by hippie-nerds in Berkeley decades ago, and even though all these things are made by different people, odds are they'll work together quite well. However, I've come to the conclusion that, on Windows, the most successful way to tackle the project is exactly as The Reporter's parent company was doing it; use Microsoft's mail server and Microsoft's web server and Microsoft's programming language and Microsoft's database on Microsoft's operating system. Once you venture outside of Microsoft's little bubble, any guarantees of interoperability go out the window. Now, of course, different people (especially those who have formal training in running Windows-based servers) will have different experiences, but as you read more about my personal experiences in the days to come, you'll see that it was quite simple for me to reach this conclusion.

Get more great Ray Gun Robot content sent directly to your feed reader or email inbox! Subscribe today!
Feed icon Articles & LinksVia Email
Feed icon Articles OnlyVia Email

0 Comments | 0 Trackbacks | Digg this article | Bookmark with del.icio.us

 

I want my server-side ECMAScript!

Sun 7 Oct 07 00:59 | Tags: Programming

I've been pretty busy recently between work and a night Japanese class I'm taking up at the local university, but nonetheless I've been considering starting a new programming project to kill time on the weekends.

I do other things at work, but what really puts bread on my plate is coding web scripts in PHP. PHP is fairly easy to learn and you can sure do a lot with it, and it definitely has one heck of a proven track record. But the more I use it, the more I find myself not particularly liking it. It's too easy to write bad code (I see some real whoppers coming out of the code of a certain other programmer at work… Alas, he's been there much longer than I have, and ostensibly has more experience…), its naming for functions and the like is irregular and often unpredictable, and the syntax for doing anything object-oriented is awful.

As I've mentioned before, I've really fallen in love with ECMAScript 4 since I learned the ActionScript 3 language (which is based on ECMAScript) for Flash CS3. I really wish I could do all my work in it. Unlike Python and Ruby, which have been encroaching on PHP's dominance as a server-side scripting language (especially Ruby), it has a familiar welcoming C-style syntax. Like Ruby, it's object-oriented to a fault. Compared to PHP, it has a higher learning curve, but maybe that'll work in its favor – it'll keep certain co-workers from somehow making it as far as they have.

Alas, it doesn't look like the world at large is as excited about the idea of server-side ECMAScript as I am. To the best of my knowledge, the only modern project implementing anything like this is with Microsoft's IIS web server, which allows you to use Microsoft's JScript variant of JavaScript (and thus would not have the new hotness that is included with ECMAScript 4). However, IIS is, of course, not free, and only runs on Windows.

My hope is that one day, a project will be announced to create an open source ECMAScript 4 interpreter which functions as an FastCGI program, allowing it to be used by Apache and lighttpd (the standard free web server and my personal favorite, respectively). But then again, maybe I just have to be patient; strictly speaking, ECMAScript 4 is still under development, and the most promising tools that such an interpreter could be built on, Mozilla's Tamarin and SpiderMonkey, still need to be fully adapted for ECMAScript 4 and then slapped together into one project first, and that's not expected to be finished any time this year. But suffice it to say that if anyone with more skills than me were to start such a project, you would already have at least one enthusiastic supporter.

Get more great Ray Gun Robot content sent directly to your feed reader or email inbox! Subscribe today!
Feed icon Articles & LinksVia Email
Feed icon Articles OnlyVia Email

5 Comments | 0 Trackbacks | Digg this article | Bookmark with del.icio.us

 

Flash, don't re-encode my MP3s!

Wed 8 Aug 07 21:00 | Tags: Programming

I'm gonna post this here in the hopes that the search engines index it and it saves other Flash programmers some time and frustration.

Flash requires that all sounds it plays (that aren't part of video clips, anyway) be in MP3 format. It's capable of converting sounds to MP3 for you, but you'll get greater control over the quality of the sound if you use a separate encoder program. (I personally like LAME.) You can then bring them into your Flash movie by simply dragging-and-dropping the file from the Finder (and presumably from Windows Explorer) on to the stage of your Flash project. It will then show up in your Library window. When you go to export your movie into a SWF file, Flash will then pass through your MP3 to the file without re-encoding it. …Sometimes.

Here's where the trick comes in. When you encode your MP3, you need to make sure that the file has a sample rate or sampling rate of 11025, 22050, or 44100 Hz. (Your encoder program might represent these as 11.025, 22.05, and 44.1 kHz instead.) What exactly a sampling rate is is beyond the scope of this article, but suffice it to say that larger numbers sound better, so you might as well use 44100 Hz for everything. (The sampling rate does not significantly affect the file size of the final MP3 file, though it may affect how long it takes to encode it.)

This is what we want to see.

Then, when you import the file into your Flash project, open up the sound's Properties window (click on its name in the Library window and click the "i" icon at the bottom of the window). If all is going well, you'll see a checkbox labeled "Use imported MP3 quality;" make sure it's checked. Now, when you export the SWF file, the MP3 will sound exactly the same as if you played it in your MP3 playing program of choice.

If you do not see that check box, then not having the proper sampling rate is the most likely culprit. However, I've noticed that even with some files with a 44.1 kHz sampling rate, Flash insists on trying to re-encode it, so it seems like there's some other mysterious factor. This is all frustratingly undocumented by Adobe, so far as I can tell, so I've had to find this all out by reading what problems others have had combined with my own trial-and-error.

Happy flashing!

Get more great Ray Gun Robot content sent directly to your feed reader or email inbox! Subscribe today!
Feed icon Articles & LinksVia Email
Feed icon Articles OnlyVia Email

0 Comments | 0 Trackbacks | Digg this article | Bookmark with del.icio.us

 

TFC Day 2: Levenshtein distance

Sun 29 Jul 07 00:56 | Tags: Programming

Today shall be Day 2 of my Totally Free Code series. It's an implementation of the Levenshtein distance algorithm in ActionScript 3, the programming language of Adobe Flash.

A little backstory. I work for Precision Intermedia, a "Multimedia Marketing Angency." (Of course, I write the content of this blog as an individual and it is in no way representative of the opinions of my company of the people that work there and so on and so forth.) One of our bigger clients is Patrick Wellman, the creator of a character called Mr Duz and the author of a new series of childrens' books featuring that character. (Mr Duz always does the right thing.) As part of creating Mr Duz's site, we created a series of games for the site, and I was charged with developing the games. I actually knew squat all about programming in Flash when I started working there a couple months ago, but I've picked it up pretty frequently. (I really love ActionScript's syntax; in programming terms, it's based on ECMAScript, is object-oriented almost to a fault, and is wonderfully strongly-typed.)

The most recent game involves spelling. I threw it together in a couple days after receiving some loose guidelines and a word list from Mr Wellman. You can play it here; click on "The Spelling Game" in the left frame of the page. (I'll leave it up to you whether you want to play a round or two of "Find Mr Duz" first; personally, I'd recommend it.) As you can see, the letters are randomly scrambled at the beginning of the game; the player then drags the letters into the correct order to unscramble the word.

There's a problem, though. If I just randomly shuffle a word's letters (quick aside: one way in which ActionScript falls short is that there's no simple way to shuffle an array), there's a possibility that the shuffled letters will come out exactly the same, or too similar to, the original sequence of letters. This is common on the shorter words; "Cat" would scramble as "Cat." "Truck" could scramble as "Trukc." When considering how to deal with this, I recalled reading about PHP's Levenshtein function while reading through the documentation of some of the roughly seven million functions available for that language. Named after its developer, a computer scientist in Soviet Russia, this algorithm calculates the "distance" (different-ness) between two strings (sequences of characters) by calculating how many removal, insertion, or substitution of characters would have to be performed on one word in order to turn it into another. Wikipedia gives an example:

…The Levenshtein distance between "kitten" and "sitting" is 3, since these three edits change one into the other, and there is no way to do it with fewer than three edits:

  1. kitten → sitten (substitution of 's' for 'k')
  2. sitten → sittin (substitution of 'i' for 'e')
  3. sittin → sitting (insert 'g' at the end)

This would be perfect to make sure that the scrambled version of a word was not too similar to its original. (Though, in retrospect, since the scrambled word will have the same number of characters as the unscrambled version, I could have used the less computationally-expensive Hamming distance algorithm instead… Oh well.) I could just run the algorithm on the original word and its scrambled version, and if the distance value is too low, then the strings are too similar and need to be shuffled again. However, ActionScript does not have a simple levenshtein() function already ready for me to use, like PHP does. And after a bit of searching, I couldn't find an implementation that anyone else had made. So, with a little help from the examples on this Wikibooks page, I made my own. Here it is in action.

It seems to work pretty well; its output matches the PHP implementation, at the least. The code of the algorithm itself could perhaps use a little more optimization; I'll leave that as a project for you. Here's the download for the entire Flash example above; the code for the algorithm can be found inside the "LevSample.as" file, at the bottom. (The Flash project itself can be considered public domain as well, though the Levenshtein algorithm part is really the only interesting part of it.)

Get the code (ZIP archive)

Keep coming back for more totally free code in the future!

Get more great Ray Gun Robot content sent directly to your feed reader or email inbox! Subscribe today!
Feed icon Articles & LinksVia Email
Feed icon Articles OnlyVia Email

0 Comments | 0 Trackbacks | Digg this article | Bookmark with del.icio.us