Skip to content

Instantly share code, notes, and snippets.

@zhy0216
zhy0216 / gist:ed2cb6d57671b3701b72
Last active August 29, 2015 14:04
permutation.py
def gen_permutation(string):
if len(string) == 1:
yield string
for char in string:
rest = string.replace(char, "")
for p_string in gen_permutation(rest):
yield char + p_string
@zhy0216
zhy0216 / autocrop.py
Created March 28, 2015 01:53
Remove any unnecessary whitespace from the edges of the source image
# copy from easy_thumbnails
from PIL import Image, ImageChops
def is_transparent(image):
"""
Check to see if an image is transparent.
"""
if not isinstance(image, Image.Image):
# Can only deal with PIL images, fall back to the assumption that that
# it's not transparent.
@zhy0216
zhy0216 / responsive-table.js
Created April 7, 2015 13:52
responsive table
$(function(){
var threadNames = [];
$('th').each(function(i){
threadNames.push($(this).html());
});
var style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = "@media "+
@zhy0216
zhy0216 / sublime-setting
Last active December 26, 2015 17:59
sublime 3 setting
{
"color_scheme": "Packages/Color Scheme - Default/Solarized (Dark).tmTheme",
"font_size": 14,
"ignored_packages":
[
"Vintage"
],
"theme": "Spacegray.sublime-theme",
"translate_tabs_to_spaces": true,
"update_check": false,
@zhy0216
zhy0216 / sublime-keymap
Created October 28, 2013 03:17
sublime keybinding
[
{ "keys": ["ctrl+d"], "command": "run_macro_file", "args": {"file": "res://Packages/Default/Delete Line.sublime-macro"} },
{ "keys": ["ctrl+up"], "command": "swap_line_up" },
{ "keys": ["ctrl+down"], "command": "swap_line_down" },
{ "keys": ["ctrl+alt+l"], "command": "beautify" },
]
@zhy0216
zhy0216 / router
Created November 15, 2013 05:23
an easy js router
/**
Usage:
app.addRoute("/user/<userid>/", function(){
console.log("userid:", this.userid);
}).addRoute("/post/<postid>/", function(){
console.log("postid:", this.postid);
}).addRoute("/post/<postid>/comments", function(){
console.log("comment of post");
})
app.startMain("/user/1/"); // >>> userid: 1
@zhy0216
zhy0216 / collection.css
Created December 16, 2013 01:55
some useful or tricky css
.yue {
font: 400 18px/1.62 "Georgia", "Xin Gothic", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft YaHei", "SimSun", sans-serif;
color: #333332;
}
@zhy0216
zhy0216 / font
Last active January 3, 2016 02:09
font collection
Redressed: [https://www.google.com/fonts/specimen/Redressed](https://www.google.com/fonts/specimen/Redressed)
@zhy0216
zhy0216 / gist:8398685
Created January 13, 2014 11:22
useful app
ngrok: https://ngrok.com/ # Introspected tunnels to localhost
class Solution(object):
def invertTree(self, root):
"""
:type root: TreeNode
:rtype: TreeNode
"""
if root is None:
return root
if root.left: