Skip to content

Instantly share code, notes, and snippets.

View randallb's full-sized avatar
🎬

Randall Bennett randallb

🎬
View GitHub Profile
exports.register = function(req, res, next) {
var client;
client = this.client;
return exports.validate(req, res, function() {
return client.hmset("person:" + req.body.wid, req.body, function(err, response) {
if (err != null) {
return next(err);
} else {
req.newUser = req.body;
console.log("success. Saved record.");
exports.list = (req, res, next) ->
users = new Array
getList (err, response) ->
if err?
next err
else
people = response
for person in people
getUser person, (err, callback) ->
users.push(response)
var getUsers;
getUsers = function(peopleArray, callback) {
var person, _i, _len, _results;
_results = [];
for (_i = 0, _len = people.length; _i < _len; _i++) {
person = people[_i];
_results.push(getUser(person, function(err, response) {
users.push(response);
return res.users = users;
}));
@randallb
randallb / gist:1108725
Created July 27, 2011 05:14
Bug.js app
// Main bug.js app
express = require("express");
app = express.createServer();
bugmodel = require("./bugmodel");
anotherContext = function(req, res, next){
bugmodel.test();
};
@randallb
randallb / gist:1108728
Created July 27, 2011 05:15
bugmodel.js
exports.test = function(){
console.log(this)
}
app.get "/person/:wid("+ people.idRegex +")/remove"
becomes
app.get("/person/:wid(" + people.idRegex(+")/remove"));
when I'm trying to get
app.get("/person/:wid(" + people.idRegex +")/remove");
for relation in relations
for key, value of relation
console.log "#{key}: #{value}"
if typeof value is "object"
for subkey, subvalue of value
console.log "inner: #{subkey}: #{subvalue}"
if subvalue is "newId"
console.log "I changed #{subkey} from #{subvalue} to #{id}."
value[subvalue] = id
console.log subvalue
@randallb
randallb / gist:1541195
Created December 30, 2011 19:46
Testing addresses for Utopia service
#txt = $("h1.street-address").text() #fron Trulia
txt = "56 East 7720 S, Midvale UT 84047" #bad
txt = "268 Park St, Midvale UT 84047" #good
htmler = ""
re1='(.*?),'
re2='.*?'
re3='((?:[a-z][a-z]+))'
re4='.*?'
re5='((?:(?:AL)|(?:AK)|(?:AS)|(?:AZ)|(?:AR)|(?:CA)|(?:CO)|(?:CT)|(?:DE)|(?:DC)|(?:FM)|(?:FL)|(?:GA)|(?:GU)|(?:HI)|(?:ID)|(?:IL)|(?:IN)|(?:IA)|(?:KS)|(?:KY)|(?:LA)|(?:ME)|(?:MH)|(?:MD)|(?:MA)|(?:MI)|(?:MN)|(?:MS)|(?:MO)|(?:MT)|(?:NE)|(?:NV)|(?:NH)|(?:NJ)|(?:NM)|(?:NY)|(?:NC)|(?:ND)|(?:MP)|(?:OH)|(?:OK)|(?:OR)|(?:PW)|(?:PA)|(?:PR)|(?:RI)|(?:SC)|(?:SD)|(?:TN)|(?:TX)|(?:UT)|(?:VT)|(?:VI)|(?:VA)|(?:WA)|(?:WV)|(?:WI)|(?:WY)))(?![a-z])'
@randallb
randallb / gist:1541231
Created December 30, 2011 19:57
Merrickified bookmarklet
var htmler, m, p, queryString, re1, re2, re3, re4, re5, re6, re7, txt;
txt = "56 East 7720 S, Midvale UT 84047";
txt = "268 Park St, Midvale UT 84047";
htmler = "";
re1 = '(.*?),';
exports.Item = class PostView extends Backbone.View
template: require "../templates/post.jade"
events:
"click" : "loadDetails"
render: () =>
debug @model.toJSON()
$(@el).html(@template @model.toJSON())
@
loadDetails: () =>