Skip to content

Instantly share code, notes, and snippets.

@cianclarke
cianclarke / gist:5491158
Created April 30, 2013 19:15
this & Functions
var getName = function() {
console.log("Name is: " + this.name);
};
console.log(getName()); // Undefined
var jos = { name : 'Jos' };
jos.getName = getName;
console.log(jos.getName()); // Name is Jos
@cianclarke
cianclarke / gist:5491180
Created April 30, 2013 19:17
this & that
var jos = { name : 'Jos' };
jos.getFullName = function(surname) {
var that = this;
var printName = function(surname){
console.log("Full name", this.name + ' ' + this.surname);
console.log("Full name", that.name + ' ' + surname);
}
printName('Parker');
}
jos.getFullName();
@cianclarke
cianclarke / gist:5491192
Created April 30, 2013 19:19
this & Constructors
var Car = function(colour) {
this.colour = colour;
};
var redCar = new Car("Red");
var yellowCar = new Car("Yellow");
Car.prototype.getColour = function(){
return this.colour;
};
console.log(redCar.getColour());
@cianclarke
cianclarke / gist:5825581
Created June 20, 2013 18:58
Obligatory Unicorn
/*
________
.##@@&&&@@##.
,##@&::%&&%%::&@##.
#@&:%%000000000%%:&@#
#@&:%00' '00%:&@#
#@&:%0' '0%:&@#
. . . . #@&:%0 0%:&@#
,`,`,`,`, #@&:%0 0%:&@#
. . . . `\`\`\`\; #@&:%0 0%:&@#
@cianclarke
cianclarke / gist:6495568
Created September 9, 2013 13:27
Socket.io - replace application.js with this
var fs = require('fs');
var util = require('util');
var http = require('http');
// index.html
var html = [
'<html><head><script src="/socket.io/socket.io.js"></script>',
'<script>',
'var socket = io.connect(document.location.href);',
#header {
display : none;
}
form li.focused {
background : none;
}
@cianclarke
cianclarke / gist:7661485
Created November 26, 2013 16:32
Compact bootstrap tabs - just add compact to nav nav-tabs
.nav-tabs.compact > li > a {
font-size: 0.9em;
padding: 4px 5px;
margin-right: 4px;
line-height: 16px;
}
@cianclarke
cianclarke / geo.js
Last active December 31, 2015 16:29
Geo Service
var http = require('http');
exports.latlong = function(params, cb) {
var url,
address = params.address,
data = '';
url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' +
address + '&sensor=false';
@cianclarke
cianclarke / gist:8060431
Created December 20, 2013 19:56
Let It Snow
var letItSnow = function(){
return setInterval(function(){
var snow = document.createElement('div');
snow.innerHTML = '*';
snow.style.cssText = 'position:absolute; color: #ddd; font-size: 22px; top: ' + Math.random()*window.innerHeight + 'px; right: ' + Math.random()*window.innerWidth + 'px';
document.body.appendChild(snow)
}, 100);
}
@cianclarke
cianclarke / application.js
Last active August 29, 2015 14:00
iBeacons cloud code for returning beacon descriptions from databrowser
var mbaas = require('fh-mbaas-express');
var express = require('express');
// Securable endpoints: list the endpoints which you want to make securable here
var securableEndpoints = ['hello'];
var app = express();
// Note: the order which we add middleware to Express here is important!
app.use('/sys', mbaas.sys(securableEndpoints));