Skip to content

Instantly share code, notes, and snippets.

@cianclarke
cianclarke / dontDoThis.js
Created October 25, 2012 22:40
Don't do this
// NO! NO! NO! DON'T EVER DO THIS EVER EVER AGAIN
// Now, remove everything except the zip we just made
exec("rm -rf `ls | grep -v 'p.zip$'`; rm -rf .git", {
cwd: repoPath
}, function(error, stdout, stdett){
// Don't care...
});
@cianclarke
cianclarke / bson.js
Created October 26, 2012 19:49
MongoDB Check for BSON _id based lookups
function _checkForBSONId(queryObject){
if (queryObject.hasOwnProperty('_id')){
// If we're keying on an autogenned one, MongoDB expects an objectId to look like: ObjectId( "505cfee6d94d451252000001" ) not just ""
if (queryObject._id.length === 24){
var BSON = require('mongodb').BSONPure;
queryObject._id = BSON.ObjectID.createFromHexString(queryObject._id);
}
}
return queryObject;
}
@cianclarke
cianclarke / gist:4148623
Created November 26, 2012 14:57
Date time tutorial cloud code
var util = require('util');
var request = require('request');
exports.getCurrentTime = function(params, callback) {
request({uri : 'http://www.timeanddate.com/worldclock/city.html?n=78'}, function(err, response, body){
return callback(null, {
'response' : body
});
});
}
@cianclarke
cianclarke / gist:5014135
Created February 22, 2013 15:19
Single letter variables fo lyfe yo
function(e, r){
var a = r.data.Forms;
for (var i=0; i< a.length; i++){
var b = a[i];
console.log(b.Hash);
}
}
@cianclarke
cianclarke / gist:5490768
Last active December 16, 2015 20:10
Hoisting example
currentLocation = 'waterford';
function whereAreYa(){
console.log('1: ' + currentLocation);
var currentLocation = 'Dublin';
console.log('2: ' +currentLocation);
}
whereAreYa();
console.log('3: ' + currentLocation);
@cianclarke
cianclarke / gist:5490830
Last active December 16, 2015 20:10
Count retains it's value
var counter = function(count){
console.log("Count is " + count);
return {
getNext: function(){
return ++count;
}
};
}
myCounter = counter(0);
@cianclarke
cianclarke / gist:5490859
Created April 30, 2013 18:33
Functions & the new keyword
function Car(){
this.wheels = 4;
}
var redCar = new Car();
console.log('1: ' + typeof redCar);
console.log('2: ' + redCar.wheels);
var otherCar = Car();
console.log('3: ' + typeof otherCar);
@cianclarke
cianclarke / gist:5490894
Created April 30, 2013 18:38
Prototypical Inheritance
function Person(){
}
var jos = new Person();
var molly = new Person();
Person.prototype.age = "28";
Person.prototype.printAge = function(){
console.log('Age is: ', this.age);
@cianclarke
cianclarke / gist:5491102
Created April 30, 2013 19:06
Functional Inheritance
var autoMobile = function(config) {
var that = {};
that.getName = function() {
return config.name;
};
that.getNumberOfWheels = function() {
return config.wheels;
};
return that;
}
@cianclarke
cianclarke / gist:5491130
Created April 30, 2013 19:11
this & methods
var name = 'Jose';
var myObject = {
name : "Molly",
getName: function() {
return this.name;
},
getWrongName: function() {
return name;
}
};