Skip to content

Instantly share code, notes, and snippets.

#!/bin/sh
#
# init.d script for single or multiple unicorn installations. Expects at least one .conf
# file in /etc/unicorn
#
# Modified by jay@gooby.org http://github.com/jaygooby
# based on http://gist.github.com/308216 by http://github.com/mguterl
#
## A sample /etc/unicorn/my_app.conf
##
require "rubygems"
require "oauth"
TQQ_CONSUMER_KEY = "9b43a5afaca04afd8eb573e673fce3f9"
TQQ_CONSUMER_SECRET = "dd6b3cef9a6896e373085a83cd8b74f9"
# 1. 获取Request Token
consumer = OAuth::Consumer.new(TQQ_CONSUMER_KEY, TQQ_CONSUMER_SECRET, {
:site => "https://open.t.qq.com",
:request_token_path => "/cgi-bin/request_token",
fast: through middleware inserted at 0
slwr: through middleware inserted via @use@
rotr: through endpoint sent via the router
bare: through ActionController::Metal with self.response_body
cntr: through ActionController::Base with self.response_body
text: through ActionController::Base with render :text
tmpl: through ActionController::Base with simple render :template
layt: through ActionController::Base with render :template with layout
Note: These tests are being run without ActiveRecord, which currently
@HungYuHei
HungYuHei / _form.html.erb
Created October 11, 2012 04:04 — forked from huacnlee/_form.html.erb
UpYun 表单上传验证信息 helper 方法,用于生成 input tag
<form action="http://v0.api.upyun.com/rbtest/" method="post" enctype="multipart/form-data">
<%= upyun_form_input_tag(:return_url => new_post_path) %>
<input type="file" name="file" />
<button type="submit">上传图片</button>
</form>
@HungYuHei
HungYuHei / smser.rb
Created August 24, 2012 11:49 — forked from mimosz/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)
@HungYuHei
HungYuHei / README.markdown
Created August 16, 2012 12:09 — forked from greypants/README.markdown
RAILS 3: nav_link helper for adding 'selected' class to navigation elements

#Behold, the nav_link:

The nav_link helper works just like the standard Rails link_to helper, but adds a 'selected' class to your link (or its wrapper) if certain criteria are met. By default, if the link's destination url is the same url as the url of the current page, a default class of 'selected' is added to the link.

For full usage details, see: http://viget.com/extend/rails-selected-nav-link-helper

Drop nav_link_helper.rb into app/helpers in your Rails 3.x app and enjoy.

@HungYuHei
HungYuHei / dynamic_document.rb
Created July 17, 2012 09:15 — forked from camallen/dynamic_document.rb
Extend the fields of a Mongoid document from a .yml file
module ExtendFields
require "yaml"
private
def extend_fields
dynamic_fields.each { |name, type| self.class.field name, type: type }
end
def dynamic_fields
YAML.load_file( File.join( Rails.root, 'config', 'class_fields', "#{self.class.name.underscore}.yml" ) ) rescue {}
@HungYuHei
HungYuHei / deploy.rb
Created June 27, 2012 03:55 — forked from stympy/deploy.rb
Skip asset pre-compilation when deploying if the assets didn't change
namespace :deploy do
namespace :assets do
task :precompile, :roles => :web, :except => { :no_release => true } do
from = source.next_revision(current_revision)
if capture("cd #{latest_release} && #{source.local.log(from)} vendor/assets/ lib/assets/ app/assets/ | wc -l").to_i > 0
run %Q{cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:precompile}
else
logger.info "Skipping asset pre-compilation because there were no asset changes"
end
end
@HungYuHei
HungYuHei / solr_cap.rb
Created June 2, 2012 06:59 — forked from doitian/solr_cap.rb
sunspot solr in capistrano
namespace :deploy do
task :setup_solr_data_dir do
run "mkdir -p #{shared_path}/solr/data"
end
end
namespace :solr do
desc "start solr"
task :start, :roles => :app, :except => { :no_release => true } do
run "cd #{current_path} && RAILS_ENV=#{rails_env} bundle exec sunspot-solr start --port=8983 --data-directory=#{shared_path}/solr/data --pid-dir=#{shared_path}/pids"
@HungYuHei
HungYuHei / gist:2515224
Created April 28, 2012 02:40 — forked from mgraupner/gist:1859298
MacOS X 10.7.3 and XCode 4.3: Installing Ruby
- Install "Command Line Tools for XCode" (Get it from Apple Developer Program) or Install XCode via Appstore
where option one is the faster one, 170MB vs 1.xGB
- Install https://github.com/sstephenson/rbenv
git clone into your home folder;
set environment variables, see install docs of rbenv;
- Get libyaml
wget http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz
configure