Skip to content

Instantly share code, notes, and snippets.

View TheWaWaR's full-sized avatar
🌀
Focusing

LingFeng TheWaWaR

🌀
Focusing
View GitHub Profile
@TheWaWaR
TheWaWaR / mini-termcolor.py
Created July 22, 2016 06:59
Mini termcolor
# coding: utf-8
"""ANSII Color formatting for output in terminal. (termcolor-1.1.0)"""
import os
ATTRIBUTES = dict(list(zip(['bold', 'dark', '', 'underline',
'blink', '', 'reverse', 'concealed'],
list(range(1, 9)))))
del ATTRIBUTES['']
@TheWaWaR
TheWaWaR / apscheduler-test.py
Last active May 16, 2021 09:14
<Advanced Python Scheduler> date trigger example
# coding: utf-8
import os
import time
from datetime import datetime, timedelta
from pytz import utc, timezone
from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.jobstores.sqlalchemy import SQLAlchemyJobStore
from apscheduler.executors.pool import ThreadPoolExecutor
@TheWaWaR
TheWaWaR / gist:373250e00f004d551872ba73556f84c8
Created May 17, 2016 07:55 — forked from danaspiegel/gist:3105761
Git pre-commit hook to check pep8 and pyflakes
#!/usr/bin/python
# borrowed from https://github.com/lbolla/dotfiles/blob/master/githooks/pre-commit
import os
import sys
import re
import subprocess
@TheWaWaR
TheWaWaR / chinese-html-diff.py
Last active April 21, 2016 06:18
HTML diff (支持中文断句)
#coding: utf-8
## 支持中文断句
punctuation = u'\uff02\uff03\uff04\uff05\uff06\uff07\uff08\uff09\uff0a\uff0b\uff0c\uff0d\uff0f\uff1a\uff1b\uff1c\uff1d\uff1e\uff20\uff3b\uff3c\uff3d\uff3e\uff3f\uff40\uff5b\uff5c\uff5d\uff5e\uff5f\uff60\uff62\uff63\uff64\u3000\u3001\u3003\u3008\u3009\u300a\u300b\u300c\u300d\u300e\u300f\u3010\u3011\u3014\u3015\u3016\u3017\u3018\u3019\u301a\u301b\u301c\u301d\u301e\u301f\u3030\u303e\u303f\u2013\u2014\u2018\u2019\u201b\u201c\u201d\u201e\u201f\u2026\u2027\ufe4f\ufe51\ufe54\xb7\uff01\uff1f\uff61\u3002'
import re
from lxml.html import diff
diff.split_words_re = re.compile(r'[^\s%(p)s]+(?:[\s%(p)s]+|$)' % dict(p=punctuation), re.U)
@TheWaWaR
TheWaWaR / install-graphite.sh
Last active April 3, 2016 05:48
Shell script for install graphite-web
# Some problem tobe solved!
# =========================
# 1. Can you setup the whole system?
# 2. Is the benchmark good enough?
# 3. Can this auth by user/password?
user=$1
GRAPHITE_ROOT=/opt/graphite
# mkdir -p /opt/graphite/data
@TheWaWaR
TheWaWaR / QueryProcessor.py
Last active December 2, 2015 09:18
A way to write flask resultful view
class QueryProcessor():
FILTER_DICT = {
# f ==> field; v ==> value;
'contains' : lambda f, v: f.contains(v),
'~contains' : lambda f, v: ~f.contains(v),
'ilike' : lambda f, v: f.ilike(u'%{}%'.format(v)),
'~ilike' : lambda f, v: ~f.ilike(u'%{}%'.format(v)),
'like' : lambda f, v: f.like(u'%{}%'.format(v)),
'~like' : lambda f, v: ~f.like(u'%{}%'.format(v)),
'in' : lambda f, v: f.in_(v),
@TheWaWaR
TheWaWaR / supervisord.sh
Last active October 23, 2015 07:12 — forked from danmackinlay/supervisord.sh
An init.d script for supervisord >> $ sudo update-rc.d supervisord defaults
#!/bin/sh
### BEGIN INIT INFO
# Provides: supervisord
# Required-Start: $remote_fs
# Required-Stop: $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Example initscript
# Description: This file should be used to construct scripts to be
# placed in /etc/init.d.
@TheWaWaR
TheWaWaR / flask_dump_request_response.py
Last active December 30, 2024 03:39
Flask dump request and response example
#!/usr/bin/env python
# coding: utf-8
import os
import sys
import json
import uuid
import tempfile
from flask import Flask, request, Response, g
@TheWaWaR
TheWaWaR / test_flask_cache_ concurrency.py
Created August 17, 2015 03:00
Test flask cache concurrency.
#!/usr/bin/env python
#coding: utf-8
import sys
import time
from datetime import datetime
from flask import Flask
from flask.ext.cache import Cache
@TheWaWaR
TheWaWaR / goroutine-pool.go
Last active August 26, 2016 06:27
A simple goroutine worker pool. Ref: http://stackoverflow.com/a/18267889
func worker(linkChan chan string, wg *sync.WaitGroup) {
// Decreasing internal counter for wait-group as soon as goroutine finishes
defer wg.Done()
for url := range linkChan {
// Analyze value and do the job here
}
}
func main() {