Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View mrjjwright's full-sized avatar

John Wright mrjjwright

View GitHub Profile
@mrjjwright
mrjjwright / calculate.m
Created August 20, 2011 18:47
Calculate height for a given row
- (CGFloat)tableView:(TUITableView *)tableView heightForRowAtIndexPath:(TUIFastIndexPath *)indexPath
{
CGFloat calcuatedHeight = 55.0;
NSDictionary *post = [_posts objectAtIndex:indexPath.row];
NSString *type = [post valueForKey:@"type"];
NSString *message = [post valueForKey:@"message"];
if (!message) message = type;
TUIAttributedString *s = [TUIAttributedString stringWithString:message];
[s setAlignment:TUITextAlignmentLeft lineBreakMode:TUILineBreakModeWordWrap];
s.color = [TUIColor blackColor];
@mrjjwright
mrjjwright / NewTableCellView.m
Created August 20, 2011 17:52
Calculate height for a custom cell
//
// 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 / App.coffee
Created June 29, 2011 22:13
Connect to DNode
# 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
@mrjjwright
mrjjwright / Backbone_sync_dnode.coffee
Created June 29, 2011 21:49
Backbone Sync using dnode
# 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 / signin_view.coffee
Created June 29, 2011 22:40
Backbone SignIn View that uses dnode
modalContent = """
<li>
<input id="email" placeholder="Email" type="text"></input>
</li>
<li>
<input id="password" placeholder="Password" type="password"></input>
</li>
"""
@mrjjwright
mrjjwright / backbone_http_mapping.js
Created June 21, 2011 14:38
Default Backbone HTTP Verb Mapping
// Map from CRUD to HTTP for our default `Backbone.sync` implementation.
var methodMap = {
'create': 'POST',
'update': 'PUT',
'delete': 'DELETE',
'read' : 'GET'
};
@mrjjwright
mrjjwright / expose_secure_db.coffee
Created June 21, 2011 15:17
Expose Secure DB over node
# 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 June 21, 2011 15:09
A Secure MongoDB like API
# 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?
# 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
# 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.