Skip to content

Instantly share code, notes, and snippets.

View kevinslin's full-sized avatar

Kevin Lin kevinslin

View GitHub Profile
@kevinslin
kevinslin / hello.random.java
Created March 8, 2013 13:43
#java #cool "Random" Hello world
// source: http://stackoverflow.com/questions/15182496/why-does-this-code-print-hello-world?newsletter=1&nlcode=83359%7c512e
System.out.println(randomString(-229985452) + " " + randomString(-147909649));
public static String randomString(int i)
{
Random ran = new Random(i);
StringBuilder sb = new StringBuilder();
for (int n = 0; ; n++)
import random
def compare_with_ties(a, b):
diff = cmp(a, b)
return diff if diff else random.choice([-1, 1])
a = {'a': 1, 'b': 2, 'c': 1, 'd':2, 'e': 1}
print "Initial dictionary:\n", str(a.iteritems())
import random
def compare_with_ties(a, b):
diff = cmp(a, b)
return diff if diff else random.choice([-1, 1])
a = {'a': 1, 'b': 2, 'c': 1, 'd':2, 'e': 1}
print "Initial dictionary:\n", str(a.iteritems())
@kevinslin
kevinslin / instal.txt
Created March 4, 2013 19:52
#unsorted Install application into mac
cd /Applications && curl http://www.ninjamonkeysoftware.com/slate/versions/slate-latest.tar.gz | tar -xz
@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')):
@kevinslin
kevinslin / nginx_modules.sh
Last active December 12, 2015 12:49
#nginx
nginx -V 2>&1 | tr -- - '\n' | grep _module
@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 / 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 / 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 / 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