Skip to content

Instantly share code, notes, and snippets.

View nlpjoe's full-sized avatar
🎯
Focusing

Jzzhou nlpjoe

🎯
Focusing
View GitHub Profile
@nlpjoe
nlpjoe / omzsh&autojump.zsh
Last active April 5, 2017 09:04
omzsh&autojump.zsh
################## install oh-my-zsh #######################
sudo apt-get install git
sudo apt-get install zsh
wget --no-check-certificate http://install.ohmyz.sh -O - | sh
这时可能会出现 密码: chsh:PAM, 手动输入 chsh -s /bin/zsh 即可解决
注销或重启就ok了
@nlpjoe
nlpjoe / resume
Last active February 21, 2017 08:15
resume
./bin/md2resume html examples/source/sample.md examples/output/
./bin/md2resume pdf examples/source/sample.md examples/output/
# Choose a template with the -t option.
./bin/md2resume html --template blockish examples/source/sample.md examples/output/
# If you want to edit your markdown resume in your editor while watching it update in your browser, run this command:
@nlpjoe
nlpjoe / bisect.py
Last active January 13, 2018 09:28
[bisect]用bisect来管理已排序的序列#python
## 2.8 用bisect来管理已排序的序列
import bisect
import sys
Haystack = [1, 4, 5, 6, 8 ,12, 15, 20, 21, 23, 23, 26, 29, 30] # 干草垛
Needles = [0, 1, 2, 5, 8, 10, 22, 23, 29, 30, 31] # 针
ROW_FMT = '{0:2d} @ {1:2d} {2}{0:<2d}'
@nlpjoe
nlpjoe / StrKeyDict.py
Last active January 14, 2018 06:35
[自定义字典映射类型]非字符串键转字符串#python
import collections
class StrKeyDict0(dict): # 继承dict
def __missing__(self, key):
if isinstance(key, str): # 找不到的键是字符串,抛出keyerror异常
raise KeyError(key)
return self[str(key)] # 找不到的键转为字符串再查找
def get(self, key, default=None):
try:
@nlpjoe
nlpjoe / promotions.py
Created January 15, 2018 06:11
[策略设计模式]折扣方案的策略设计模式#python
# 6.使用一等函数实现设计模式
from collections import namedtuple
Customer = namedtuple('Customer', 'name fidelity')
class LineItem(object):
def __init__(self, product, quantity, price):
self.product = product
self.quantity = quantity
self.price = price
@nlpjoe
nlpjoe / decorator_promotion.py
Created January 15, 2018 06:50
[装饰器改进的策略模式]折扣改进#python
# 7 函数装饰器和闭包
## 使用装饰器改进策略模式
from collections import namedtuple
Customer = namedtuple('Customer', 'name fidelity')
class LineItem(object):
def __init__(self, product, quantity, price):
@nlpjoe
nlpjoe / deco_funcs.md
Last active March 5, 2018 05:27
[实用装饰器函数]#python

函数运行时间

import time
import functools
from functools import singledispatch

def clock(func):
    @functools.wraps(func)
    def clocked(*args, **kwargs):
        t0 = time.time()
@nlpjoe
nlpjoe / CPU任务并发代码.md
Last active March 13, 2018 07:04
[CPU任务并发代码]进程池#python

普通多线程:

    def __init__(self, name_2_id_path, triple_path):

        self.name_2_id_path = name_2_id_path
        self.triple_path = triple_path
        self.entity_2_id_set = defaultdict(dict)
        self.triple_set = defaultdict(dict)
        t1 = Thread(target=self.load_name_2_id)
@nlpjoe
nlpjoe / IO任务并发.md
Last active March 5, 2018 03:21
[IO任务并发]executor.map#python

直接多进程

class KnowledgeEngine:
    def __init__(self, name_2_id_path, triple_path):
        self.name_2_id_path = name_2_id_path
        self.triple_path = triple_path
        self.entity_2_id_set = defaultdict(dict)
        self.triple_set = defaultdict(dict)
        t1 = Thread(target=self.load_name_2_id)
@nlpjoe
nlpjoe / instance_method_dispatch.py
Created January 20, 2018 09:04
[python中两种利用singledispatch实现实例方法分发]#python
### 基础的singledispatch装饰器只能实现静态方法
from functools import singledispatch
class TestClass(object):
@singledispatch
def test_method(arg, verbose=False):
if verbose:
print("Let me just say,", end=" ")