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
@muloka
muloka / gist:809640
Created February 3, 2011 15:41
Code, create, and share
Code, create, and share
- create solutions to sore points
- reduce friction, stream line processes
- create projects that scratch an itch or ease some pain
- start contributing to official documentation efforts
- focus more on community and less on yourself
Remember, Code talks.
- Talk (and read) less, Code More
- If you want to run your own business, code is the perfect way to find cofounders and employees
@muloka
muloka / gist:853425
Created March 3, 2011 20:09
JSMC Exercise 2 - Closures
(function (functionName, container){
var index;
function log(){
console.log(index);
}
function iterate(){
log();
if(index>1) setTimeout(iterate, 1000);
@muloka
muloka / gist:853572
Created March 3, 2011 21:09
JSMC Exercise 3
// functional
var logCar = function (obj){
return function(){
"I'm a" + obj.color + " " + obj.make;
}
}
// Example call for functional version:
logCar({ color: 'blue', make: 'BMW' });
var logCar = function (obj){ return "I'm a" + obj.color + " " + obj.make; }
// 1. Write a class to support the following code:
var Person = function(name) { this.name = name; }
var thomas = new Person('Thomas');
var amy = new Person('Amy');
thomas.name // --> "Thomas"
// 2. Add a getName() method to all Person objects, that outputs
// 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]);
}
});