Skip to content

Instantly share code, notes, and snippets.

code-later / gist:719848
Created November 29, 2010 11:25
Load a project specific .irbrc in your Rails 3 project
View gist:719848
# Add this method the MyApp::Application class (in config/application.rb)
def load_console(sandbox=false)
project_specific_irbrc = File.join(Rails.root, ".irbrc")
puts "Loading project specific .irbrc ..."
load(project_specific_irbrc) if File.exists?(project_specific_irbrc)
runemadsen / description.markdown
Created September 26, 2011 15:23
Reverse polymorphic associations in Rails
View description.markdown

Polymorphic Associations reversed

It's pretty easy to do polymorphic associations in Rails: A Picture can belong to either a BlogPost or an Article. But what if you need the relationship the other way around? A Picture, a Text and a Video can belong to an Article, and that article can find all media by calling

This example shows how to create an ArticleElement join model that handles the polymorphic relationship. To add fields that are common to all polymorphic models, add fields to the join model.

kevinSuttle /
Last active November 10, 2023 15:25 — forked from lancejpollard/
List of Usable HTML Meta and Link Tags
danneu / benchmark
Created October 29, 2012 23:04
Ox vs Nokogiri: DOM and SAX parsing comparison
View benchmark
# I'm no benchmark guru. Just did a bunch of:
$ time ruby <filename>
# Note: This is just an 80mb XML file with 38,000 nodes.
ox_dom.rb 4.56s user 0.78s system 93% cpu 5.714 total (550mb)
ox_dom.rb 4.58s user 0.79s system 87% cpu 6.126 total (550mb)
ox_dom.rb 4.60s user 0.80s system 87% cpu 6.140 total (550mb)
nokigiri_dom.rb 11.75s user 1.02s system 94% cpu 13.518 total (895mb)
nokigiri_dom.rb 11.36s user 1.02s system 93% cpu 13.211 total (895mb)
tadas-s /
Created April 18, 2013 08:58
MySQL database rename script
# Disclaimer - make backups, use at your own risk.
# Based on this comment:
# Views and stored procedures have to be done separately.
MYSQL="mysql -u root -pyour_password "
wbotelhos /
Last active December 12, 2019 12:08
Installing PhantomJS 1.9 on Ubuntu 12/14.xx x64/x86
sudo apt-get remove phantomjs
sudo unlink /usr/local/bin/phantomjs
sudo unlink /usr/local/share/phantomjs
sudo unlink /usr/bin/phantomjs
cd /usr/local/share
mobilemind /
Last active November 26, 2023 14:48
how to delete a git tag locally and remote
# delete local tag '12345'
git tag -d 12345
# delete remote tag '12345' (eg, GitHub version too)
git push origin :refs/tags/12345
# alternative approach
git push --delete origin tagName
git tag -d tagName
pmarreck / rb_snowflake_id.rb
Created December 20, 2013 03:20
An implementation of Twitter's Snowflake ID generation algorithm in pure Ruby. Note: I didn't rewrite the bits that run this as a service. This is just the algorithm.
View rb_snowflake_id.rb
require 'monitor'
class IdWorker
attr_reader :worker_id, :datacenter_id, :reporter, :logger, :sequence, :last_timestamp
TWEPOCH = 1288834974657
JamesChevalier / poly_to_osm.rb
Created February 8, 2014 00:35
This is my script to generate OSMs out of all of a country's POLY files.
View poly_to_osm.rb
#!/usr/bin/env ruby
Dir.glob('poly/*.poly').each_slice(50) do |group|
bp_wx = ''
group.each do |poly_file|
file = File.basename(poly_file, '.poly')
city, region = file.split('_')
bp_wx << "--buffer bufferCapacity=50000"\
" --bp file='poly/#{city}_#{region}.poly'"\
sangeeths / github-to-bitbucket
Created March 10, 2014 15:24
Forking a Github repo to Bitbucket
View github-to-bitbucket
Go to Bitbucket and create a new repository (its better to have an empty repo)
git clone
cd myforkedrepo
Now add Github repo as a new remote in Bitbucket called "sync"
git remote add sync
Verify what are the remotes currently being setup for "myforkedrepo". This following command should show "fetch" and "push" for two remotes i.e. "origin" and "sync"
git remote -v