Skip to content

Instantly share code, notes, and snippets.

@jhjguxin
jhjguxin / how_to_concerns.md
Last active November 28, 2018 17:16 — forked from dhh/gist:1014971
how to concerns with rails 3
@jhjguxin
jhjguxin / mongoid_batches_operate.rb
Last active December 14, 2015 22:48 — forked from justinko/gist:1272234
mongoid batches operate include find and remove
def find_in_batches(criteria, batch_size = 1000, sleep_seconds = 1)
current_batch = 0
count = criteria.count
while count > 0 do
criteria.skip(current_batch * batch_size).limit(batch_size).collect{|doc| yield doc}
count -= batch_size
current_batch += 1
#logger.info "now picked #{current_batch * batch_size}, batch_size is #{batch_size} then sleep #{sleep_seconds}'s ..."
sleep sleep_seconds
@jhjguxin
jhjguxin / deploy.rb
Created December 19, 2012 06:40 — forked from andruby/deploy.rb
after "deploy:symlink", "deploy:restart_workers"
##
# Rake helper task.
# http://pastie.org/255489
# http://geminstallthat.wordpress.com/2008/01/27/rake-tasks-through-capistrano/
# http://ananelson.com/said/on/2007/12/30/remote-rake-tasks-with-capistrano/
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
jhjguxin / active_record_associations.rb
Created November 9, 2012 05:38 — forked from karmi/active_record_associations.rb
An example of elasticsearch & Tire setup for ActiveRecord associations
# An example of elasticsearch & Tire setup for ActiveRecord associations.
#
# A `Book has_many :chapters` scenario, with mapping and JSON serialization
# for indexing associated models.
#
# Demonstrates three important caveats as of now:
#
# 1. You you have to use `touch: true` in the `belongs_to` declaration,
# to automatically notify the parent model about the update.
#
@jhjguxin
jhjguxin / deploy.rb
Created September 28, 2012 06:19 — forked from agaidot/deploy.rb
Start and Stop tasks for resque workers, with capistrano deploy hook (without God)
after "deploy:create_symlink", "deploy:restart_workers"
##
# Rake helper task.
# http://pastie.org/255489
# http://geminstallthat.wordpress.com/2008/01/27/rake-tasks-through-capistrano/
# http://ananelson.com/said/on/2007/12/30/remote-rake-tasks-with-capistrano/
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
jhjguxin / Capistrano-Deployment-Recipe.rb
Created September 3, 2012 06:39 — forked from mrrooijen/Capistrano-Deployment-Recipe.rb
a "base" Capistrano Rails Deployment Recipe. Use it to deploy your Rails application. It is also easily expandable. So feel free to grab this Recipe and add your own tasks/customization!
# Guide
# Configure the essential configurations below and do the following:
#
# Repository Creation:
# cap deploy:repository:create
# git add .
# git commit -am "initial commit"
# git push origin master
#
# Initial Deployment:
# Guide
# Configure the essential configurations below and do the following:
#
# Repository Creation:
# cap deploy:repository:create
# git add .
# git commit -am "initial commit"
# git push origin master
#
# Initial Deployment:
@jhjguxin
jhjguxin / deploy.rb
Created August 31, 2012 10:38 — forked from andruby/deploy.rb
Start and Stop tasks for resque workers, with capistrano deploy hook (without God)
after "deploy:symlink", "deploy:restart_workers"
##
# Rake helper task.
# http://pastie.org/255489
# http://geminstallthat.wordpress.com/2008/01/27/rake-tasks-through-capistrano/
# http://ananelson.com/said/on/2007/12/30/remote-rake-tasks-with-capistrano/
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
jhjguxin / smser.rb
Created August 27, 2012 00:40 — 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)
@jhjguxin
jhjguxin / notifier.coffee
Created August 3, 2012 15:16 — forked from sishen/notifier.coffee
Web Notifications integration in Pragmatic.ly
class Notifier
constructor: ->
@enableNotification = false
@checkOrRequirePermission()
hasSupport: ->
window.webkitNotifications?
requestPermission: (cb) ->
window.webkitNotifications.requestPermission (cb)