Text

BlackBerry WebWorks and the same origin policy

Say you’re coding a website, and you need to grab a section (perhaps a specific ID) of an external website to display on your site, via AJAX. You can’t just grab the page via AJAX because it violates the same origin policy, which states that you can only grab pages on your own domain.

As a workaround, people usually create a serverside proxy of the remote site. So if you’re working on example1.com, and you need the #content section of a page on example2.com, you’d create example1.com/example2 (or whatever you want to name it) which would just be a clone of example2.com. Then you’d be free to do whatever you want to it via AJAX, since it’s on your domain.

I was working on a BlackBerry WebWorks project recently, and needed to make an AJAX request to a website, and since with WebWorks you’re limited to HTML/CSS/JS and you’re not actually working on a website (but rather an app), the serverside proxy is impossible.

Luckily, even though the docs glazed over this point, you can add trusted domains in your app’s config file, and any domains in that list ignore the same origin policy. So you’re free to make any and all AJAX requests you want to any domain in your list. Just wanted to point that out since I learned it the hard way.

Tags: apps ajax
Text

Why would anyone use vim?

(Note: this is a post for vim newbies. If you’re an experienced user, you won’t find anything new here)

I recently switched to vim full time after years of asking myself that question. It seemed like a huge percentage of the better hackers I came across used vim, but all I could see was “no mouse, no IDE goodies, no deal.” Why would anyone subject themselves to that? Well, turns out, here’s why:

Vim is ubiquitous

For web developers who do a decent amount of SSH’ing and editing on a server somewhere, this is huge. Pretty much any Linux box you can find yourself in will have vim installed, and it’s a huge plus when that editor just happens to be the editor you use day in and day out and are comfortable with.

To take it a step further, you can even use vim key binding in Firefox, Chrome, bash, Thunderbird, etc. More about that at StackOverflow. It has a decades-long history and tons of fans, so you start to find that almost anything you do on a computer can be done in a vim-like fashion.

Vim is lightweight

Eclipse is a beast. Aptana’s right there with it. Netbeans isn’t much better. I found myself using Gedit for about a year just because it had a decent feature set (with plugins, that is) without feeling like a wildebeest. Then I made my way to Komodo Edit, which was dangerously close to wildebeest zone, but not quite there.

Vim starts up immediately and leaves a teeny tiny footprint. Maybe this isn’t important to some, but it really makes me happy.

Vim has everything I wanted in an IDE

One of the main things that stopped me from giving vim a serious look for so long is the false belief that it was just a simple editor with some crazy key bindings. Turns out, I couldn’t be further from the truth. After just a couple days of using vim, I had set up an environment with:

  • Tab autocomplete (for both project functions and language functions) complete with a function definition popup
  • The ability to jump from function call to function declaration and back easily
  • A sidebar function outline, automatic syntax checking (even including JS using JSLint and HTML using Tidy)
  • Spell check (for typing up blog posts like this one)
  • Tabs for switching files (although it seems basic, I was worried about using multiple files in vim, but it’s really great)
  • Project search (including replace and regexp support)
  • Smart indenting and auto-indent support
  • Just about any other IDE goodie that I wanted.

I really can’t think of anything I’m missing now that I would have with a different setup.

Vim has some really great plugins

I’ve found the plugin selection for vim to be a cut above that of most other editors. Some of my favorites are:

  • NERDCommenter - Comment out lines/chunks/selections of code in many languages, with your choice of comment types.
  • Gist - Create a GitHub Gist out of the document or selection. This is really, really awesome for me as I tend to send code a lot in IRC.
  • Syntastic - Automatic syntax checking for many languages. Opens errors up in a split window, highlights problematic lines, lets you jump from error to error, etc.
  • Command-T - Quickly open project files by typing any part of the filename/path. Named “Command-T” after the keyboard combo in Textmate which does the same. Much faster than using tree-based sidebar project file lists for me.
  • Zen Coding - Vim support for the amazing Zen Coding HTML/CSS shorthand expander.
  • Taglist - Displays a toggle-able sidebar of project or current file functions/variables for easy jumping.
  • Matchit - Lets you type % to match more than just the vim default of single characters (like if you want to jump from an HTML opening tag to an HTML closing tag, for example).

