Skip to content

Instantly share code, notes, and snippets.

View muloka's full-sized avatar
💖
I may be slow to respond.

Muloka muloka

💖
I may be slow to respond.
View GitHub Profile
// Part 1.
// Implement a function prototype extension that caches function results for
// the same input arguments of a function with one parameter.
//
// For example:
// Make sin(1) have the result of Math.sin(1), but use a cached value
// for future calls.
var sin = function() { return (arguments.length === 0) ? false : Math.sin(arguments[0]); }
<div id="the_div">
<ul id="the_list">
<li id="the_item">Click me!</li>
</ul>
</div>
<p id="log"></p>
<script type="text/javascript" charset="utf-8">
function log(string){
(function(){ alert('later!'); }).delay(1);
// function is called 1 second later ^^
Function.prototype.delay = function(seconds){
setTimeout(this, seconds*1000);
};
function forEach(array, method) {
var l = {};
for( l.ii = 1; l.ii <= arraylen(arguments.array); l.ii++ ) {
method(arguments.array[l.ii]);
}
}
function writeNow(str) {
writeOutput(str);
writeOutput('+');
@muloka
muloka / gist:935527
Created April 21, 2011 21:26
clearing input fields w/o switch/case
jQuery('#' + form_id).find(':input').each(function(i,e) {
// list of types to clear with default values
var obj = {
'text' : ''
, 'select-one': 0
};
if (obj[e.type] !== undefined) {
jQuery(e).val(obj[e.type]);
}
});
String.prototype.trim = function() {
return this.replace(/^\s+|\s+$/g, '');
};
String.prototype.isNumber = function() {
return typeof parseFloat(this, 10) === 'number' && isFinite(this) && this.trim().length > 0;
};
// saw this on Forrst, forget who posted it though
$('[href$="pdf"],.pdf').live("click", function(){
// get the link attribute and find the filename of the PDF
var pdfLink = $(this).attr("href"),
pdfLocation = pdfLink.substr(pdfLink.lastIndexOf("/")).replace("/","");
_gaq.push(['_trackPageview', pdfLocation]);
});
info it worked if it ends with ok
verbose cli [ 'node',
verbose cli '/Users/muloka/src/npm/cli.js',
verbose cli 'install',
verbose cli '-g',
verbose cli '-f' ]
info using npm@1.0.26
info using node@v0.5.5-pre
verbose config file /Users/muloka/.npmrc
verbose config file /Users/muloka/local/node/etc/npmrc
require 'formula'
class YoutubeDl <ScriptFileFormula
url 'https://github.com/phihag/youtube-dl/raw/master/youtube-dl'
homepage 'http://rg3.github.com/youtube-dl/'
md5 'a5b92351e8cfa663c888e7d24116477e'
version '2011.08.24-phihag'
end
SELECT stuff FROM [Product] p
JOIN [category] c ON
-- collating on the fly #FTW
c.[Name] COLLATE SQL_Latin1_General_CP1_CI_AS = p.[Name] COLLATE SQL_Latin1_General_CP1_CI_AS