This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
A simple wrapper make a class become a functor, | |
the class need a __call__ function. The (*sub, | |
**kwargs) will be passed for the __init__ function, | |
and the name of class will be the name of function | |
object. | |
Example | |
------- | |
@functor(*sub, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; cmd | |
;; ---------- | |
;;; Open the cmd in the current directory. | |
(defun cmd () | |
"Open the cmd in the current directory." | |
(interactive) | |
(w32-shell-execute | |
"open" | |
"cmd")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import httplib2 | |
# set proxy_rdns=True to ensure use the dns on | |
# remote proxy, in case local DNS is pulluted. | |
proxy = httplib2.ProxyInfo(httplib2.socks.PROXY_TYPE_HTTP, | |
'localhost', 8000, | |
proxy_rdns=True) | |
http = httplib2.Http(proxy_info=proxy) | |
http.request('http://google.com') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import signal | |
import time | |
from signal_inject import * | |
def dummy_handler(signum, frame): | |
print "In dummy handler" | |
inject_signal_handler(signal.SIGINT, dummy_handler) | |
while 1: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Get the Linux birth time of the system or a process using /proc/stat | |
and /proc/pid/stat. | |
For example, you may get local datetime when process 12345 started: | |
import datetime | |
import btime | |
datetime.datetime.fromtimestamp(btime.process_time(12456)[1]) | |
''' | |
import os |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import json | |
def compact_json_dumps(*sub, **kw): | |
''' | |
A wrapper of json.dumps support an optional compact_length parameter. | |
compact_length take effects when indent > 0, will return a more compact | |
indented result, i.e., pretty and compact json dumps. | |
''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name better data.stats.gov.cn | |
// @namespace https://gist.github.com/socrateslee/69169c58be9cf2e0e3019b09b680461b | |
// @version 0.1 | |
// @description Inject css for better display of data.stats.gov.cn | |
// @author https://github.com/socrateslee | |
// @include http://data.stats.gov.cn/easyquery.htm* | |
// @grant none | |
// ==/UserScript== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# An pure python implemetation of Dynamic Time Warpping | |
# http://en.wikipedia.org/wiki/Dynamic_time_warping | |
class Dtw(object): | |
def __init__(self, seq1, seq2, distance_func=None): | |
''' | |
seq1, seq2 are two lists, | |
distance_func is a function for calculating |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
An object stores the change history of its attributes, | |
the object can be use to store the hierarchies of different | |
levels of configurations. | |
Example | |
------- | |
# Set up config object | |
config = TracedObj() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Wider Yuque | |
// @namespace https://gist.github.com/socrateslee/751c6670c59d5b9cdbd8428fab493375 | |
// @version 0.1 | |
// @description Let yuque a bit wider on browser screen. | |
// @author github.com/socrateslee | |
// @include https://*.yuque.com/* | |
// @grant none | |
// ==/UserScript== |
OlderNewer