Fork me on GitHub

Zeke Sikelianos

Mumblings from the code swamp. Find my more interesting online-ness at zeke.sikelianos.com.

Encouraging Users to Drop IE

After a few days struggling to make a recent project look right on Internet Explorer, I set about trying to find a graceful way of notifying users that they need to upgrade. I played with a shit-ton of pre-existing solutions, but in the end I decided to whip up something much more basic that I can easily integrate into any Rails app:


“If you’re not familiar with what makes a valid Rack application it basically comes down to an object that receives the “call” method with exactly one argument, the environment hash, and returns an array with exactly 3 elements. The status, headers and body.” Pancake Documentation

Mac Users: Extract Frames from Animated GIFs with Preview.app

Animated GIFs are kind of a relic these days, but when you need to crack one open and get at its individual frames, you might think Photoshop is that way to go. Alas, Photoshop doesn’t support animated GIFs (any more).

But! It turns out Preview.app does. You just open the GIF and drag the frames right out of it. Handy.


Testing HTTP Basic Auth in Sinatra

Snagged from http://www.sinatrarb.com/faq.html#test_http_auth


HTML Form Submission with button/image Combo

When you submit an HTML form using <input type="image">, the x and y coordinates of the image get passed along as GET parameters in the URL. I can never seem to remember how to avoid this, so here’s a snippet for reference:


script/console for Sinatra

Wishing you had a Rails-like console for your Sinatra app? Welp, zapnap has implemented a nice solution into his vanilla sinatra-template on github, based on code from barking iguana. Happy consolation!

Update: Check out racksh, a console for Rack-based ruby web applications, including Rails, Merb, Sinatra, Camping, Ramaze, or even your own framework.


Lessons learned on my first date with DataMapper

Today I started playing around with DataMapper, an up-and-coming ORM that’s popular among the Merb/Sinatra kids, and one that’s making its way into Rails 3 as an alternative to ActiveRecord. Here are some notes from day one:

Different Database Column Defaults: The default String size is 50 characters, unlike ActiveRecord which defaults to 255 (for MySQL, anyway)

Strategic Eager Loading: At first I was dismayed to find there’s no :include option for nesting associations in a query. Then I realized it’s not necessary! DataMapper will only issue the very bare minimums of queries to your data-store that it needs to. Read more about it here.

Serialization: DataMapper is intended to have a lean and minimalistic core, which provides the minimum necessary features for an ORM. In order to successfully convert an array of objects to JSON (or XML or CSV or YAML), you’ll need to get the dm-more gem and drop a require 'dm-serializer' in your app.

Scopes: As with eager loading, DataMapper is smart about reducing the number of queries it makes. Check this out:

So far, I’m finding DataMapper to be smart and intuitive. Here’s to day two..


Sinatra Extension: Ratpack

As soon as I started using Sinatra, I felt naked without those handy ActionView helpers from Rails like stylesheet_link_tag, javascript_include_tag, link_to, etc. So today I read up a little on how to write Sinatra Extensions and put together the beginnings of a gem to address the need.

Here are the methods implemented so far..

  • content_tag
  • convert_to_list_items
  • image_tag
  • javscript_include_tag
  • link_to
  • stylesheet_link_tag
  • tag

So if you’re a Rails developer that’s getting familiar with Sinatra, you may want to check Ratpack out: http://github.com/zeke/ratpack/


“Criticism may not be agreeable, but it is necessary. It fulfills the same function as pain in the human body. It calls attention to an unhealthy state of things.” Winston Churchill

Access the 'clicked' item within a jQuery function.

I always seem to forget this, but the proper syntax is $(this):


New Rails Plugin: Autoform

I’m currently working on a Rails project that has lots of models that all need basic CRUDability, but the forms and views don’t need to be fancy, as the app is used primarily as an XML webservice. We need the CRUD so we can tweak content here and there, but it’s not public-facing. I got tired of having to update the forms every time I wrote a migration, so I created Autoform.

Autoform is a Rails plugin that makes it easy to dynamically auto-generate a form for an ActiveRecord object. It cycles through all columns in the model and generates semantically correct form output with labels. Think of Autoform as a scaffolder that automatically keeps your forms current as you make changes to your model.

Check it out at github.com/zeke/autoform


[Flash 9 is required to listen to audio.]

A Coupla Handy Tools for working with XML

Camino
If you’re on a Mac, the Camino web browser is a good buddy. It’s great for those times when you want a fast, lean browser without the frills. One of its many perks is that it displays XML nicely (unlike Firefox and Safari), with syntax highlighting and little toggle buttons for expanding and collapsing elements.

hurl
One of the coolest things to come out of this year’s railsrumble competition is hurl. It’s a simple tool that helps you test APIs. “Choose the request method, customize headers and POST parameters, add basic authorization, and even follow redirects. Then view the nicely formatted request and response.” Check out the demo screencast for a quick rundown.


Adding non-columnar data to Rails XML and JSON feeds

ActiveRecord offers handy to_xml and to_json methods for converting AR objects to XML or JSON format. Today I discovered that you can easily add values from model methods to the output, like so..

See Module::ActiveRecord::Serialization for more info.


How to Suppress Adobe Debugger's Exception Alerts

If you’re a Flash developer and have the Debugger Version of Adobe Flash Player installed, you’ve probably noticed that it periodically pops up annoying alerts when you browse the web. They are the result of poor exception handling by the Actionscript/Flex programmers of the world. To disable the alerts, open up your mm.cfg and add this line:

SuppressDebuggerExceptionDialogs=1

You’ll probably need to restart your browser for the change to take effect. That’s it!


Page 1 of 2