Vim’s modal editing really opens doors for amazing things

This is the main thing that keeps vim users happy. Vim has a “keep your hands on the home row” philosophy, and the only way that’s really possible is by making the main keyboard keys do more than just type letters. So, because of that, you have your regular old insert mode (same as other editors), but you also have a “command mode” that lets typing things execute commands rather than inserting text. Here are a few examples:

  • Type d$ to delete everything from the cursor position to the end of the line (d = delete and $ = end of line)
  • Type o to create a new line below the current line and enter insert mode on that line.
  • Type ci" to delete everything inside double quotes and enter insert mode (c = change, i = inside, and ” = what you want to change inside of)
  • Type gg=G to autoindent the entire file (gg = top of file, “=” = autoindent, and G = end of file).

This is crazy for awhile, but then it starts to not seem so crazy, then it starts to actually seem pretty sane, then it becomes amazing. For a quick intro to vim’s commands, type the vimtutor command at a terminal and go through that - it only takes about 10-15 minutes.

Vim is fun to use

All of this adds up to a really enjoyable experience. You have a lightweight, free, feature-rich, customizable editor that’s everywhere and lets you get crap done more quickly. I’m glad I gave it a shot.

Soon, I’ll be posting a guide to setting vim up for Drupal development. Check back!

Tags: Vim Apps
Text

A rundown of keyboards for Android phones

There are a ton of keyboards you can use instead of the Android default. Here’s my take on them.

Default (pre-gingerbread)

Nice, quick and simple. Light footprint and does decent job with the auto correction. No multi touch support, no alternate layouts, nothing fancy.

Swype

The current leader in the swipe typing category, in competition with the ShapeWriter and SlideIT. Does a pretty good, although I’ve found that recent-ish updates have vastly increased the size of the dictionary which means that it recommends stupid words that I would never say and have never heard. Also runs a bit sluggish on my phone. Also annoying is that it’s still in Beta which means that you have to download it through Skype’s website rather than the market and you must manually update.

SlideIT

Basically Swype but with slightly less accurate prediction/correction (at least in my experience). At least this one’s in the market, though.

ShapeWriter

In my experience, vastly superior to both Swype and SlideIT. Runs well on my phone and has good prediction. Downside is that it’s no longer on the Android market and there’s not even an official place to get it, so I had to resort to getting it through a random forum post, which is shady at best.

Smart Keyboard Pro

A great, flexible, multi-touch keyboard with a load of options, layouts, themes, etc. Did a pretty good job correcting my typing, even with me using two thumbs and going as quickly as possible. Not sluggish at all, themes look good, and the settings (although there are tons of them) are laid out logically. Fun to use.

Better Keyboard

Basically the same as Smart Keyboard Pro but with themes listed as separate market apps, not quite as many options, and (at least in my experience), slightly less accurate typing correction. Still worth a try.

SwiftKey

This is the one I’m using as my primary keyboard now. The thing that sets it apart is its contextual word prediction - it predicts what you’re typing based on which word makes the most since to go after the words before it, and also based on what you have typed in the past. This means that it predicts a word before you even start typing it, and lots of commonly used expressions can be typed out by just hitting the space key over and over. Also has good multi-touch and looks nice (although there’s only 1 theme). Runs a little sluggish on my phone but not enough to really complain.

Tags: Android Apps
Text

Useful Gmail Keyboard Shortcuts

There are a ton of keyboard shortcuts for Gmail, but a few stick out as being extremely useful:

  • j and k” - move the cursor down and up respectively
  • x” - check the checkbox next to the current message
  • o” - open message
  • e” - archive message(s)
  • <shift>i” - mark message(s) as read
  • r” - reply
  • a” - reply all
  • gi” - go to the inbox

Gmail has gotten much more enjoyable for me since I started using those a couple weeks ago.

Note that you have to enable Keyboard Shortcuts in Labs before you can use these.

Text

Making the most of browser custom search engines

Firefox, Chrome, and Opera (and maybe even IE, I’m not sure), all support pretty sophisticated custom search engines and shortcuts, allowing you to search sites pretty easily with just a shortcut key. These are useful for far more than you might think at first glance.

