Skip to content

Instantly share code, notes, and snippets.

@mrjjwright
mrjjwright / NewTableCellView.m
Created Aug 20, 2011
Calculate height for a custom cell
View NewTableCellView.m
//
// NewsTableCellView.m
// Crew
//
// Created by John Wright on 8/18/11.
// Copyright 2011 QuickLeft. All rights reserved.
//
#import "PostCellView.h"
#import "Crew.h"
@mrjjwright
mrjjwright / maskNSImage.c
Created Jul 26, 2011
Fill opaque parts of NSImage with color
View maskNSImage.c
+ (NSImage *)maskImageNamed:(NSString *)name color:(NSColor *)color
{
NSImage *image = [NSImage imageNamed:name];
CGRect rect = CGRectMake(0, 0, image.size.width, image.size.height);
CGContextRef c = MyCreateBitmapContext(image.size.width, image.size.height);
[image drawInRect:rect fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
CGContextSetFillColorWithColor(c, [color CGColor]);
CGContextSetBlendMode(c, kCGBlendModeSourceAtop);
CGContextFillRect(c, rect);
CGImageRef ciImage = CGBitmapContextCreateImage(c);
@mrjjwright
mrjjwright / signin_view.coffee
Created Jun 29, 2011
Backbone SignIn View that uses dnode
View signin_view.coffee
modalContent = """
<li>
<input id="email" placeholder="Email" type="text"></input>
</li>
<li>
<input id="password" placeholder="Password" type="password"></input>
</li>
"""
@mrjjwright
mrjjwright / App.coffee
Created Jun 29, 2011
Connect to DNode
View App.coffee
# The root namespace for your app
# Everything starts from here.
window.App =
start: ->
# Connect to DNode
DNode.connect (remote) ->
try
# Our remote db object
App.db = remote.db
View Backbone_sync_dnode.coffee
# Overwrite the Backbone sync method to use Dnode and rbdb
Backbone.sync = (method, model, success, error) ->
# Backbone Models have a "hasChanged" function, distinguishing them from Collections
isCollection = if model.hasChanged? then false else true
# Each model has a collection name, the collection in our MongoDB API
collectionName = if isCollection then new (model.model)().collectionName() else model.collectionName()
# A generic response handler using Node style callbacks to invoke Backbone success/error handlers
handleResponse = (err, obj) ->
if err?
@mrjjwright
mrjjwright / expose_secure_db.coffee
Created Jun 21, 2011
Expose Secure DB over node
View expose_secure_db.coffee
# Start up the http server
console.log("Starting on port #{options.port}")
server.listen(options.port)
# Start up dnode and expose our remote secure API to the user. This API has built-in token based security so we will be ok if the
# web-socket is over https
remote =
db: dbSecure
dnode(remote).listen(server)
@mrjjwright
mrjjwright / secure_db.coffee
Created Jun 21, 2011
A Secure MongoDB like API
View secure_db.coffee
# Now create a secure API to this
# library that requires authentication
# Users can only access these collections
collectionWhiteList = ["records", "sources", "searchers"]
# These collections don't need any authentication at all for
findWithNoAuthentication = ["sources"]
secureTemplate = (user, collectionName, cb, doneCB) ->
if not user? or not user.accessToken?
@mrjjwright
mrjjwright / backbone_http_mapping.js
Created Jun 21, 2011
Default Backbone HTTP Verb Mapping
View backbone_http_mapping.js
// Map from CRUD to HTTP for our default `Backbone.sync` implementation.
var methodMap = {
'create': 'POST',
'update': 'PUT',
'delete': 'DELETE',
'read' : 'GET'
};
View Bus.coffee
# Bus 0.1(alpha)
# (c) 2010 John Wright, QuickLeft Inc.
# Bus may be freely distributed under the MIT license.
# For all details and documentation:
# http://github.com/mrjjwright/Bus
#
#
#
# Bus would not be possible without Jeremy Ashkenas who wrote CoffeeScript, the language
View sloth.coffee
# sloth 0.1(alpha)
# Version for Node.js.
# (c) 2010 John Wright, QuickLeft Inc.
# sloth may be freely distributed under the MIT license.
# For all details and documentation:
# http://github.com/mrjjwright/sloth
#
#
# Sloth is a content based JSON store. It tracks changes in the content of JSON objects, not ids, uuids or timestamps.