Tag Archives: ruby

Recursive custom to_json in Ruby for arrays of objects or nested objects

Let’s say we want to customize the json template for an object: class User def to_json super(:except => [:password, :password_salt, :encrypted_password, :last_sign_in_ip, :updated_at, :current_sign_in_ip, :remember_token, :reset_password_token, :remember_created_at]) end end Apparently this is fixed in Ruby 1.9 but for now only converting an object [...]
Posted in Software | Also tagged , , , , | Comments closed

Deduping join data in ruby based on multiple attributes

In the past I created an app using Rails built in HABTM and no unique index on the join tables. I’m more into the has_many :through choice today. In order to migrate my data with a unqiue index, I had a bunch of de-duping to do. It was a bit trickier than [...]
Posted in Software | Also tagged , , , , | Comments closed

More cool stuff with ruby’s tap method

I had to write up a quick data processor at work today and I wanted a decent output at the end of execution. The ruby tap method came in handy here. class AssetDeliveryPopulater   def self.populate results_text = [] asset_secrets_count, asset_delivery_count, asset_not_found_count, asset_delivery_creation_errors = 0,0,0,0   Email.all.tap{|emails| [...]
Posted in Software | Also tagged | Comments closed

Tap before you squash

Tap is a pretty awesome ruby method I recently discovered. Let’s say I have the following request: post '/api/v1/users/', params.merge(:sig => Authentication.calculate(TestAuthData.secret_access_key,params.to_query) ).to_json I realize [...]
Posted in Software | Also tagged , | Comments closed

RSpec 2, Sinatra and Mongoid example

I spent yesterday coding a very abbreviated version of an authentication service that uses Sinatra, Mongoid and RSpec 2. It took more than a couple hours because there are so many outdated code samples on the web that just don’t work. I put my code up on github for people to see. [...]
Posted in Software | Also tagged , , , , | Comments closed

Country Seed Data for your Rails App

Never go looking for basic country seed data again: [ { :name => 'Afghanistan', :iso_two_letter_code => 'AF' }, { :name => 'Aland Islands', :iso_two_letter_code => 'AX' }, { :name => 'Albania', :iso_two_letter_code => 'AL' }, { :name => 'Algeria', :iso_two_letter_code => 'DZ' }, { :name => 'American Samoa', :iso_two_letter_code => 'AS' [...]
Posted in Software | Also tagged , , | Comments closed

B’more on Rails synopsis – April 2010

B’more on Rails is a community of Baltimore folks who use the Ruby programming language and the Ruby on Rails application framework. Check out our MeetUp page. Below is a brief synopsis from our April 2010 meetup. You can also download the slides here. Bundler is great for gem management. Among other [...]
Posted in Bmore On Rails Review, Software | Also tagged , , , , , , , , , , | Comments closed

Back links for your Ruby on Rails application

Here is a nice little helper I wrote to display back links: def back_link link_to "« Go Back", request.env["HTTP_REFERER"].blank? ? "/" : request.env["HTTP_REFERER"] end If you just use the HTTP_REFERER without checking if it’s blank, weird things can happen if someone lands on your page from an email, for example. If you enjoyed this post, make [...]
Posted in Software | Also tagged , | Comments closed

How to quickly set up a test for Twitter OAuth authentication from your local machine

Working with API’s such as Twitter from your local machine can be a pain. A problem that comes up is Twitter does not let you set your callback URL to hit your localhost. If you are working with OAuth on your local machine and want to test the user authorization flow, you are screwed. [...]
Posted in Software | Also tagged , , , , , | Comments closed

MySpace Statistics

I wrote scripts to look at over 2 million MySpace pages and extract data about over 80,000 bands on MySpace.
Posted in portfolio | Also tagged , | Comments closed