Skip to content

Instantly share code, notes, and snippets.

View seanmonstar's full-sized avatar

Sean McArthur seanmonstar

View GitHub Profile
var recipeList = new ListView({
title: 'Recipes',
dataProvider: recipes,
display: '{name} - {difficulty}',
onItemSelect: function(item) {
}
});
panel.grab(recipeList);
var A = new Class({
initialize: $empty,
a: function() {
return arguments.callee.caller.caller.caller._name;
},
b: function() {
console.log(this.a()); //knows 'b' called it
}
});
function range(min, max) {
if(!max) {
max = min;
min = 0;
}
var arr = [];
for(var i = min; i <= max; i++) {
arr.push(i);
}
return arr;
Function.prototype.lazy = function() {
var fn = this,
init = false;
return function() {
if(!init) {
init = true;
fn = fn.apply(this, arguments);
}
return fn.apply(this, arguments);
}
<label>
<span>Always switch:</span>
<input type="checkbox" name="change" id="change" />
</label>
<button type="button" id="btn">Loop</button>​
@seanmonstar
seanmonstar / Array.batch.js
Created October 26, 2010 04:14
Similar to Array.each, but loops in batches, use setTimeout to allow the Browser thread to do other things, like respond to UI events and changes. Useful for really big arrays, or really intensive functions.
Array.implement('batch', function(callback, loopsPerBatch, delay, bind) {
if(!loopsPerBatch) loopsPerBatch = 10;
if(!delay) delay = 50;
if(callback) {
var loops = 0,
index = 0,
that = this;
function doLoops() {
loops = 0;
for (var length = that.length; (index < length) && loops < loopsPerBatch; index++) {
@seanmonstar
seanmonstar / tumblr-backup.py
Created December 7, 2010 06:58
Makes a backup of your tumblr blog.
#!/usr/bin/env python
import os
import sys
import urllib2
from xml.dom import minidom
from datetime import datetime
def url_request(url):
text = None
Collapse.Stateful = new Class({
// or perhaps Collapse.Persistant?
Extends: Collapse,
options: {
getAttribute: function(element){
return element.get('id');
},
var extend = function(child, parent) {
for(var i in parent) {
if(parent.hasOwnProperty(i)) {
child[i] = parent[i];
}
}
return child;
};
@seanmonstar
seanmonstar / base.managers.py
Created May 26, 2011 22:40
QuerySetManager
class QuerySetManager(models.Manager):
def get_query_set(self):
return self.QuerySet(self.model)
def __getattr__(self, attr, *args):
return getattr(self.get_query_set(), attr, *args)