Skip to content

Instantly share code, notes, and snippets.

View jameswomack's full-sized avatar
📈

James J. Womack jameswomack

📈
View GitHub Profile
@jameswomack
jameswomack / gist:1081396
Created July 13, 2011 21:40
Magazine API
//this
"editions":{
"4":{
"id":"4",
"name":"My First edition",
"date_created":"2011-07-10 21:31:12",
"date_last_updated":"2011-07-10 21:31:12"
}
}
@jameswomack
jameswomack / gist:1085291
Created July 15, 2011 18:58
API User->Magazine
//this
{
"magazines":{
"4":{
"id":"4",
"name":"Young Olmos",
"description":"The latest from San Diego's most original dirigible",
"creator":{
"id":"4",
"name":"James Womack"
@jameswomack
jameswomack / gist:1087912
Created July 17, 2011 18:41
User API -> Subscriptions : Subscriptions object broken
"subscriptions":[
{
"id":"1",
"name":"Mag 1",
"description":"Description for Magazine: 1",
"creator":{
"id":"1",
"name":"Chris Bull"
},
"date_created":"2011-07-16 15:12:38",
@jameswomack
jameswomack / authWithEmail.m
Created August 15, 2011 23:25
Example Login Method
/*
This is an example of sending a POST request to a server that returns a JSON object containing a user ID, API key, etc. isSnagazineReachable is a method for checking if the server is available first. The main work is done by creating an NSDictionary with the data you want to post, passing that to the CCWebUtils class method postToUrl:params: which returns an NSString of the server response.
*/
- (BOOL)authWithEmail:(NSString *)theEmail andPassword:(NSString *)thePassword; {
if (![[CCSnagazineDataSource sharedData] isSnagazineReachable]) {
Alert(0,nil,kNetworkDown,@"Ok",nil);
return FALSE;
}
if (![self userId] || ![self apiKey]) {
@jameswomack
jameswomack / window_events.js
Created August 16, 2012 22:05
Getting an array of all events possible on winow and use to remove all events from an object
window.__defineGetter__('events',function(){
var _events = [];
for (var k in window) {
if(k.match(/^on/)){
_events.push(k)
}
};
return _events;
});
@jameswomack
jameswomack / act.coffee
Created August 28, 2012 02:49
Technique for ensuring you have the info you need, and it's up to date
act: (context, f, keyPaths...) ->
ok = true
for k in keyPaths
if !context.get(k)?
ok = false
context.observe k, (newValue, oldValue, keyPath) =>
ok = true
for k in keyPaths
ok = context.get(k)?
return unless ok
@jameswomack
jameswomack / javascript_background_thread.js
Created September 11, 2012 06:41
Extend function prototype to run a function as a WebWorker
Function.prototype.runOnBackgroundThread = function (aCallback) {
var _blob = new Blob(['onmessage = '+this.toString()],{"type":"text/javascript"});
var _worker = new Worker((webkitURL.createObjectURL || URL.createObjectURL)(_blob));
_worker.onmessage = aCallback;
_worker.postMessage();
}
var _test = function () {
postMessage((1+1).toString());
}
var InlineWorker = function (theWorkerFunction,aCallback) {
var _blob = new Blob(['onmessage = '+theWorkerFunction.toString()],{"type":"text/javascript"});
var _worker = new Worker((webkitURL.createObjectURL || URL.createObjectURL)(_blob));
_worker.onmessage = aCallback;
this.postMessage = function(){_worker.postMessage.apply(_worker,Array.prototype.slice.call(arguments))};
return this;
}
var _inlineWorkerCode = function(e) {
//put anything that doesn't use window or document here
@jameswomack
jameswomack / html
Created September 28, 2012 08:13
Node.js proxy for couchdb audio
<audio controls="controls">
<source src="http://machine.local:8976/px/ttt/cry-bla.mp3" type="audio/mpeg">
</audio>
@jameswomack
jameswomack / hot.coffee
Created September 28, 2012 18:19
Call method when n events have fired
Batman.Object::actOnListeners = (context, f, objectEventPairs...) ->
_satisfiedObjects = []
for objectEventPair in objectEventPairs
objectEventPair[0].on objectEventPair[1], ->
_satisfiedObjects.add objectEventPair
f.apply theContext if objectEventPairs.exclude(_satisfiedObjects...).length is 0
@actOnListeners @, @showArticle, [[Brilliant,'ready'],[@get('currentArticleView'),'ready']]