Skip to content

Instantly share code, notes, and snippets.

View simsicon's full-sized avatar

simsicon

  • Shanghai
View GitHub Profile
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
@simsicon
simsicon / kmp.py
Last active December 5, 2016 03:21
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 / logrotate.conf
Created March 24, 2016 05:57
Helpful logrotate configuration
/var/log/app.log {
weekly
missingok
rotate 52
compress
delaycompress
notifempty
copytruncate
}
@simsicon
simsicon / provisioning.sh
Created May 6, 2016 11:09
A provisioning script for Rails webapp on Ubuntu 14.04 LTS
### 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 / assertions.rb
Created February 13, 2014 06:31
capybara minitest assertions comments
##
# 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 / source.list
Created September 5, 2013 07:18
A source.list for ubuntu 13.04 Raring
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 / sublime_fix_home_end_keys.md
Created August 10, 2021 06:09 — forked from ihor-lev/sublime_fix_home_end_keys.md
Fix Sublime Text Home and End key usage on Mac OSX

Sublime Text Home/End keys default functionality jumps to the beginning and end of the file.

Fix Home and End keys to move the cursor to the beginning and end of lines.

Preferences > Key Bindings - User

Adding the following to the array:

{ "keys": ["home"], "command": "move_to", "args": {"to": "bol"} },
{ "keys": ["end"], "command": "move_to", "args": {"to": "eol"} },
@simsicon
simsicon / main.py
Last active September 16, 2021 10:15
Sqlalchemy subquery is cached, the result is incorrect respect to the different parameters
from sqlalchemy import create_engine, select, func, text
from sqlalchemy.orm import sessionmaker, declarative_base
from sqlalchemy import Column, Integer, Date
import datetime
#SQLAlchemy==1.4.23 psycopg2==2.9.1 with postgresql 13
engine = create_engine("postgresql+psycopg2://postgres:postgres@127.0.0.1:5432/sa_test?sslmode=disable", echo=False)
Session = sessionmaker(engine)
Base = declarative_base()