Skip to content

Instantly share code, notes, and snippets.

View masterkain's full-sized avatar
🤖

Kain masterkain

🤖
View GitHub Profile
class ApplicationController < ActionController::Base
protect_from_forgery
layout Proc.new { |controller| controller.request.xhr? ? 'ajax' : 'test' }
end
@masterkain
masterkain / array.rb
Created July 31, 2011 22:36
splice in ruby
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)
# @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;
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]
@masterkain
masterkain / routes.rake
Created January 7, 2012 02:16
Journey + Graphviz
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
@masterkain
masterkain / Gemfile
Created March 1, 2012 03:29
Sidekiq GitHub issue reporter
gem 'sidekiq'
gem 'octokit'
@masterkain
masterkain / nginx_rails_3_1
Created April 17, 2012 20:03 — forked from shapeshed/nginx_rails_3_1
Nginx Config for Rails 3.1 with Unicorn and Asset Pipeline
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 {
{"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
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 <[email protected]>, Michal Papis <[email protected]> [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 <[email protected]>, Michal Papis <[email protected]> [https://rvm.io/]
DEBUG [9b4d75a0] Running ~/.rvm/bin/rvm current on 162.243.255.230
@masterkain
masterkain / gist:a192c5982f5c46f80ebd
Created February 21, 2015 02:18
custom rails json dump load class
require 'oj'
# Macro in model:
# serialize :payload, ActiveSupport::OJSON
#
# payload is a text data type in postgres
#
module ActiveSupport
module OJSON
class << self