Skip to content

Instantly share code, notes, and snippets.

@houoop
houoop / js-date-format.js
Created May 10, 2013 08:30
format js date
var formatDate = function(time) {
return [time.getFullYear(), '-', time.getMonth() + 1, '-', time.getDate(),
' ', time.getHours(), ':', time.getMinutes(), ':',
time.getSeconds()].join('');
};
@houoop
houoop / underscore for rails.js
Created May 7, 2013 09:30
underscore template for rails
_.templateSettings = {
interpolate: /\{\{\=(.+?)\}\}/g,
evaluate: /\{\{(.+?)\}\}/g
};
@houoop
houoop / pre-commit.py
Created April 28, 2013 09:56
git pre-commit jshit
#!/usr/bin/env python
import os, sys
"""
Checks your git commit with JSHint. Only checks staged files
"""
def jshint():
errors = []
@houoop
houoop / get-tomorrow-date.js
Created April 28, 2013 03:44
js get tomorrow date
new Date(new Date().getTime() + 24 * 60 * 60 * 1000)
@houoop
houoop / js-event-bind.js
Created April 27, 2013 09:41
js event bind
bind: window.dispatchEvent ? function(el, type, fn, phase) {
el.addEventListener(type, fn, !!phase);
return fn;
} : function(el, type, fn) {
el.attachEvent && el.attachEvent("on" + type, fn);
return fn;
}
Sublime Text 2 - Default shortcuts cheatsheet (PC keyboard)
-----------------
General
-----------------
* Go to file (CTRL + P)
* Go to project (CTRL + ALT + P)
* Go to methods (CTRL + R)
* Go to line (CTRL + G)
* Toggle side bar (CTRL + KB)
@houoop
houoop / uuid.js
Created March 29, 2013 03:08
uuid generater
function S4() {
return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
}
function guid() {
return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
}
@houoop
houoop / array dedupe
Created March 21, 2013 05:33
JS数组去重
Array.prototype.dedupe=function () {
var hash={},result=[],
hasown=Object.prototype.hasOwnProperty;
for (var i = this.length - 1; i >= 0; i--) {
if(!hasown.call(hash,this[i])){
hash[this[i]]=1;
result.push(this[i]);
}
};
return result;
@houoop
houoop / css-ellipsis.css
Created January 26, 2013 07:09
CSS 超出文字变省略号
width: 200px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
<!--[if lte IE 7]>
<![endif]-->