This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Object.defineProperty(Object.prototype, 'extend', { | |
enumerable: false, | |
value: function (from) { | |
var props = Object.getOwnPropertyNames(from), | |
dest = this; | |
props.forEach(function(name) { | |
var destination; | |
if (name in dest) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function TypeOf () { | |
return Object.prototype.toString.call(this) | |
.replace(/(\bobject\b\s)/g, '') | |
.replace(/\[/g, '') | |
.replace(/\]/g, '') | |
.toLowerCase(); | |
}; | |
console.log(TypeOf.call({})); // object | |
console.log(TypeOf.call([])) // array |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/html" id="item_tmpl"> | |
<div id="<%=id%>" class="<%=(i % 2 == 1 ? " even" : "")%>"> | |
<div class="grid_1 alpha right"> | |
<img class="righted" src="<%=profile_image_url%>"/> | |
</div> | |
<div class="grid_6 omega contents"> | |
<p><b><a href="/<%=from_user%>"><%=from_user%></a>:</b> <%=text%></p> | |
</div> | |
</div> | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;(function (root) { | |
var defaults = { | |
defaultValue: 'thats a default value' | |
}; | |
// constructor class | |
function ClassName (options) { | |
this.options = $.extend(defaults, options); | |
console.log('im the constructor'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function gi() { | |
rm .gitignore; | |
(curl http://www.gitignore.io/api/$@) >> .gitignore; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ClassName = (function () { | |
var | |
// here is the place to inject private methods | |
_private = {}, | |
// all attributes values goes here | |
attributes = { | |
}; | |
function ClassName (args) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fn = function even (n) { | |
if (n === 0) { | |
return true | |
} | |
else return !even(n - 1) | |
} | |
fn(5); | |
//=> false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var truncate = function(string, n, terminator) { | |
if (typeof string !== 'string') { | |
return; | |
} | |
var lastIndex = string.lastIndexOf(' ', n), ret = string.toString(); | |
if(ret.length <= n) return ret; | |
if (lastIndex != -1) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var slug = function (text) { | |
return text | |
.toLowerCase() | |
.replace(/[^\w ]+/g,'') | |
.replace(/ +/g,'-'); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String.prototype.trunc = function(n){ | |
return this.length>n ? this.substr(0,n-1)+'…' : this; | |
}; |