Skip to content

Instantly share code, notes, and snippets.

View Hanaasagi's full-sized avatar
🧠
我脑子有病

Hanaasagi

🧠
我脑子有病
View GitHub Profile
InfiniteDict = lambda: defaultdict(InfiniteDict) # noqa
@Hanaasagi
Hanaasagi / .tmux.conf
Last active August 1, 2017 13:26
depend on xclip xsel
# 修改默认 shell
set-option -g default-shell /bin/zsh
# 启用终端 256 色
set -g default-terminal "screen-256color"
# 状态栏编码
set -g status-utf8 on
# 状态栏前景色背景色
set -g status-fg white
set -g status-bg cyan
# 状态栏高亮
@Hanaasagi
Hanaasagi / longestsubstring.py
Created June 25, 2017 07:43
最长子串 可以使用 difflib
def longest_substring(str1, str2):
"""
>>> longest_substring("apple pie available", "apple pies")
'apple pie'
>>> longest_substring("apples", "appleses")
'apples'
>>> longest_substring("bapples", "cappleses")
'apples'
"""
result = ""
@Hanaasagi
Hanaasagi / lru_cache.py
Created June 23, 2017 04:37
an LRU cache
class LRUCache:
""" LRUCache implemented with HashMap and LinkList
>>> cache = LRUCache(3)
>>> cache.set(1,1)
>>> cache.set(2,2)
>>> cache.set(3,3)
>>> cache
capacity: 3 [(1, 1), (2, 2), (3, 3)]
>>> cache.get(1)
1
@Hanaasagi
Hanaasagi / tmux-cheatsheet.markdown
Created May 25, 2017 07:59 — forked from ryerh/tmux-cheatsheet.markdown
Tmux 快捷键 & 速查表

Tmux 快捷键 & 速查表

启动新会话:

tmux [new -s 会话名 -n 窗口名]

恢复会话:

tmux at [-t 会话名]
@Hanaasagi
Hanaasagi / view_pyc_file.py
Created May 23, 2017 04:21
show the bytecode from a pyc file
import platform
import time
import sys
import binascii
import marshal
import dis
import struct
def view_pyc_file(path):
# ip source https://db-ip.com/db/#downloads
import csv
import netaddr
result = []
with open('dbip-country-2017-05.csv', 'r') as rf, \
open('ip-cidr-CN', 'w') as wf:
reader = csv.reader(rf, delimiter=',')
for row in reader:
@Hanaasagi
Hanaasagi / max_cont_subseq.md
Created May 4, 2017 06:04
求最大连续子序列和的 N 种方法

求最大连续子序列和的 N 中方法

1) O(n^3)

def max_continuous_subsequence(l):
    maxsofar = 0
    length = len(l)
    for i in range(length):
        for j in range(i, length):
@Hanaasagi
Hanaasagi / binary_search.py
Created May 4, 2017 05:08
可以找出元素第一次出现位置的二分查找
def binary_search(l, t):
low, high = -1, len(l)
while low+1 != high:
mid = (low + high) / 2
if l[mid] < t:
low = mid
else:
high = mid
pos = high
if pos >= len(l) or l[pos] != t:
@Hanaasagi
Hanaasagi / flatten.py
Created May 2, 2017 14:51
flatten a list
def flatten(seq):
l = []
for elt in seq:
t = type(elt)
if t is tuple or t is list:
for elt2 in flatten(elt):
l.append(elt2)
else:
l.append(elt)
return l