Tag Archives: ruby
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 de-duplication, habtm, removing duplicates, Ruby On Rails, unique index 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| [...]
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 [...]
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. [...]
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' [...]
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 [...]
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. [...]
MySpace Statistics
I wrote scripts to look at over 2 million MySpace pages and extract data about over 80,000 bands on MySpace.

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