Skip to content

Instantly share code, notes, and snippets.

View timhudson's full-sized avatar

Tim Hudson timhudson

View GitHub Profile

Usage

$ mongoexport -d test -c activities | node event-convert-stream.js | mongoimport -d test -c events
#!/bin/bash
# from here: http://www.codingsteps.com/install-redis-2-6-on-amazon-ec2-linux-ami-or-centos/
# and here: https://raw.github.com/gist/257849/9f1e627e0b7dbe68882fa2b7bdb1b2b263522004/redis-server
###############################################
# To use:
# wget https://gist.github.com/thrashr888/6047603/raw/6584ab9c5d500613303c852d79d619690b835305/install-redis.sh
# chmod 777 install-redis.sh
# ./install-redis.sh
###############################################
echo "*****************************************"
app.set('port', process.env.PORT || 3000);
var host = process.env.HOST || 'localhost:'+app.get('port')
var port = process.env.PORT || 3000
, host = process.env.HOST || 'localhost:3000'
var one = 1
, two = 2
, three = 3
var one = 1,
two = 2,
three = 3;
var one = 1
var two = 2
/* Simple spam protection for email addresses using jQuery.
* Well, the protection isn’t jQuery-based, but you get the idea.
* This snippet allows you to slightly ‘obfuscate’ email addresses to make it harder for spambots to harvest them, while still offering a readable address to your visitors.
* E.g. Changed "at" to "atty" and "dot" to "dotty" to confuse some of the more intelligent harvesters.
* <a href="mailto:foo(atty)example(dotty)co(dotty)uk">foo aty example dotty co dotty uk</a>
* →
* <a href="mailto:[email protected]">[email protected]</a>
*/
$(function() {
var query = {$or: [
{_id: req.params.id, app: req.app.id},
{altId: req.params.id, app: req.app.id}
]}
Show.findOne(query, function(err, show) {
// send them the show
})
var Model = Backbone.SubCollectionModel.extend({
collectionAttribute: 'dogs',
collectionToJSON: function(collection) {
return collection.pluck('name')
}
})
var model = new Model({
name: 'example',
dogs: [
Watchlists.View = Backbone.Marionette.CompositeView.extend({
template: Backbone.Marionette.TemplateCache.get('#watchlists-view'),
itemView: Watchlists.TableItemView,
itemViewContainer: 'tbody',
events: {
'submit .add-form': 'addWatchlist'
},
@timhudson
timhudson / pre-save-update.js
Last active July 3, 2020 08:58
Update the `lastUpdated` field every time a mongoose model is saved
var schema = mongoose.Schema({
lastUpdated: {type: Date, 'default': Date.now}
})
schema.pre('save', function(next) {
this.lastUpdated = Date.now()
next()
})