Skip to content

Instantly share code, notes, and snippets.

View yxkelan's full-sized avatar

Yuan Xie yxkelan

  • San Francisco, CA
View GitHub Profile
@yxkelan
yxkelan / gist:5938500
Last active December 19, 2015 10:09
#CSS How to set equal-height columns
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<style>
.box{
width:250px;
margin-left:25px;
float:left;
display:inline;
@yxkelan
yxkelan / gist:5938448
Created July 6, 2013 02:57
#JavaScript Using closure to implement simple animation.
function animated(id){
var elem = document.getElementById(id);
var tick = 0;
var timer = setInterval(function(){
if(tick < 100){
elem.style.left = elem.style.top = tick + 'px';
tick ++;
}else{
clearInterval(timer);
@yxkelan
yxkelan / gist:5579890
Created May 14, 2013 21:50
#CSS3 Gradient
Very good examples for 'CSS3 Gradient'. http://css-tricks.com/examples/CSS3Gradient/

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt
@yxkelan
yxkelan / check_anagram.py
Created April 10, 2013 05:42
#String Check 2 strings are anagrams or not
def check_anagram(x,y):
''' check_anagram(string,string): check if 2 strings are anagrams'''
try:
if not len(x) == len(y):
return False
chars_dict={}
@yxkelan
yxkelan / test_funcs.py
Created April 10, 2013 01:22
#Python test functions
# This module includes all the functions that used for test.
def testEqual(a,b):
"""testEqual(a,b)--- a : the expression you want to test, b: the value you expect to get"""
if a == b:
print True
else:
print False
@yxkelan
yxkelan / humansize.py
Last active December 15, 2015 18:48
humansize.py , from Dive into Python 3
SUFFIXES = {
1000: ['KB','MB','GB','TB','PB','EB','ZB','YB'],
1024: ['KiB','MiB','GiB','TiB','PiB','EiB','ZiB','YiB']
}
def approximate_size(size, a_kilobyte_is_1024_bytes = True):
'''Convert a file size to human-readable form.
Keyword arguments:
size --- file size in bytes
@yxkelan
yxkelan / gist:5157158
Created March 13, 2013 22:49
Style a select menu with CSS. The original one is on http://www.cssflow.com/snippets/dark-and-light-dropdown-lists
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
<!--[if lt IE 7]> <html class="lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="lt-ie9 lt-ie8" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="lt-ie9" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html lang="en"> <!--<![endif]-->
</head>
@yxkelan
yxkelan / gist:5114484
Last active December 14, 2015 16:19
JavaScript Scope !!! * scope are declared as function, not as {} block. * function declaration will be hoisted within scope but variables can't.
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
<style>
.pass{color:green;}
.fail{color:red;}
</style>
</head>
@yxkelan
yxkelan / gist:5095821
Last active December 14, 2015 13:48
The assertion, from "Secrets of JavaScript Ninja". 1, Simple test assertion function. 2, Test groups. 3, Asynchronous testing.
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
<style>
li.pass{
color:green;
}
li.fail{