Skip to content

{ Category Archives } code

Ruby Front-end for MailChimp

As part of a recent project, I implemented Ruby front-end to the API of the bulk-mailing service MailChimp. The main feature is the Session, which eliminates the need to insert the MailChimp session key into every API call. Example # Authenticate to MailChimp and subscribe a user MailChimp::Session.open( “user”, “pass” ) do |session| session.listSubscribe( “mailchimp_list_id”, [...]

ImageScroller

var imageUrls = [ "http://farm1.static.flickr.com/60/175826051_0f7f5994d8_m.jpg", "http://farm1.static.flickr.com/9/12743016_46f72fb7c3_m.jpg", "http://farm1.static.flickr.com/24/38814512_79009cfe95_m.jpg", "http://farm1.static.flickr.com/23/38814475_efd2cc3e58_m.jpg" ]; var parent = document.getElementById( “parent” ); var options = { loaderImageUrl: “http://svn.jonahb.com/js/trunk/loader.gif”, width: 415, height: 180, vertical: false, reverse: false }; var is = new ImageScroller( parent, imageUrls, options ); ImageScroller is a free Javascript/HTML control that scrolls images across a web page. Download For now [...]

FogBugz Subversion Integration on DreamHost

Tonight I tried to integrate my Subversion repository, hosted at DreamHost, with FogBugz. But, after I followed the installation instructions and checked in, FogBugz showed no links to changed files. I tracked the problem to wget. The FogBugz Subversion script uses the “–no-check-certificate” option, which became available in wget 1.10. The version of wget on [...]

Web Part Connections Test Parts

When I worked in the SharePoint group at Microsoft, I needed to understand ASP.NET’s web part connections so I wrote a collection of simple web parts that produce and consume common connection interfaces. They might help you to learn about connections and to test web parts that use connections. If you’re a developer new to [...]

Equirectangular Projection for Google Maps

In cartography, a projection maps the curved, two-dimensional surface of the earth onto a plane. There are lots of cool projections, from the familiar Mercator to the cordiform Werner to the Azimuthal equidistant, the projection in the United Nations emblem and my favorite. If you’re using the Google Maps API, you can replace Google’s standard [...]

DuplicateRecord

Ruby on Rails raises ActiveRecord::StatementInvalid when you violate a unique constraint. This leads people to write the following code: begin record.save! rescue ActiveRecord::StatementInvalid # assume a unique-key constraint has been violated end Unfortunately, StatementInvalid is also thrown when you access a non-existent table, violate a foreign-key constraint, or just submit a malformed query. In fact, [...]

ProcessInfo

ProcessInfo, a program for Windows, displays a list of processes and information about the selected process. It can help you understand what’s running on your computer and find malware. Download ProcessInfo 1.0 (requires Microsoft .NET Framework 2.0) or view the source.

Read/Write Lock in Ruby

In software (as in real life) a lock is a device that controls access to a resource. Here’s an example. Suppose you’re running two programs that both want to print something. Only one of these programs at a time should be able to access the printer — you don’t want two documents spewing forth at [...]

CookieRequirement

CookieRequirement is a Rails plug-in that lets you ensure that your users have cookies enabled. It works like David Heinemeier Hansson’s SSL Requirement: Include the module in your controller and declare the actions that require cookies by calling the cookies_required class method. Code and documentation are here.

Rails 1.2.2 Regression

While moving an application from Rails 1.1.6 to Rails 1.2.2, I ran into a nasty Rails regression. In my controller tests, I pass a hash of session variables to get, using symbols as keys: get :edit, {}, { :advocate_id => 1 } Later, in the implementation of edit I access the hash: session[ :advocate_id ] [...]