Skip to content

Instantly share code, notes, and snippets.

@josephok
josephok / random_string.py
Last active August 29, 2015 13:57
Generate a random string with arbitrary length
import string
import random
def random_string(length):
return ''.join(random.sample(string.printable, length))
@josephok
josephok / random_string.coffee
Created March 27, 2014 01:44
Generate a random string with arbitrary length
random_string = (length) ->
id = ""
id += Math.random().toString(36).substr(2) while id.length < length
id.substr 0, length
@josephok
josephok / quicksort.coffee
Last active August 29, 2015 13:58
quick sort
quicksort = (array) ->
_quicksort = (array, left, right) ->
[i, j] = [left, right]
if left > right
return
pivot = array[left]
until i is j
while array[j] >= pivot and i < j
j--
@josephok
josephok / dict.py
Last active August 29, 2015 13:58
英译汉小词典
#!/usr/bin/python
import requests
import sys
from bs4 import BeautifulSoup
import functools
import re
from threading import Thread
RESET_COLOR = "\033[0m"
@josephok
josephok / counter.py
Last active August 29, 2015 13:59
Python closure
def new_counter():
i = 0
def nested():
nonlocal i
i += 1
return i
return nested
c = new_counter()
print(c())
@josephok
josephok / Fxcgz.markdown
Last active August 29, 2015 13:59
A Pen by Joseph.
@josephok
josephok / SassMeister-input-HTML.html
Created April 14, 2014 06:49
Generated by SassMeister.com.
<section></section>
@josephok
josephok / SassMeister-input-HTML.html
Created April 15, 2014 01:18
Generated by SassMeister.com.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf8">
<title>CSS特指度计算</title>
<link rel=stylesheet href="style.css" />
<style type="text/css">
em {color: blue;}
</style>
</head>
@josephok
josephok / SassMeister-input-HTML.html
Created April 15, 2014 01:22
Generated by SassMeister.com.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf8">
<title>CSS特指度计算</title>
<link rel=stylesheet href="style.css" />
<style type="text/css">
em {color: blue !important;}
</style>
</head>
@josephok
josephok / SassMeister-input-HTML.html
Created April 15, 2014 01:24
Generated by SassMeister.com.
<section id="one">1
</section>
<section id="two">2
</section>
<section id="three">3
</section>
<section id="four">4
</section>