Skip to content

Instantly share code, notes, and snippets.

View rubyonrailsworks's full-sized avatar

RubyonRailsWorks rubyonrailsworks

  • Shanghai,China
View GitHub Profile
@rubyonrailsworks
rubyonrailsworks / convert.rake
Created December 8, 2012 04:28 — forked from mperham/convert.rake
Ruby script to update MySQL from Latin1 to UTF8 without data conversion
desc "convert a latin1 database with utf8 data into proper utf8"
task :convert_to_utf8 => :environment do
puts Time.now
dryrun = ENV['DOIT'] != '1'
conn = ActiveRecord::Base.connection
if dryrun
def conn.run_sql(sql)
puts(sql)
end
else
@rubyonrailsworks
rubyonrailsworks / changes.md
Created November 27, 2012 07:58 — forked from funny-falcon/changes.md
Performace patch for ruby-1.9.3-p327

Changes:

  • this version includes backport of Greg Price's patch for speedup startup http://bugs.ruby-lang.org/issues/7158 .

    ruby-core prefers his way to do thing, so that I abandon cached-lp and sorted-lf patches of mine.

  • this version integrates 'array as queue' patch, which improves performance when push/shift pattern is heavily used on Array.

    This patch is accepted into trunk for Ruby 2.0 and last possible bug is found by Yui Naruse. It is used in production* for a couple of months without issues even with this bug.

@rubyonrailsworks
rubyonrailsworks / rails-template.rb
Created October 30, 2012 16:59 — forked from HungYuHei/rails-template.rb
Rails 3 App Template with JQuery, Mongoid, Compass, HAML & Barista
# rails new NAME -OJ -m https://gist.github.com/raw/903515/rails-template.rb
remove_file 'README'
remove_file 'public/index.html'
remove_file 'public/images/rails.png'
prepend_file 'config/boot.rb' do <<-RB
begin
require 'yaml'
YAML::ENGINE.yamler = 'syck'
@rubyonrailsworks
rubyonrailsworks / rails-back-page
Created October 30, 2012 16:58 — forked from HungYuHei/rails-back-page
rails返回上一页
request.env['HTTP_REFERER']
request.referer
<%= link_to_function "返回上一页", "history.go(-1)" %>
<%= link_to "Back", :back %>
redirect_to :back
@rubyonrailsworks
rubyonrailsworks / import_file_to_gridfs.rake
Created October 30, 2012 16:57 — forked from HungYuHei/import_file_to_gridfs.rake
将 File System 的上传文件导入到 Mongodb 的 GridFS 里面
# coding: UTF-8
#
# 以下为 Rake 任务,功能是将普通文件系统里面的东西转移到 MongoDB GridFS 里面
# 此代码片段来自于 Homeland 项目: https://github.com/huacnlee/homeland/tree/mysql
# 场景:
# 老架构 Linux File Store, Paperclip, hash 目录:"https://github.com/huacnlee/homeland/blob/ca0bdd8ab26da7b780e2dae7eba12b79f41e6d65/config/initializers/paperclip_hashpath.rb"
# 新架构 Mongodb GridFS, Garrierwave, 继续沿用 Paperclip 目录兼容: https://github.com/huacnlee/homeland/tree/7100ce4c506cc2c4387f25e50c533e5bbcac6cc2/app/uploaders
# 整个过程不会修改任何原始数据库和上传文件
#
require 'mongo'
@rubyonrailsworks
rubyonrailsworks / smser.rb
Created October 30, 2012 16:54 — forked from HungYuHei/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)
@rubyonrailsworks
rubyonrailsworks / Gemfile
Created October 30, 2012 16:53 — forked from HungYuHei/Gemfile
followable with redis Sorted-Set
# Gemfile
gem 'redis', '~> 3.0.1'
@rubyonrailsworks
rubyonrailsworks / database.yml.erb
Created October 20, 2012 18:39 — forked from thbar/database.yml.erb
ERB template for git-branch aware database.yml (development/test only)
<%
# if you need to work on a branch with a different schema, use
# git config --bool branch.the-new-branch.database true
# http://mislav.uniqpath.com/rails/branching-the-database-along-with-your-code/
branch = `git symbolic-ref HEAD 2>/dev/null`.chomp.sub('refs/heads/', '')
suffix = `git config --bool branch.#{branch}.database`.chomp == 'true' ? "_#{branch}" : ""
%>
common: &common
@rubyonrailsworks
rubyonrailsworks / gist:3903447
Created October 17, 2012 02:49 — forked from hisea/gist:3363163
Rake task with param and dependency
require 'resque/tasks'
namespace :ns do
desc "test task accepts param"
task :task, [:param] => [:environment] do |t,args|
abort "Please specify a param!" unless args[:param]
puts args[:param]
end
end
@rubyonrailsworks
rubyonrailsworks / deploy.rb
Created October 2, 2012 18:58 — forked from Mic92/deploy.rb
My mina deploy setup
require 'mina/bundler'
require 'mina/rails'
require 'mina/git'
require 'mina/rbenv'
# Basic settings:
# domain - The hostname to SSH to
# deploy_to - Path to deploy into
# repository - Git repo to clone from (needed by mina/git)
# user - Username in the server to SSH to (optional)