This stuff's the Adversaria

Splitting a string into lines in Javascript

I recently ran into the question of how to split a string into its component lines using Javascript without knowing beforehand what type of linebreaks were being used. After experimenting with the problem for a while, I finally arrived at the following solution (please note that I haven’t tested this cross-browser, but it works great in Safari/WebKit):

var lines = text.match(/^.*([\n\r]+|$)/gm);

Or the alternate version if you want to ensure that each line ends with a single linebreak rather than potentially have lines with multiple line breaks at their end (for my purposes this didn’t matter, but it might for yours):

var lines = text.match(/^.*((\r\n|\n|\r)|$)/gm);

The code assumes that text is a multiline string, and it utilizes the built-in Javascript String.match() method, which when performed with a regex with the global flag enabled will return an array of matches. The multiline flag makes sure that the regex matches at the beginning of every line, and the alternatives at the end of the regex match one or more linebreaks or the end of the line (if we are on the last line). The ultimate result of which is you split the string into a Javascript array with one line per index with the linebreaks preserved.

MobileMe email settings for Palm Pre

For the record, I finally bit the bullet and ditched my iPhone for a Palm Pre last week, and I’m extremely happy with the switch. I’ll post in more detail about why the Pre (and particularly WebOS) is freaking fantastic soon, but for now here’s a quick tip for other Palm Pre owners who want to configure their Pre to use MobileMe and can’t figure out why it keeps claiming you’re doing it wrong.

Although some people have apparently had luck using the automatic setup (where you just enter an email address and your password), I needed to use the manual setup in order to get it to use IMAP rather than POP. I think recent MobileMe accounts don’t even have POP activated by default, so maybe the age of my account is the problem. In any case, if the automatic setup booted you into POP3 rather than IMAP, delete the account and recreate it. From the screen where it asks for your username and password, open the menu and choose “Manual Setup” (why they didn’t just stick a Manual Setup button on the main screen where anybody could find it is beyond me, but I digress).

Here’s all the settings you’ll need to get rolling:

  • Incoming mail server: mail.me.com
  • Username: [your username, without @me.com or @mac.com]
  • Password: [your password]
  • Encryption: SSL
  • Port #: 993 (this should be automatically selected when you choose SSL)
  • Outgoing mail server: smtp.me.com
  • User Authentication: On
  • (Username and password will be auto-filled)
  • Encryption: TLS (this is what was probably screwing you up if you tried manual setup already)
  • Port #: 587

These settings work perfectly for me; hopefully they’ll save other Pre users with MobileMe the headache of “SMTP setup failed” errors.

One Crayon redesigned

After working on it for the past couple months, I’m very happy to announce that my freelancing site, One Crayon, has been redesigned from the ground up.

One Crayon now looks several orders of magnitude better than its original design; offers information and documentation for TEA for Espresso, TEA for Coda, and my other projects in a single unified location; and offers numerous other improvements like a news feed for keeping up to date with general One Crayon news and updates to my various software projects.

I’m not actively seeking freelance work thanks to a busy full time schedule, but I’ve been wanting to revitalize One Crayon for a while, not least because I wanted to start migrating some of my sites over to ExpressionEngine and One Crayon seemed like a good place to start.

There are still some rough edges (I’m looking at you, IE 6) and I haven’t added my website or writing portfolios, but I hope you’ll enjoy it anyway!

Estimates

Estimation

My other favorite time estimator is Stuffit, which back when I still used it would tell me that files would be completely unstuffed anywhere from -16,000 to 1,000,000,000 minutes. I never was sure how a file could have been unstuffed in negative minutes. Possibly Stuffit was trying to tell me that it had been unstuffed once before in the past, so why the hell was I opening it again?

Tibia or not tibia…

Tibia or not tibia...

Pete Joison’s artwork, in all its forms, makes me so very, very happy.

Coda 1.6 released, minor TEA for Coda update

Coda 1.6 has been released, and boy howdy is it exciting! Coda now includes a plugin architecture, including Cocoa plugins for people who need to be able to manipulate the interface and an easy-to-use plugin creator that will allow you to run plugins using command-line languages (similar to Textmate). This is a fantastic update, and as we start to see plugins being produced I don’t doubt that Coda will become more and more appealing for Textmate users who have been holding out. It’s certainly not as powerful and flexible (no tab stops, for instance), but the addition of user-generated plugins will certainly allow people to do great things.

Along with the update to Coda, I’ve updated the TEA for Coda bundle (find the most recent version on the dedicated TEA for Coda page); all of the scripts will now perform their actions in the active document even if multiple windows are open. Additionally Indent New Line should be significantly improved performance-wise. The scripts do now require Coda 1.6, though; if you’re running an old version of Coda expect buggy behavior.

I am unlikely to improve the TEA for Coda scripts anymore; my new goal will be to get the Textmate bundle items that I know and love into Coda using the plugin interface. This will necessitate learning some Cocoa, though (since some of the key actions require user input), so it may be a little bit of time before I’m able to get a working plugin up and running. In the interim (or until someone else does it), TEA for Coda is still the best way that I know to get Coda to behave like a full-blooded HTML editor.

TEA for Coda now Universal Binary

I’ve posted a minor update to my TEA for Coda bundle. This update includes two changes:

  • The HTML Tidy script is now a universal binary! At long last, our PPC friends can run it just as easily as those with newer hardware.
  • The Format with Em and Format with Strong scripts now keep your text highlighted rather than moving the cursor to the end. This is not only more congruent with Textmate’s behavior, but I think it makes better sense, particularly if you ever need to wrap the text in more than one tag (or wish to add a class name, or…).

You can get the update from the dedicated TEA for Coda page. Unless you use PathFinder or have some other way of viewing invisible files, you’ll need to replace the entire HTML directory (if you’ve made changes to the scripts, you should copy them into the new directory before replacing the old one). If you are comfortable with invisible files, then you’ll just need to replace the .lib directory and the Format directory.

Fiction Rule of Thumb

XKCD presents fantasy in a nutshell:

Minor TEA for Coda update

I’ve posted a minor update to my Textmate Emulation Applescripts for Coda and created an official TEA for Coda landing page since the scripts have been reasonably popular and I’d like people to be able to reach them without digging through blog archives.

The most recent release (2008-09-25) adds Insert BR, a script that inserts a <br /> element at the cursor (warning: will replace any selected text), fixes an annoying cursor position bug for anything that positions the cursor (cursor was previously overshooting by a character), and vastly improves on the behavior of Insert Open/Close Tag by allowing it to intelligently handle self-closing XHTML tags like img and link.

If you’re already using the scripts, you can update by replacing the HTML folder in your Coda scripts folder with the one in the download. Newcomers should follow the installation instructions in the Read Me.

StuffIt updates to version 13.0

Ah, StuffIt. The most perplexing rip-off in the recent history of software. I predicted we’d see version 13.0 before 12.0.4. Turns out I was bit conservative; the last 12.0.x update was 12.0.2.

For those who missed my previous hating on StuffIt, I’ll recap: do not buy it, and you probably shouldn’t update if you already own it. It is redundant, outdated, buggy, and a sad excuse for professional software whose company makes money by bumping the version number for every minor update. Back in the day, StuffIt was a must-have tool. Now it is an example of why giving complete control over a product to a marketing team is a terrible idea.

If you need a file compression and archiving solution, do yourself a favor and try something like Springy or BetterZip instead.

Track me like a stalker:
  • Tagamac
  • Twitter
Clicky Web Analytics