Skip to content

Instantly share code, notes, and snippets.

@timothyklim
timothyklim / gist:900271
Created April 3, 2011 07:55
small expose
require 'active_support/all'
class Yeah
def initialize
@params = {"university_id" => 2, "id" => 3}
end
def method_missing(name, *args)
if name.to_s =~ /^find_([a-z]+)_id$/
find_id($1)
@timothyklim
timothyklim / gist:900292
Created April 3, 2011 08:31
application_controller.rb
class ApplicationController < ActionController::Base
protect_from_forgery
def method_missing(method, *args)
if method.to_s =~ /^find_([a-z]+)_id$/
find_id($1)
elsif method.to_s =~ /^find_([a-z]+)$/
find_id($1, :search_name_only)
else
super
@timothyklim
timothyklim / oauth.rb
Created April 26, 2011 06:55
2-legged OAuth
def authorize
%w{HTTP_AUTHORIZATION X-HTTP_AUTHORIZATION X_HTTP_AUTHORIZATION}.each do |http_header|
@request = request.env[http_header] if request.env[http_header].present?
end
if @request.present?
@oauth_request = OAuth::Helper.parse_header @request
if @oauth_request["oauth_signature_method"] == "HMAC-SHA1"
require 'oauth'
URL = "http://localhost:9090/oauth/check"
CONSUMER_KEY = "c740398d919e199ff222be3f75b916e6" # App.first.consumer_key
CONSUMER_SECRET = "414e9edf0dd2f24fc78c6da47cbd2dd9" # App.first.consumer_secret
TOKEN_KEY = "4db6a2ce6f1dc173e9000002" # User.first.id
TOKEN_SECRET = "f8b3cb31ad6351af93e47f1a962f808a4e46038d" # User.first.tokens.first.secret
~/Projects/Work/parabola on master(2e2bb5d) exited 30
parabola:master! % ./parabola.rb -d "14.02.03 21:12-12.04.05"
Error: Last date less than start date
~/Projects/Work/parabola on master(2e2bb5d) exited 30
parabola:master! % ./parabola.rb -d "11.02.03 21:12-12.04.05"
2011-02-03 21:12:00 +0000
2012-04-05 23:59:59 +0000
~/Projects/Work/parabola on master(2e2bb5d)
require 'nokogiri'
require 'open-uri'
i = 0
heroes = []
descriptions = []
puts "Parsing..."
while i+=1
require 'zlib'
require 'lzoruby'
module GZIP
def self.compress string, level
z = Zlib::Deflate.new level
dst = z.deflate string, Zlib::FINISH
z.close
dst
end
source 'http://rubygems.org'
gem 'rails', '>= 3.1.0.rc1'
gem 'spork', '>= 0.9.0.rc5'
gem 'ZenTest', '>= 4.5.0'
gem 'sqlite3'
gem 'sass'
class Group
include DataMapper::Resource
property :id, Serial
property :title, String, unique: true, length: 1..20
property :rules, String
SUPPORT_MODELS = %w[account offering city country]
SUPPORT_ACTIONS = %w[read create destroy edit]
@timothyklim
timothyklim / unicorn.rb
Created July 20, 2011 13:27
unicorn.rb
APP_ROOT = File.expand_path(File.dirname(File.dirname(__FILE__)))
if ENV['MY_RUBY_HOME'] && ENV['MY_RUBY_HOME'].include?('rvm')
begin
rvm_path = File.dirname(File.dirname(ENV['MY_RUBY_HOME']))
rvm_lib_path = File.join(rvm_path, 'lib')
$LOAD_PATH.unshift rvm_lib_path
require 'rvm'
RVM.use_from_path! APP_ROOT
rescue LoadError