Skip to content

Instantly share code, notes, and snippets.

View toaco's full-sized avatar
🎯
Focusing

toaco toaco

🎯
Focusing
View GitHub Profile
@toaco
toaco / calc_deadline.py
Created November 13, 2017 01:47
calculate deadline of current period which unit is month
import arrow
def diff_month(d1, d2):
return (d1.year - d2.year) * 12 + d1.month - d2.month
def calc_deadline(start_date, period):
date = arrow.get(start_date)
now = arrow.get()
@toaco
toaco / file.markdown
Created November 8, 2017 09:15
Math Rendering Problems

统计机器翻译(英语:Statistical Machine Translation,简写为SMT)是机器翻译的一种,基本思想是通过对大量的平行语料进行统计分析,构建模型,进而使用此模型进行翻译。

所谓的平行语料就是表达同一个意思的不同语言的句子,如:

這是一個蘋果。
This is an apple.

桌上有一本書。
There is a book on the table.
@toaco
toaco / dictstack.py
Created November 3, 2017 03:52
Hash stack in Redis which could expire items
import datetime
import redis
class DictStack(object):
def __init__(self, key_name, redis_option):
self._db = redis.StrictRedis(**redis_option)
self._key_name = key_name
@toaco
toaco / utils.py
Created August 7, 2017 01:55
Replace all sensitive value to `******`, according to instance attribute or dict key.
import copy
import types
def shield_sensitive(obj, *args):
"""
replace all sensitive value to `******`, according to instance attribute or dict key.
"""
try:
@toaco
toaco / get_all_resources.py
Created July 18, 2017 09:11
list all resource requested by a request
# list all resource requested by a request
from ghost import Ghost
ghost = Ghost()
def get_all_resources(url):
with ghost.start() as session:
page, extra_resources = session.open(url)
for extra_resource in extra_resources:
@toaco
toaco / main.py
Created December 6, 2016 04:17
查看windows剪切板信息(View Windows Clipboard information)
# 参考链接: http://stackoverflow.com/questions/101128/how-do-i-read-text-from-the-windows-clipboard-from-python
import win32clipboard
win32clipboard.OpenClipboard()
for i in range(0XFFFF):
try:
data = win32clipboard.GetClipboardData(i)
print("Clipboard Formats Value: {}(HEX:{:X})".format(i, i))
print("ClipboardDate:\n{}".format(repr(data)))
print("------------------------------------------------------------------------")