Skip to content

Instantly share code, notes, and snippets.


jhjguxin jhjguxin

View GitHub Profile
jhjguxin /
Created May 24, 2012 — forked from dongyi/
# -*- Encoding: utf-8 -*-
import base64
import binascii
import cgi
import hashlib
import hmac
import logging
import time
import urllib
import urlparse
View render_and_redirect.markdown

Render and Redirect

The normal controller/view flow is to display a view template corresponding to the current controller action, but sometimes we want to change that. We use render in a controller when we want to respond within the current request, and redirect_to when we want to spawn a new request.


The render method is very overloaded in Rails. Most developers encounter it within the view template, using render :partial => 'form' or render @post.comments, but here we'll focus on usage within the controller.


jhjguxin / rails_template_for_mongoid.rb
Created Jun 11, 2012 — forked from huacnlee/rails_template_for_mongoid.rb
A custom Rails template for Mongoid.
View rails_template_for_mongoid.rb
# coding: utf-8
# This is a Rails init template with MongoDB projects
# Mongoid, Devise, Bootstrap, jQuery, Redis, Cells, will_paginate, Carrierwave, simple_form, Settingslogic, Thin
# Usage
# $ rails new app_name -m
jhjguxin / cap.rb
Created Jun 20, 2012 — forked from jeanmartin/cap.rb
Kill resque workers using rake task, let god handle the restart
View cap.rb
after "deploy:restart", "resque:stop_workers"
namespace :resque do
task :stop_workers, :except => { :no_release => true } do
run "cd #{current_path} && rake RAILS_ENV=#{rails_env} resque:stop_workers"
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 / gist:3144247
Created Jul 19, 2012 — forked from jrochkind/gist:2161449
A Capistrano Rails Guide
View gist:3144247

A Capistrano Rails Guide

by Jonathan Rochkind,

why cap?

Capistrano automates pushing out a new version of your application to a deployment location.

I've been writing and deploying Rails apps for a while, but I avoided using Capistrano until recently. I've got a pretty simple one-host deployment, and even though everyone said Capistrano was great, every time I tried to get started I just got snowed under not being able to figure out exactly what I wanted to do, and figured I wasn't having that much trouble doing it "manually".

jhjguxin / AddFieldToUser.rb
Created Jul 30, 2012 — forked from wesgarrison/AddFieldToUser.rb
Using Rails Migration on different database than standard “production” or “development”
View AddFieldToUser.rb
class AddFieldToUser < ActiveRecord::Migration
ActiveRecord::Base.establish_connection "user_#{Rails.env}"
def self.up
add_column :users, :field, :type
jhjguxin /
Created Aug 3, 2012 — forked from sishen/
Web Notifications integration in
class Notifier
constructor: ->
@enableNotification = false
hasSupport: ->
requestPermission: (cb) ->
window.webkitNotifications.requestPermission (cb)
jhjguxin / smser.rb
Created Aug 27, 2012 — forked from mimosz/smser.rb
View smser.rb
# -*- encoding: utf-8 -*-
require 'digest/md5'
require 'nestful'
class Smsbao
attr_accessor :login, :passwd
def initialize(login, passwd)
@login = login
@passwd = Digest::MD5.hexdigest(passwd)
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}"