Skip to content

Instantly share code, notes, and snippets.

@socrateslee
socrateslee / SimpleDTW.cs
Created March 3, 2012 14:06
Simple DTW(Dynamic Time Wrapping) in C#
//http://data-matters.blogspot.com/2008/07/simple-implementation-of-dtwdynamic.html
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace DTW
{
@socrateslee
socrateslee / python-dtw.py
Created August 5, 2012 16:25
Simple DTW(Dynamic time wrapping) in python
# -*- 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
@socrateslee
socrateslee / stack_trace.py
Created November 4, 2012 11:24
A Stack Trace Decorator of Python Functions
import sys
import functools
'''
Usage:
consider following functions
import stack_trace
def foo():
pass
def bar():
@socrateslee
socrateslee / emacs_cmd_windows.el
Created March 13, 2013 10:10
Open the cmd in the current directory in Windows, place the gist in .emacs file.
;; cmd
;; ----------
;;; Open the cmd in the current directory.
(defun cmd ()
"Open the cmd in the current directory."
(interactive)
(w32-shell-execute
"open"
"cmd"))
@socrateslee
socrateslee / httplib2_remote_dns_proxy.py
Created March 26, 2013 05:31
Set remote dns for httplib2 proxy.
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')
@socrateslee
socrateslee / example.py
Created May 9, 2013 15:36
Inject a signal handler before the existed signal handler.
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:
@socrateslee
socrateslee / winpath.py
Created May 28, 2013 13:44
A simple command line tool for managing windows PATH variable in Windows Registry. Get help by `python winpath.py help`.
'''
A simple command line tool for managing windows PATH variable.
'''
import _winreg as winreg
import os
import sys
def choose_key(scope, write=False):
'''
@socrateslee
socrateslee / btime.py
Created May 30, 2013 04:21
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])
'''
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
@socrateslee
socrateslee / functor.py
Created May 28, 2014 06:23
A simple wrapper make a class become a functor.
'''
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)
@socrateslee
socrateslee / static-serve.go
Created June 18, 2014 14:56
Serving static files in current directory with golang. Simply a "python -m SimpleHTTPServer [PORT]" replacement written in golang. Use it as "static-serve [PORT]"
package main
import (
"net/http"
"os"
"fmt")
func main() {
port := "8080"
if len(os.Args) >= 2 {