Skip to content

Instantly share code, notes, and snippets.

View kevinslin's full-sized avatar

Kevin Lin kevinslin

View GitHub Profile
rm(list=ls())
@kevinslin
kevinslin / gist:1260863
Created October 4, 2011 03:50
Change Timezone in Unix System
sudo dpkg-reconfigure tzdata
@kevinslin
kevinslin / Click
Created October 20, 2011 18:27
Simulate a click using javacsript
function simulatedClick(target, options) {
var event = target.ownerDocument.createEvent('MouseEvents'),
options = options || {};
//Set your default options to the right of ||
var opts = {
type: options.click || 'click',
canBubble:options.canBubble || true,
cancelable:options.cancelable || true,
@kevinslin
kevinslin / gist:1490982
Created December 17, 2011 18:27
Simple Fibonacci finder
#python, #elegant, #example
def fib(n):
" Generate fib sequence up to n "
a, b = 0, 1
while (b < n):
print b
a, b = b, a + b
@kevinslin
kevinslin / quicksort.py
Created December 20, 2011 16:00
Quicksort
def quicksort(lst, left=0, right=None):
if right is None:
right = len(lst) - 1
l = left
r = right
if l <= r:
mid = lst[(left+right)/2]
while l <= r:
while l <= right and lst[l] < mid:
l += 1
@kevinslin
kevinslin / jquery.js
Created January 17, 2012 23:16
Include Jquery
down vote accepted
From http://erikvold.com/blog/index.cfm/2010/6/14/using-jquery-with-a-user-script
// ==UserScript==
// @name jQuery For Chrome (A Cross Browser Example)
// @namespace jQueryForChromeExample
// @include *
// @author Erik Vergobbi Vold & Tyler G. Hicks-Wright
@kevinslin
kevinslin / automata.py
Created May 9, 2012 17:34
A finite state automata
from optparse import OptionParser
from collections import defaultdict
def run(inputWord):
a, states = open("avtomat.txt") ,defaultdict(list)
state, final= a.readline().split()[1:],a.readline().split()[1:]
[states[(i.split()[0], i.split()[1])].append(i.split()[3]) for i in a]
for letter in inputWord:
@kevinslin
kevinslin / contiguous.py
Last active December 12, 2015 12:29
#python #unsorted
# http://stackoverflow.com/questions/14721406/pythonic-way-to-determine-whether-not-null-list-entries-are-continuous?newsletter=1&nlcode=83359%7c512e
from itertools import groupby
def contiguous(seq):
return sum(1 for k,g in groupby(seq, lambda x: x is not None) if k) == 1
@kevinslin
kevinslin / nginx_modules.sh
Last active December 12, 2015 12:49
#nginx
nginx -V 2>&1 | tr -- - '\n' | grep _module
@kevinslin
kevinslin / key_check.py
Created March 3, 2013 04:12
#cool #one-line Check if multiple keys are in the dict
if all(u in POST for u in ('skill', 'description')):