Skip to content

Instantly share code, notes, and snippets.

View gist:3920f630e42d2aa318ca
-- drop_table(:users)
-> 0.0156s
-- create_table(:users)
-> 0.0034s
-- add_index(:users, :preferences, {:using=>:gin})
-> 0.0040s
-- initialize_schema_migrations_table()
-> 0.0207s
#=> Ruby 2.2.0
#=> ActiveRecord 4.2.0
@masterkain
masterkain / gist:a192c5982f5c46f80ebd
Created Feb 21, 2015
custom rails json dump load class
View gist:a192c5982f5c46f80ebd
require 'oj'
# Macro in model:
# serialize :payload, ActiveSupport::OJSON
#
# payload is a text data type in postgres
#
module ActiveSupport
module OJSON
class << self
View gist:f4ada8799b81667229e4
cap staging foreman:setup
DEBUG [b77dc6fe] Running ~/.rvm/bin/rvm version on 162.243.255.230
DEBUG [b77dc6fe] Command: ~/.rvm/bin/rvm version
DEBUG [b77dc6fe]
DEBUG [b77dc6fe] rvm 1.25.25 (master) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]
DEBUG [b77dc6fe]
DEBUG [b77dc6fe] Finished in 2.093 seconds with exit status 0 (successful).
rvm 1.25.25 (master) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]
DEBUG [9b4d75a0] Running ~/.rvm/bin/rvm current on 162.243.255.230
View gist:3229234
{"item_photo":{"item_id":"10","content_type":"image/jpeg","original_filename":"test.jpg","photo_data":"/9j/4QAYRXhpZgAASUkqAAgAAAAAAAAAAAAAAP/sABFEdWNreQABAAQAAABQAAD/4QNxaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wLwA8P3hwYWNrZXQgYmVnaW49Iu+7vyIgaWQ9Ilc1TTBNcENl aGlIenJlU3pOVGN6a2M5ZCI/PiA8eDp4bXBtZXRhIHhtbG5zOng9ImFkb2JlOm5zOm1ldGEvIiB4 OnhtcHRrPSJBZG9iZSBYTVAgQ29yZSA1LjAtYzA2MSA2NC4xNDA5NDksIDIwMTAvMTIvMDctMTA6 NTc6MDEgICAgICAgICI+IDxyZGY6UkRGIHhtbG5zOnJkZj0iaHR0cDovL3d3dy53My5vcmcvMTk5 OS8wMi8yMi1yZGYtc3ludGF4LW5zIyI+IDxyZGY6RGVzY3JpcHRpb24gcmRmOmFib3V0PSIiIHht bG5zOnhtcE1NPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvbW0vIiB4bWxuczpzdFJlZj0i aHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL3NUeXBlL1Jlc291cmNlUmVmIyIgeG1sbnM6eG1w PSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bXBNTTpPcmlnaW5hbERvY3VtZW50SUQ9 InhtcC5kaWQ6MDM4MDExNzQwNzIwNjgxMTk1RkVBNDIxMDE4OTQzMTUiIHhtcE1NOkRvY3VtZW50 SUQ9InhtcC5kaWQ6OEVBNjU2ODU2OUE3MTFFMTlDMDQ4RDBGMTVBOUYwMkYiIHhtcE1NOkluc3Rh bmNlSUQ9InhtcC5paWQ6OEVBNjU2ODQ2OUE3MTFFMTlDMDQ4RDBGMTVBOUYwMkYiIHhtcDpDcmV
@masterkain
masterkain / nginx_rails_3_1
Created Apr 17, 2012 — forked from shapeshed/nginx_rails_3_1
Nginx Config for Rails 3.1 with Unicorn and Asset Pipeline
View nginx_rails_3_1
upstream app {
server unix:/srv/app/current/tmp/sockets/unicorn.sock fail_timeout=0;
}
server {
listen 80;
server_name www.app.com;
rewrite ^/(.*) http://app.com/$1 permanent;
}
server {
@masterkain
masterkain / Gemfile
Created Mar 1, 2012
Sidekiq GitHub issue reporter
View Gemfile
gem 'sidekiq'
gem 'octokit'
@masterkain
masterkain / routes.rake
Created Jan 7, 2012
Journey + Graphviz
View routes.rake
namespace :routes do
desc "Writes doc/routes.html. Requires Graphviz (dot)"
task :visualizer => :environment do
File.open(Rails.root.join('doc', 'routes.html'), 'wb') do |f|
f.write Rails.application.routes.router.visualizer
end
end
end
View gist:1129946
require "resque"
require "resque/failure/multiple"
require "resque/failure/redis"
# Configure Resque connection from config/redis.yml. This file should look
# something like:
# development: localhost:6379
# test: localhost:6379:15
# production: localhost:6379
Resque.redis = YAML.load_file(Rails.root + 'config/redis.yml')[Rails.env]
View topic.rb
# @topic = Topic.new(params[:topic])
# @topic.this_user = current_user
class Topic < ActiveRecord::Base
belongs_to :user
attr_accessor :this_user
def validate_on_update
# Make sure that this_user is an instance of User, otherwise just use the id
errors.add(:user, "Only the topic creator can update the topic") if user_id != this_user.id;
@masterkain
masterkain / array.rb
Created Jul 31, 2011
splice in ruby
View array.rb
class Array
def splice(start, len, *replace)
self[start, len] = replace
self
end
end
ruby-1.8.7-p352 :008 > initial_array = [:a, :c, :h, :g, :t, :m]
=> [:a, :c, :h, :g, :t, :m]
ruby-1.8.7-p352 :009 > initial_array.splice(2, 2, :test)