Skip to content

Instantly share code, notes, and snippets.

View stephenmelrose's full-sized avatar

Steve Melrose stephenmelrose

View GitHub Profile
@stephenmelrose
stephenmelrose / hogan_partials.js
Created July 14, 2012 18:45
Hogan and Partials
var hogan = require('hogan.js');
var partial = hogan.compile('{{#list}}{{foo}}{{/list}}');
var template = hogan.compile('{{> somelist}}');
var result = template.render(
{
list: [
{ foo: 'bar1' },
{ foo: 'bar2' },
@stephenmelrose
stephenmelrose / inheritance.js
Last active December 11, 2015 03:28
Prototypical inheritance
function MyObject() {}
MyObject.prototype.doSomething = function() {
console.log('MyObject.doSomething()');
}
// -----
var parent = MyObject;
@stephenmelrose
stephenmelrose / test.php
Created March 8, 2013 15:54
Comparing two objects that have internal date properties with DateTime objects assigned to them. Why does this work?!
<?php
class MyTest {
protected $date;
public function __construct($time) {
$this->date = new DateTime($time);
}
}
$test1 = new MyTest('2013-02-01 00:00:00');
@stephenmelrose
stephenmelrose / bootstrap.php
Last active December 14, 2015 17:09
MVP design/approach.
<?php
$repository = new Repository();
$data = new Data($repository);
$controller = new Controller($data);
$controller->executeAction($_GET['something']);
@stephenmelrose
stephenmelrose / spec.md
Created July 4, 2013 09:48
New laptop spec
  • Optimus Series: 15.6" Matte Full HD LED Widescreen (1920x1080)
  • Intel® Core™i7 Quad Core Mobile Processor i7-3630QM (2.40GHz) 6MB
  • 8GB SAMSUNG 1333MHz SODIMM DDR3 MEMORY (1 x 8GB)
  • NVIDIA® GeForce® GTX 660M - 2.0GB DDR5 Video RAM - DirectX® 11
  • 120GB KINGSTON HYPERX 3K SSD, SATA 6 Gb/s (upto 555MB/sR | 510MB/sW)
  • 250GB WD SCORPIO BLACK WD2500BEKT, SATA 3 Gb/s, 16MB CACHE (7200 rpm)
  • 8x SATA DVD±R/RW/Dual Layer (+ 24x CD-RW))
  • GIGABIT LAN & WIRELESS INTEL® ADVANCED-N 6235 (300Mbps) + BLUETOOTH
@stephenmelrose
stephenmelrose / example.js
Created September 17, 2013 20:48
Updating multiple elements in a Mongo document array
// Example document structure
{
"balance": {
"start": 0,
"end": 0
},
"transactions": [
{ "balance": 0 },
{ "balance": 0 },
{ "balance": 0 },
@stephenmelrose
stephenmelrose / error.js
Created October 14, 2013 14:52
Developer sense of humour
throw new Error(util.format(
'Invalid team location [%s]. Expected "home" or "away" (with you each day).',
teamLocation
));
@stephenmelrose
stephenmelrose / tests.php
Created January 29, 2014 21:31
Multiple test cases
<?php
public function testProcessTimePeriod_GetProcessingData()
{
// TransactionRepository::getProcessingDataByTimePeriodAndAccountId should return false
// TransactionRepository::getProcessingDataByTimePeriodAndAccountId should return an empty array
}
public function testProcessTimePeriod_SortTransactions()
@stephenmelrose
stephenmelrose / array_slice.php
Created February 5, 2014 13:15
array_slice() works on hash tables
<?php
$data = array(
'a' => 1,
'b' => 2,
'c' => 3,
'd' => 4,
'e' => 5
);
@stephenmelrose
stephenmelrose / Vagrantfile
Created July 18, 2014 10:26
Vagrant + Docker Order Problem
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Set default provider to docker
ENV['VAGRANT_DEFAULT_PROVIDER'] = 'docker'
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|