Skip to content

Instantly share code, notes, and snippets.

View mikefrey's full-sized avatar

Mike Frey mikefrey

View GitHub Profile
@mikefrey
mikefrey / superdeepmodel.js
Created July 9, 2012 15:16
Backbone.js SuperDeepModel
(function() {
function hOPExtend(obj) {
var args = Array.prototype.slice.call(arguments, 1)
for (var i = 0; i < args.length; i++) {
source = args[i]
for (var prop in source) if (source.hasOwnProperty(prop)) {
obj[prop] = source[prop];
}
}
@mikefrey
mikefrey / testcase.js
Last active December 15, 2015 12:19
New Relic node module swallows on uncaught exceptions. Tested on node.js v0.8.22.
var newrelic = require('newrelic')
var http = require('http')
function handleRequest(req, res) {
console.log('Handling request')
// Swallows the exception on the next line.
// Should throw a runtime error instead since DiesHere is undefined.
var x = DiesHere
res.end()
}
@mikefrey
mikefrey / func-stringify.js
Created July 18, 2013 19:13
JSON-Stringifying functions on objects
var obj = { fn:function() { return 'Wooo!' } }
JSON.stringify(obj) // '{}'
obj.fn.toJSON = function() { return this() }
JSON.stringify(obj) // '{"fn":"Wooo!"}'
@mikefrey
mikefrey / task-runner-test.js
Created May 17, 2014 17:14
Task Runner Test
describe('TaskRunner', function () {
var scope
var TR
var $q
var success
var error
function MockTasks() {
this.tasks = []
this.dfds = []
@mikefrey
mikefrey / attempt1.js
Created January 30, 2015 21:48
Elevator Saga
{
init: function(elevators, floors) {
var pickup = {up:[], down:[]}
var topFloor = floors.length - 1
var bottomFloor = 0
console.log(floors[0])
// setup floors
floors.forEach(function(floor, i) {
pickup.up[i] = false
pickup.down[i] = false
@mikefrey
mikefrey / lego_keycap.jscad
Last active January 23, 2017 00:09
Lego Cherry MX Keycap
// dimensions Cherry MX connector
var c_corr = 0.4 // tolerance
var c_horiz = 1.1 // horizontal bar width
var c_vert = 1.0 // vertical bar width
var c_dia = 4 // cross width
var c_depth = 7 // connector depth
var c_space = 7 // height of hollow inside
var c_inset = 0.75 // distance connector start to keycap base
// stuff
@mikefrey
mikefrey / route-loader.js
Created March 11, 2016 21:44
Route Loader plugin for hapi.js
/*
Loads and registers routes automatically.
USAGE
{
register: require('../app/plugins/route-loader'),
options: {
pattern: 'app/routes/*.js'
}
@mikefrey
mikefrey / config.js
Created July 20, 2016 14:53
Angular S3 browser upload with hapi
{
plugin: {
register: './app/plugins/s3-upload-token',
options: {
accessKey: 'YOURACCESSKEY',
secretKey: 'YOURSECRETKEY',
photoBucket: 'YOURBUCKET',
s3Policy: {
expiration: 10 * 60 * 1000, // 10 min
conditions: [
@mikefrey
mikefrey / data.json
Last active July 21, 2016 21:38
framed Example
{
"nodes": [
{ "id": 1, "x": 40, "y": 40 },
{ "id": 2, "x": 80, "y": 40 },
{ "id": 3, "x": 120, "y": 40 },
{ "id": 4, "x": 160, "y": 40 },
{ "id": 5, "x": 200, "y": 40 },
{ "id": 6, "x": 240, "y": 40 },
{ "id": 7, "x": 280, "y": 40 },
{ "id": 8, "x": 320, "y": 40 },
@mikefrey
mikefrey / generate.go
Created May 3, 2017 00:10
Generate a `map[string]string` from sql files using `go generate`
// +build ignore
package main
import (
"io/ioutil"
"log"
"os"
"path/filepath"
"strconv"