Skip to content

Instantly share code, notes, and snippets.

@hughfdjackson
hughfdjackson / gist:2888929
Created June 7, 2012 13:58
'Respectable' browserbased game store requirements
  • An unobtrusive revenue system, and possibly an api for in-game currency
  • A viewport that's either full-screen, or full-window. Distraction-free environment
var toggleWidget = function(selector){
var state = {
on: false
, onFunc: function(){}
, offFunc: function(){}
, $el: $(selector)
}
o.$el.mouseenter(function(){
function Foo() {this.bak = 'bax';}
Object.prototype.bar = 'baz5';
Foo.prototype.bar = 'baz';
Foo.bam = 'ban';
var foo = new Foo();
/*
At this point, the chains are:
Foo -> Function.prototype -> null
foo -> Foo.prototype -> Object.prototype -> null
var client = new XMLHttpRequest();
client.open('GET', 'maxid.php', false);
client.send(null);
maxid=client.responseText;
JSON.parse(maxid);
return maxid;
(function($, root) {
root.x24 = {
slide: new Backbone.Model.extend({
id: 'i1',
title: 't1',
text: 'tt1',
link: 'l1'
})
}
for (var i = 0; i < 10; i++) {
process.nextTick(function (i) { console.log(i); }.bind(this, i));
}
// Prints 10 x 10 times
// I want it to print 1 - 10 without using an external array to store i
/*
In browser test edition
function loadFunction() {
var obj = {};
Request({
url: "http://0.0.0.0:4567/annotations/" + annotationId,
onComplete: function (response) {
if ( obj.oncomplete ) obj.oncomplete(response);
}
}).get();
var MyClass = function() {
this.cosa = 0;
console.log('constructor');
};
(function() {
var func1 = function() {
console.log('func1');
console.log(this.cosa);
};
@hughfdjackson
hughfdjackson / gist:2725819
Created May 18, 2012 15:17 — forked from yorickvP/gist:2725801
Simple (regex) routing in JavaScript
module.exports = function router() {
function router(method, url) {
var r = get_routes(method), rl = r.length
for (var i = 0; i < rl; ++i) {
if (r[i].type == 'string') {
if (r[i].url == url)
return [[url], r[i].callback] }
else {
var route = r[i]
@hughfdjackson
hughfdjackson / gist:2655842
Created May 10, 2012 20:57
Awfully silly interfaces
var interface = function(inter){
return {
test: function(testee) {
for ( var prop in inter ) {
if ( !(prop in testee) ) return false }
return true
}
}
}