Skip to content

Instantly share code, notes, and snippets.

View kristopherjohnson's full-sized avatar
💭
Huh?

Kristopher Johnson kristopherjohnson

💭
Huh?
View GitHub Profile
@kristopherjohnson
kristopherjohnson / nodejs_snippets.js
Last active March 1, 2022 16:06
Random node.js code snippets
console.log('Hello, world!')
// Common modules
var util = require('util');
var events = require('events');
var http = require('http');
var url = require('url');
var fs = require('fs');
var zlib = require('zlib');
@kristopherjohnson
kristopherjohnson / skeleton_index.jade
Created November 28, 2012 21:11
The Skeleton boilerplate index.html, translated into a Jade template
!!! 5
//if lt IE 7
<html class="ie ie6" lang="en">
//if IE 7
<html class="ie ie7" lang="en">
//if IE 8
<html class="ie ie8" lang="en">
//if (gte IE 9)|!(IE)
<!--><html lang="en"> <!--
@kristopherjohnson
kristopherjohnson / openlayers_ch1.jade
Created December 7, 2012 20:03
OpenLayers example from chapter 1 of "OpenLayers 2.10" by Eric Hazard, translated to Jade
doctype 5
html
head
title My OpenLayers Map
script(src='OpenLayers.js')
script
function init() {
map = new OpenLayers.Map('map_element', {});
var wms = new OpenLayers.Layer.WMS(
'OpenLayers.WMS',
@kristopherjohnson
kristopherjohnson / make_test.sublime-build
Created December 9, 2012 12:58
Sublime Text 2 build system for running "make test"
{
"cmd": ["make", "test"],
"working_dir": "${project_path}",
"path": "/usr/bin:/bin:/usr/local/bin:/usr/local/share/npm/bin"
}
@kristopherjohnson
kristopherjohnson / make_test_mocha.sublime-build
Created December 9, 2012 13:29
Sublime Text 2 build system that runs "make test" with Mocha.js
{
"cmd": ["make", "test"],
"working_dir": "${project_path}",
"path": "/usr/bin:/bin:/usr/local/bin:/usr/local/share/npm/bin",
"file_regex": "\\((...*?):([0-9]*):([0-9]*)\\)"
}
/* jQuery Tiny Pub/Sub - v0.7 - 10/27/2011
* http://benalman.com/
* Copyright (c) 2011 "Cowboy" Ben Alman; Licensed MIT, GPL */
(function($) {
var o = $({});
$.subscribe = function() {
o.on.apply(o, arguments);
@kristopherjohnson
kristopherjohnson / stringFromSeconds.js
Last active December 10, 2015 08:28
Given a number of seconds, create a string of the form "Nd NN:NN:NN" (e.g., "5d 17:13:46")
// Given numeric value, convert to string with enough leading zeros
// to make it two characters long
var zeroPad2 = function (val) {
result = val.toString();
while (result.length < 2) {
result = "0" + result;
}
return result;
};
@kristopherjohnson
kristopherjohnson / continuousMakeTest.sh
Last active December 10, 2015 18:58
Automatically clear screen and run "make test" every few seconds
#!/bin/sh
# Every 5 seconds, clear screen and run 'make test'
while true; do
clear
make test
sleep 5
done
@kristopherjohnson
kristopherjohnson / mocha_chai.html
Last active December 10, 2015 18:58
Example of Mocha-based browser unit tests for a Node/Express application, using the Chai assertion library
<html>
<head>
<meta charset="utf-8">
<title>My Browser Tests</title>
<link rel="stylesheet" href="../../node_modules/mocha/mocha.css" />
</head>
<body>
<!-- Div used by mocha to report results -->
<div id="mocha"></div>
@kristopherjohnson
kristopherjohnson / Default (OSX).sublime-keymap
Last active December 11, 2015 03:58
My Sublime Text user settings
[
{ "keys": ["super+alt+ctrl+up"], "command": "select_lines", "args": {"forward": false} },
{ "keys": ["super+alt+ctrl+down"], "command": "select_lines", "args": {"forward": true} },
]