Zeke Sikelianos
Mumblings from the code swamp. Find my more interesting online-ness at zeke.sikelianos.com.
Install the CoffeeScript TextMate bundle in Sublime Text 2
It took me a while to figure this out, so I figured I’d post it here:
On the differences between Zepto and jQuery
- Zepto doesn’t have
slideUp()orslideDown(), but it does haveanimate(). - Zepto doesn’t have
outerHeight()andouterWidth(), butheight()is equivalent tojQuery.outerHeight(false) - Be careful when using
.each()to iterate over a collection: jQuery allows use of theindexInArrayargument without the accompanyingvalueOfElement, but zepto does not.
The best source for Zepto documentation its README.
A shell script to bootstrap Textmate
I put together a little bash script that downloads all the bundles and themes I like to use. That way I don’t have to start from scratch the next time I’m installing Textmate on my machine.
Improved Javascript Logging Function
This a a javascript function for console logging that accounts for browsers that don’t have window.console. To understand where arguments comes from, see my previous post. Props to Will Fitzgerald for opening my eyes.
Ruby syntactic sugar: Object.in?
Close a jQuery autocomplete on ENTER keypress.
jQuery UI’s autocomplete opens up with suggestions, but maybe you don’t want them. By default you can hide the suggestions by tabbing away or hitting ESC, but the ENTER key does nothing. This snippet remedies that..
Rake Task: Configatron to Javascript!
Configatron is a “super cool, simple, and feature rich configuration system for Ruby apps”. It’s a great tool for keeping your apps DRY and your configuration free-spirited. But today it gets even better! This rake task exports your configatron config to a JSON hash and sticks in a native JS object, making it easy to give your static javascript files access to your app’s entire configatron config.
Remember: Given the public-facing nature of javascript, this practice will expose all the values in your config file to the world. If you have secret infoz in ur configatronz, work around it by moving the private stuff to a file that’s not loaded by the rake task.
Rails View Helper for Placehold.it
I just found placehold.it, a quick and simple image placeholder service. The requirements are a little touchy and it’s easy to construct a bad URL, so I wrote a little view helper for Rails that makes it a bit easier to use.
Dynamic background-image Strings with Sass 3 and Compass
I was having trouble defining a dynamic background image path in a Rails app using Sass 3 and Compass, because the quotes were getting encoded somewhere along the line during the conversion from Sass to CSS (presumably by Compass, as the sass-convert binary itself was not encoding the quotes). To solve the problem I started used Compass’s nifty image_url function..
Human-friendly model attribute labels with i18n and Formtastic
I’ve been using the awesome Formtastic FormBuilder DSL in all my Rails projects for a while now. It’s semantic nature makes it a great tool for generating HTML forms that are consistent and easy to style.
Today I discovered a new feature: you can define custom labels/names for your model attributes by adding a snippet like the one below to your project’s en.yml (or other internationalization file). Formtastic’s form.input helper will automatically use the values you specify there for your form’s labels.
Rails on a Plane!
Sometimes I’m coding on the move. During these lapses in internet connectivity I’ve typically had to comment out application features that require an internet connection, like a map or a Google Ajax Libraries API call. Today I whipped up a little solution to that issue. Drop the snippet below into application_helper.rb.
To pull up a web interface to the rdocs of all your installed gems, try this bash alias:
For an even fancier offline docs solution, check out the gembox gem.
Rails HTTP Basic Auth with Cookies on Heroku
Heroku uses config vars to keep sensitive data out of your code. Here’s a little setup I just made to get simple HTTP authentication into an app, with persistence across page views using the session. If you’ve set a heroku config var for the admin password, it will be used. Otherwise the default password is ‘secret’.