Skip to content

Instantly share code, notes, and snippets.

class Foo < ActiveRecord::Base
class MyOwnHash
def self.dump(hash)
hash.to_json
end
def self.load(hash)
(hash || {}).with_indifferent_access
end
class MyRedis
def self.conn
connect unless @conn
begin
@conn.ping
rescue Redis::BaseConnectionError
raise if @tried
@tried = true
connect
retry
@smathy
smathy / console
Last active August 29, 2015 14:25
Foo: 1 bar
[14] pry(main)> params = {"authenticity_token"=>"qNm7AlvhnrQoWc3XqN1csWfDauWDNUzkiv0ARa1jJPQ=", "evento"=>{"id"=>"", "situacao"=>"1", "nome"=>"teste", "apresentacao"=>"<p>teste</p>\r\n", "coordenador_id"=>"21243", "exibir_gabarito"=>"0", "exibir_estatistica_individual"=>"0", "exibir_forum"=>"0", "inicio"=>"09/04/2015", "fim"=>"09/10/2015", "fase_do_evento_id"=>"1", "duracao"=>"5", "tipo_questao_id"=>"1", "ponto_acerto"=>"0.0", "ponto_erro"=>"0.0", "ponto_aprovacao"=>"0.0"}, "aproveitamentos_produto"=>{"aproveitamento_id"=>["1"]}, "grupo_novo"=>[{"area_conhecimento_id"=>"15", "total_questoes"=>"1", "ponto_corte"=>"1", "ordem"=>"1"}]}
=> {"authenticity_token"=>"qNm7AlvhnrQoWc3XqN1csWfDauWDNUzkiv0ARa1jJPQ=",
"evento"=>
{"id"=>"",
"situacao"=>"1",
"nome"=>"teste",
"apresentacao"=>"<p>teste</p>\r\n",
"coordenador_id"=>"21243",
"exibir_gabarito"=>"0",
"exibir_estatistica_individual"=>"0",
[7] pry(main)> f = Foo.new
=> #<Foo:0x007ff0f3cbfd68 id: nil, name: nil, created_at: nil, updated_at: nil>
[8] pry(main)> f.changes
=> {}
[9] pry(main)> f.name = "Blah"
=> "Blah"
[10] pry(main)> f.changes
=> {"name"=>[nil, "Blah"]}
[11] pry(main)>
ActiveRecord::Migration.class_eval do
def create_or_replace_view view
execute File.read(Rails.root.join "db/views/#{view}.sql")
end
end
ActiveRecord::Migration.class_eval do
def create_or_replace_view view
execute File.read(Rails.root.join "db/views/#{view}.sql")
end
end
SELECT a.attname, format_type(a.atttypid, a.atttypmod),
pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = 'researchers'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
location ~* ^/convenient_url/(.+)$ {
internal;
set $host_name some.secret.cdn.hostname.com;
set $content_ip 10.11.12.13;
set $content_url http://$content_ip/$1;
proxy_set_header Host $host_name;
add_header Content-Type 'application/octet-stream';
Pry::Commands.block_command 'r' do |*w|
run "show-routes" + ( w.present? ? " --grep '#{w.join ' '}'" : "" )
end