Skip to content

Instantly share code, notes, and snippets.

class CreditCardType < ActiveRecord::Base
acts_as_enumeration :lookup_name
column :name
def initialize(attributes = nil)
super
self.lookup_name ||= name.to_s.gsub(/[^A-Za-z0-9-]/, '').underscore
end
create :id => 1, :name => 'Visa'
class Foo
private
def self.hello
puts "hi"
end
end
Foo.hello # => "hi"
class Bar
@eric
eric / snippet.rb
Created November 19, 2008 20:14 — forked from defunkt/snippet.rb
class Array
def second
self[1]
end
def third
self[2]
end
def forth
<div class="header_wrapper">
<div class="header clearfix">
<h1><a href="/">Kashless</a></h1>
<ul class="menu">
<li><%= link_to "Find a free item", listings_path %></li>
<li><%= link_to "Give Away", new_listing_path %></li>
<%- if logged_in? && current_user.has_role?(:admin) -%>
<li><%= link_to "Users Admin", admin_users_path %></li>
<li><%= link_to "Invitations Admin", admin_invitations_path %></li>
require 'open3'
module ShellJob
@queue = :default
def self.perform(*args)
puts "$ #{args.join(' ')}"
Open3.popen3(*args) do |stdin, stdout, stderr|
puts stdout.read.inspect
end
@eric
eric / .gitconfig
Created January 11, 2010 22:14 — forked from kneath/._what.md
[alias]
up = !sh -c 'git pull && git --no-pager log --pretty=format:\"%Cred%ae %Creset- %C(yellow)%s %Creset(%ar)\" HEAD@{1}.. && echo'
namespace :bundler do
task :symlink_vendor do
shared_gems = File.join(shared_path, 'vendor/bundler_gems/ruby/1.8')
release_gems = File.join(release_path, 'vendor/bundler_gems/ruby/1.8')
cmd = %w(gems specifications).collect do |sub_dir|
shared_sub_dir = File.join(shared_gems, sub_dir)
"mkdir -p #{shared_sub_dir} && mkdir -p #{release_gems} && ln -s #{shared_sub_dir} #{release_gems}/#{sub_dir}"
end.join(' && ')
@eric
eric / ports.sh
Created April 21, 2010 18:40 — forked from defunkt/ports.sh
# List what ports are in use on OS X
sudo lsof -iTCP -sTCP:LISTEN
/*
* Bookmarklet for viewing source in iPad Safari
* Originally from http://www.ravelrumba.com/blog/ipad-view-source-bookmarklet/
*/
javascript:(function(){
var w = window.open('about:blank'),
s = w.document;
s.write('<!DOCTYPE html><html><head><title>Source of ' + location.href + '</title><meta name="viewport" content="width=720, maximum-scale=1.0, minimum-scale=1.0, initial-scale=1.0" /></head><body></body></html>');
# estimate the duration of an ALTER TABLE statement in mysql
# this code estimates the worst case, as most of the time, an ALTER will result in a table that is smaller than the original
percentage = 0
interval = 10
while(true) do
sleep(interval)
new_percentage = (File.size('#sql-5316_1a.ibd').to_f / File.size('moves.ibd').to_f)
change = new_percentage - percentage
intervals = 1.0/change