This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mySchema.statics.upsert = function (conditions, update, callback) { | |
this.findOne(conditions, function (err, existingDoc) { | |
if (err) { | |
callback(err); | |
} else if (existingDoc) { | |
// I don't think this is valid | |
existingDoc.update(update); | |
existingDoc.save(callback); | |
} else { | |
return this.create(update, callback); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mySchema.statics.validateAndUpsert = function (conditions, update, callback) { | |
var updateModel = new this(update); | |
updateModel.validate(function (err) { | |
if (err) { | |
callback(err); | |
} else { | |
this.findOneAndUpdate(conditions, update, { upsert: true}, callback); | |
} | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vagrant@heroku:~$ sudo su postgres | |
$ psql | |
psql (9.1.9) | |
Type "help" for help. | |
postgres=# SELECT rolname FROM pg_roles; | |
rolname | |
---------- | |
postgres | |
vagrant |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://developers.google.com/latitude/v1/using#ListingHistory | |
var minTimeMs = 0, // Earliest location to pull, 1st Jan 1070 seems far back enough. | |
maxTimeMs = Date.new().getTime(), // Latest location to pull, now. | |
lastResponse = []; | |
while { | |
// it is assumed this returns a max of 1000 locations in reverse chronological order, | |
// most recent location before maxTime first, | |
// then 999 more locations going back in time. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var testCollection = require('mongojs')('test').collection('testCollection'), | |
shouldBeOneDoc = testCollection.find({}).sort({ myField : 1 }).limit(1); | |
shouldBeOneDoc.count(function (err, count) { console.log(count) }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Mocha test | |
to use: | |
npm install mocha | |
mocha <filename> | |
or | |
npm test | |
*/ | |
var assert = require('assert'); | |
var tzwhere = require('../lib/index'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.routes = function() { | |
this.get('/', function() { | |
var users = db.collection('users'); | |
this.res.setHeader("Content-Type", 'text/html'); | |
this.res.writeHead(200, {}); | |
var that = this; | |
var stream = users.find().forEach(function(err, userDoc) { | |
if(userDoc) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34.442688693689824,-113.53830101755034 | |
34.33576843364106,-113.42973400738283 | |
34.44648524918964,-113.52317003164038 | |
34.41614244624507,-113.42110221380793 | |
34.443154610235155,-113.49498783458732 | |
34.43219600146056,-113.43444706591943 | |
34.36054463655045,-113.53565715125131 | |
34.427160925658754,-113.47398007995909 | |
34.43880963756491,-113.43854457484196 | |
34.37758904544772,-113.51267759234292 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Running command: | |
curl -o latest.dump `heroku pgbackups:url --app xxxxx` | |
At 100% we get: --> | |
<Error><Code>AccessDenied</Code><Message>Request has expired</Message><RequestId>xxxxxxx</RequestId><Expires>2013-03-21T16:02:26Z</Expires><HostId>xxxxxxx</HostId><ServerTime>2013-03-21T16:50:38Z</ServerTime></Error> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/routes.rb | |
resources :places, only: [:index, :edit, :update], constraints: {format: :json} do | |
collection do | |
get 'map' | |
end | |
# app/controllers/places_controller.rb |