This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo | |
private | |
def self.hello | |
puts "hi" | |
end | |
end | |
Foo.hello # => "hi" | |
class Bar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Array | |
def second | |
self[1] | |
end | |
def third | |
self[2] | |
end | |
def forth |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[alias] | |
up = !sh -c 'git pull && git --no-pager log --pretty=format:\"%Cred%ae %Creset- %C(yellow)%s %Creset(%ar)\" HEAD@{1}.. && echo' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(' && ') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# List what ports are in use on OS X | |
sudo lsof -iTCP -sTCP:LISTEN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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>'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
OlderNewer