Let’s start boring and take the classic search example: Google. Say you want to search Google by typing “g searchterm” in your address bar (assuming browser didn’t already let you search Google). To do this, you’d create a new custom search, add the shortcut key (“g”) and the URL (http://www.google.com/search?q=%s - note that the %s will get replaced with your search term) and save it. Now type “g awesome” and you will Google the word “awesome.” Meh, right?

Here’s the good part: this isn’t just useful for searching. Since all you’re doing is just sticking a custom word or phrase at an arbitrary location in an arbitrary URL, you can get kind of fancy with it.

Here are some quick examples:

See what I mean? If you frequently type in URLs that have a predictable structure, this can be a huge time saver.

Bonus: you can just remove %s from the URL altogether to have instant keyword-accessible bookmarks.

Text

My top 10 Gedit plugins

Gedit can be a really awesome editor if you give it a few plugins and an open mind. Here are a few of my favorites.

  1. MultiEdit - This bad boy lets you edit in multiple locations by only typing once. You would be AMAZED at how useful this is.
  2. Snippets - One of the default plugins, this one is sort of hard to explain because it does so much. It lets you create shortcuts for code that are expanded when you hit tab, but it also includes support for placeholders, wrapping text in tags, and lots of other crazy stuff.
  3. Zen Coding - This one’s my own, but the magic really comes from the Zen Coding library. Zen Coding lets you write a sort of HTML and CSS shorthand which is evaluated and expanded. Here’s a video to explain.
  4. AutoTab - A really simple plugin that tries to figure out the tab width of the current document, and sets Gedit to use that.
  5. Line Tools - Gives you some shortcuts to do stuff like delete current line (CTRL+D), duplicate current line (CTRL+SHIFT+D), move selected lines up/down (ALT+UP/DOWN), etc. Really, really useful.
  6. Save Without Trailing Space - Automatically strips any whitespace from ends of lines when you save, and can also add a blank line at the end of the file upon saving. Really useful for patches to projects like Drupal which reject patches with extra whitespace.
  7. Tab Switch - Lets you switch between tabs using the commonly used CTRL+TAB and CTRL+SHIFT+TAB.
  8. Todo - Gives you a little window that displays any TODO items in your code comments, among other keywords. Really handy for catching up on what you were working on the day before or keeping track of places to improve.
  9. External Tools - Gives you the ability to execute any command on the current document or selected text. The possibilities are endless with this one. Perhaps you want to validate your PHP syntax or run your HTML through HTMLTidy or check your JS with JSLint, etc.
  10. Pastie for Gedit - Lets you create a pastie (see http://pastie.org) out of the currently selected text. Great for sending snippets to people quickly.
Text

A Gedit plugin for Zen Coding

Zen Coding is a pretty sweet set of tools for HTML and CSS that allows you to code things in a short of code shorthand, hit a magic button, and it expand to regular old code.

If you’re interested, here’s a demo video of it.

Sadly, there’s no official Gedit plugin for it, but Stuart Langridge hacked up a quick plugin a few months ago. However, it left a bit to be desired, and he didn’t seem to interested in maintaining it.

Therefore, I’m continuing development on it myself. I’ve fixed a few bugs and refactored a couple parts, and I’m hoping to turn this into a really nice plugin.

The code is all at GitHub, so feel free to download, drop it into your Gedit plugins folder (see the README file for more info), and try it out.

Text

MarkItUp Module for Chyrp’s Markdown

I just released a Chyrp module which implements MarkItUp’s Markdown set into Chyrp’s admin UI. It’s a really simple module and should work with Chyrp’s 2.0 release as well as the development releases at GitHub.

I’ve been using it for a couple weeks and have really enjoyed it. MarkItUp does a good job of finding a middle ground between raw code and WYSIWYG. If you’re not familiar with the editor, check out the demos.

Part of the beauty of MarkItUp is that the textarea can stay a textarea since it’s still just text. Most WYSIWYGs have to convert it to an iFrame to display bold text, italic text, images, etc., and that tends to get a bit messy and slow.

Anyways, if you’re a Chyrp user and you’re interested, check out the module. Also, here’s a screenshot: