Skip to content

Instantly share code, notes, and snippets.

@danmactough
danmactough / Mongoose+Express test 02b
Created July 6, 2011 16:20
Modify the record (fails)
var mongoose = require('mongoose')
, Schema = mongoose.Schema
, crypto = require('crypto')
, sys = require('sys')
, User
;
function defineModels(mongoose, fn) {
var Schema = mongoose.Schema
, ObjectId = Schema.ObjectId
@danmactough
danmactough / Mongoose+Express test 01
Created July 6, 2011 16:15
Create a new User record
// Create the record we will test modify
var mongoose = require('mongoose')
, Schema = mongoose.Schema
, crypto = require('crypto')
, sys = require('sys')
, User
;
function defineModels(mongoose, fn) {
var Schema = mongoose.Schema
@danmactough
danmactough / Mongoose+Express test 02a
Created July 6, 2011 16:20
Modify the record (working)
var mongoose = require('mongoose')
, Schema = mongoose.Schema
, crypto = require('crypto')
, sys = require('sys')
, User
;
function defineModels(mongoose, fn) {
var Schema = mongoose.Schema
, ObjectId = Schema.ObjectId
@danmactough
danmactough / express-form-alt.js
Created July 20, 2011 14:36
Alternative to Connect - Multipart
/*!
* Alternative to Connect - Multipart
* Copyright(c) 2010, 2011 TJ Holowaychuk <tj@vision-media.ca>, Dan MacTough <danmactough@gmail.com>
* MIT Licensed
*/
/**
* Module dependencies.
*/
Model.post('init', function() {
if (!this.isNew) {
var my = this
, activePaths = Object.keys(this._activePaths.states.init);
Object.keys(my._doc).forEach(function(path){
if (activePaths.indexOf(path) === -1) {
delete(my._doc[path]);
}
});
this._doc = my._doc;
@danmactough
danmactough / index.js
Created September 26, 2011 00:54 — forked from aheckmann/index.js
var mongoose = require('mongoose');
mongoose.connect('localhost', 'testing_535');
console.error('mongoose version', mongoose.version);
var OID = mongoose.Types.ObjectId;
var ASchema = new mongoose.Schema({
square: mongoose.Schema.ObjectId
, task: Number
});
@danmactough
danmactough / includes.jade
Created September 28, 2011 20:08
Jade Issue #354
html
body
h1 My Site
p Welcome to my super lame site.
include template.jqtl
@danmactough
danmactough / gist:2041678
Created March 15, 2012 03:24
Bash one-liner to create JSON { shorturl: longurl } from a directory of Adjix redirects
grep "rel=\"canonical\"" * | awk '{ OFS = ""; ORS = ","; file = substr($1, 0, 4); href = match($0, /http:\/\/[^\"]+/); print "\"", file, "\": \"", substr($0, RSTART, RLENGTH), "\""}' | awk '{ OFS = ""; ORS = ""; len = length($0); print "{", substr($0, 1, len - 1), "}" }'
var mongoose = require('mongoose')
, Schema = mongoose.Schema
, ObjectId = Schema.ObjectId
;
mongoose.connect('mongodb://localhost/test_update_getters_setters_defaults');
var Fooschema = new Schema ({
name : { type: String, default: 'foo', required: true }
, date : Date
Installed Packages
ConsoleKit.i686 0.4.2-3.fc14 @updates
ConsoleKit-libs.i686 0.4.2-3.fc14 @updates
ConsoleKit-x11.i686 0.4.2-3.fc14 @updates
GConf2.i686 2.31.91-1.fc14 @fedora
GConf2-gtk.i686 2.31.91-1.fc14 @fedora
ImageMagick.i686 6.6.4.1-16.fc14 installed
ModemManager.i686 0.4.998-1.git20110706.fc14 installed
ORBit2.i686 2.14.19-1.fc14 @fedora
SDL.i686 1.2.14-11.fc14 @updates