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
// Simple JavaScript Templating | |
// John Resig - http://ejohn.org/ - MIT Licensed | |
(function(){ | |
var cache = {}; | |
this.tmpl = function tmpl(str, data){ | |
// Figure out if we're getting a template, or if we need to | |
// load the template - and be sure to cache the result. | |
var fn = !/\W/.test(str) ? | |
cache[str] = cache[str] || |
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; | |
}; |
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
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 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 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
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
;(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
<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 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 |
OlderNewer