Skip to content

Instantly share code, notes, and snippets.

View tyler-smith's full-sized avatar

Tyler Smith tyler-smith

View GitHub Profile
Models
----------------------------------------
Invitation
has_many :comments
Comment
belongs_to :invitation
Controller
@tyler-smith
tyler-smith / gist:3661410
Created September 6, 2012 23:38
is_a_with_awesome?.awesome? ? ':)' : ':('
>> class Object
>> def is_a_with_awesome? *args
>> args.any?{|klass| self.is_a? klass }
>> end
>> end
=> nil
>> User.first.is_a_with_awesome?(User, AuditStatus)
=> true
>>
def update
@user = User.find(params[:id])
if @user.update_attributes(params[:user])
flash[:notice] = 'Dados salvos com sucesso'
redirect_to :action => 'edit'
else
flash[:error] = 'Falha ao salvar dados'
render :edit
end
@tyler-smith
tyler-smith / .gitignore
Created September 28, 2012 19:39
Install this gem and add this file to the project root
# ~/.gitignore but GH doesn't allow subdirs in gists
zeus.json
class Object
def x
"Object's x"
end
end
class MyClass
x = "hello"
end
@tyler-smith
tyler-smith / gist:3855764
Created October 9, 2012 00:13
Array#bifurcate
class Array
def bifurcate(&block)
self.each_with_object([[],[]]){|el, ary| ary[yield(el) ? 0 : 1] << el }
end
end
evens, odds = (1..10).to_a.bifurcate{|el| el % 2 == 0}
def rps_result(m1, m2)
return {:r => {:s => :r, :p => :p},
:p => {:r => :p, :s => :s},
:s => {:p => :s, :r => :r}}[m1][m2]
end
puts rps_result(:r, :p)
OAuth = require('oauth').OAuth;
class UVClient
constructor: (@subdomain, @api_key, @api_secret, @callback=null, @token='', @secret='') ->
@api_url = "https://#{@subdomain}.uservoice.com"
@consumer = new OAuth null, null, @api_key, @api_secret, "1.0", null, "HMAC-SHA1"
request: (method, path, params={}, callback=null) ->
# Allow users to not specify empty params
if typeof params is 'function'
@tyler-smith
tyler-smith / resque.ru
Created October 26, 2012 17:41
Run a Rails 2.3 server with Resque Server
#\ -p 3000
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__)))
require 'config/environment'
require 'resque'
require 'resque/server'
app = Rack::Builder.new do
use Rails::Rack::Static
use Rails::Rack::LogTailer
Please review.\r\n\r\n---------- Forwarded message ----------\r\nFrom: UserVoice <test@uservoice.com>\r\nDate: Mon, Jan 9, 2012 at 12:44 PM\r\nSubject: (rich@uservoice.com) A brand-new front end for your UserVoice\r\naccount next week\r\nTo: test+development@uservoice.com\r\n\r\n\r\nHi there,\r\n\r\nIn March, along with the announcement of UserVoice Helpdesk, we\r\nlaunched a brand-new front-end interface for UserVoice. You may have\r\nseen it...our account uses it, and every new signup since then has had\r\nit.\r\n\r\nWe\x92ve been moving accounts to this new interface over the last month.\r\nSo far, folks have no complaints. We\x92ve waited this long to move you\r\nbecause we wanted to make sure not to damage your custom design. We\x92ve\r\npainstakingly examined every custom design and fixed anything that\r\nmight break in migration. So this transition should go smoothly, with\r\nyour custom design remaining intact. We know you\x92ve spent a lot of\r\ntime on it, however, so we\x92ve set up a page which yo