Skip to content

Instantly share code, notes, and snippets.

View Laisky's full-sized avatar

Laisky.Cai Laisky

View GitHub Profile
@Laisky
Laisky / get_longest_continuous_checkin_date.py
Created October 8, 2018 03:30
从 XMLS 中获取连续签到日期超过 7 天的 id。
from datetime import datetime
import glob
from collections import defaultdict
import xlrd
LEAST_CONT_DAYS = 7
@Laisky
Laisky / git-restrict-rules.sh
Last active December 20, 2016 07:34
Git commit comment restrict rules
# Inspired by https://gist.githubusercontent.com/leftstick/29e4099a61d2c0182e1fda196eb9e071/raw/4270cf778d70202bfc5d76fdee7e87c628b198e5/commit-msg
#!/usr/bin/env bash
echo "
#!/usr/bin/env bash
# regex to validate in commit msg
commit_regex='([A-Z]{1,7}-[0-9]{1,7}: .{1,100}(\\\nReviewed by: [a-zA-Z0-9\\.]{1,25})?|(fix|docs|feat|style|refactor|perf|test|chore): .{1,100})'
if ! grep -iqE \"\$commit_regex\" \"\$1\"; then
echo '\\\033[31m Commit comment format not correct!'
@Laisky
Laisky / pytopo.py
Last active September 28, 2015 06:22
Generate network topological graph by pygraphviz_1.3rc
#! /usr/bin/env python
# -*- coding: utf-8
"""
@description: Generate network topological graph by pygraphviz_1.3rc.
@created_at: Mon Aug 24 16:21:10 2015
@author: Laisky
@copyright: 2015/Laisky
@license: MIT/Apache
@Laisky
Laisky / sorted_chain.py
Created September 25, 2015 06:18
Sortable itertools.chain with key.
"""
@description: Sortable chain with key, just like sorted.
@author: Laisky
@copyright: 2015/Laisky
@license: MIT/Apache
"""
from collections import namedtuple
@Laisky
Laisky / docker_utils
Created February 6, 2015 03:58
docker_utils
# Some useful commands to use docker.
# Author: yeasy@github
# Created:2014-09-25
alias docker-pid="sudo docker inspect --format '{{.State.Pid}}'"
alias docker-ip="sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}'"
#the implementation refs from https://github.com/jpetazzo/nsenter/blob/master/docker-enter
function docker-enter() {
if [ -e $(dirname "$0")/nsenter ]; then
@Laisky
Laisky / Apriori_with_hconfidence.py
Created December 29, 2014 07:57
Apriori_with_hconfidence
import datetime
from pprint import pprint
from collections import defaultdict
import numpy as np
import pandas as pd
def apriori(dataset, min_support=0.5, min_hconf=0.5, verbose=False):
"""Implements the Apriori algorithm.
@Laisky
Laisky / profile_cmd.py
Created December 26, 2014 07:11
profile by subprocess.Popen
import queue
import random
import time
from datetime import datetime
from itertools import product
import concurrent.futures
import pandas as pd
from pipe import as_list
@Laisky
Laisky / parse_table.py
Created December 26, 2014 07:07
parse huge table from html
import os
import re
import codecs
import concurrent.futures
import multiprocessing
import pandas as pd
def worker(task_q):
@Laisky
Laisky / replace_content_in_mongo.py
Last active August 29, 2015 14:06
replace duanwei with 儿童
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import logging
import pymongo
NEW_HASH = '0f533b43e264260e17fed6a15e05ffd6c3f8e3b1'
HASH_TEXT = 'duanwei-儿童'
OLD_HASH_LS = ['efacd9afc28bed0712c4e904585f10a277fbfc7d',
'59f420d90a824716eb07df9b698aa2ecedf3f0dc',