Skip to content

Instantly share code, notes, and snippets.


jhjguxin jhjguxin

View GitHub Profile
jhjguxin /
Last active Nov 28, 2018 — forked from dhh/gist:1014971
how to concerns with rails 3
jhjguxin / deploy.rb
Created Aug 31, 2012 — forked from andruby/deploy.rb
Start and Stop tasks for resque workers, with capistrano deploy hook (without God)
View deploy.rb
after "deploy:symlink", "deploy:restart_workers"
# Rake helper task.
def run_remote_rake(rake_cmd)
rake_args = ENV['RAKE_ARGS'].to_s.split(',')
cmd = "cd #{fetch(:latest_release)} && #{fetch(:rake, "rake")} RAILS_ENV=#{fetch(:rails_env, "production")} #{rake_cmd}"
jhjguxin / ringbuffer.rb
Created Oct 29, 2018 — forked from eerohele/ringbuffer.rb
A simple ring buffer for Ruby.
View ringbuffer.rb
class RingBuffer < Array
attr_reader :max_size
def initialize(max_size, enum = nil)
@max_size = max_size
enum.each { |e| self << e } if enum
def <<(el)
if self.size < @max_size || @max_size.nil?
echo "Updates packages. Asks for your password."
sudo apt-get update -y
echo "Installs packages. Give your password when asked."
sudo apt-get install build-essential bison openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev -y
echo "Installs ImageMagick for image processing"
sudo apt-get install imagemagick --fix-missing -y
echo "Installs RVM (Ruby Version Manager) for handling Ruby installation"
jhjguxin / unicorn.rb
Created Sep 8, 2016 — forked from ak47/unicorn.rb
force figaro ENV vars to reload on unicorn USR2 restarts
View unicorn.rb
root = "/var/www/cake/current"
working_directory root
pid "#{root}/tmp/pids/"
stderr_path "#{root}/log/unicorn.stderr.log"
stdout_path "#{root}/log/unicorn.log"
listen "/tmp/unicorn.cake.sock"
worker_processes 2
timeout 15
jhjguxin / gist:942131cc6795cbf98ceb
Created Jan 26, 2016 — forked from donnierayjones/LICENSE
Render Bootstrap as "small" layout when printing
View gist:942131cc6795cbf98ceb
@media print {
.col-sm-1, .col-sm-2, .col-sm-3, .col-sm-4, .col-sm-5, .col-sm-6, .col-sm-7, .col-sm-8, .col-sm-9, .col-sm-10, .col-sm-11, .col-sm-12 {
float: left;
.col-sm-12 {
width: 100%;
.col-sm-11 {
width: 91.66666667%;
View Rakefile
require 'my-sinatra-app'
require 'sinatra/activerecord/rake'
desc "run irb console"
task :console, :environment do |t, args|
ENV['RACK_ENV'] = args[:environment] || 'development'
exec "irb -r irb/completion -r my-sinatra-app"
View gist:7462754

Implement Routing for Subdomains

Rails 3.0 introduced support for routing constrained by subdomains.

A subdomain can be specified explicitly, like this:

match '/' => 'home#index', :constraints => { :subdomain => 'www' } 
View gist:6278572
module ActsAsTaggable
module Taggable
def self.included(base)
base.field :tags, :type => Array, :default => []
module Tagger
def tag(object, tags)
View custom_logger.rb
# lib/custom_logger.rb
class CustomLogger < Logger
def format_message(severity, timestamp, progname, msg)
"#{timestamp.to_formatted_s(:db)} #{severity} #{msg}\n"
logfile ="#{Rails.root}/log/custom.log", 'a') # create log file
logfile.sync = true # automatically flushes data to file
CUSTOM_LOGGER = # constant accessible anywhere