Skip to content

Instantly share code, notes, and snippets.

@th3james
th3james / gist:8826662
Last active August 29, 2015 13:56
A basic Mocha Unit test
suite("Metric");
test(".getDataLabels returns all data epochs as human readable dates", function() {
var labels, metric;
metric = new Metric({
data: [
{ date: 1388793600 },
{ date: 1391472000 }
]
});
@th3james
th3james / gist:8825392
Last active August 29, 2015 13:56
Mocha Client Testing setup
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="/js/test_libs/css/mocha.css">
<title>Client Tests</title>
</head>
@th3james
th3james / post_controller
Last active December 11, 2015 01:39
Backbone Diorama Example prototype
class Backbone.Controllers.PostsController extends Backbone.Diorama.Controller
constructor: ->
@mainRegion = new Backbone.Diorama.ManagedRegion()
$('body').append(@mainRegion.$el)
# Start state
@index()
index: =>
postCollection = new Backbone.Collection.PostCollection()
@th3james
th3james / gist:2952921
Created June 19, 2012 08:08
vim_rc 06/12
" Somewhat copied from https://github.com/spf13/spf13-vim/blob/master/.vimrc
set nocompatible " We're running Vim, not Vi!
call pathogen#runtime_append_all_bundles() " add pathogen
" UI stuff
syntax on " Enable syntax highlighting
set background=dark " Assume a dark background
color ir_black
set backspace=indent,eol,start " backspace for dummys
@th3james
th3james / gist:2558102
Created April 30, 2012 12:57
Postgres != slowness
# Crazy Slow
UPDATE protected_areas SET criteria = 'Not Applicable' WHERE designation_id != 5;
# Near instant
UPDATE protected_areas SET criteria = 'Not Applicable'
FROM protected_areas AS pa
LEFT OUTER JOIN designations ON pa.designation_id = designations.id
WHERE designations.id = 5 AND pa.designation_id = NULL;
typeof(some_var) // returns 'undefined'
//Therefore, the correct way in javascript to check if a variable has a value is:
typeof some_var === 'undefined'
undefined = "don't ever do this";
if (some_var === undefined)
var some_var;
some_var === null; // false
some_var == null; // true
some_var; // undefined
// from
if (some_var == null
// to
if (some_var === null)