Skip to content

Instantly share code, notes, and snippets.

View billiegoose's full-sized avatar

Billie Hilton billiegoose

View GitHub Profile
@billiegoose
billiegoose / README.md
Created May 6, 2016 21:46
Mocha users need to watch out for this surprising behavior

Mocha does not reload modules when running multiple tests. This can lead to some curious errors that are difficult to understand at first, but have to do with modules that have an internal state of their own. If you have a folder with two files, test1.js and test2.js (shown in gist below), you will find you get different test results even though they are identical except in name. The first one fails, but the second succeeds.

So some state from previous tests can "pollute" later tests. This makes it difficult to write unit tests in isolation with Mocha, because suddenly when you put both tests together in the same directoy, mocha's behavior can break the tests.

@billiegoose
billiegoose / random_thoughts.txt
Last active February 25, 2016 20:32
Thoughts on a Universal Data schema
// TODO: Clean up thoughts into a nice document.
// Thoughts on Universal Data language / description
// See: https://martin.kleppmann.com/2012/12/05/schema-evolution-in-avro-protocol-buffers-thrift.html#comment-2534873305
/* Preface:
Why do Thrift, Protobuf, and Avro each define their own IDL?
I would think that there could be an implementation-independent "master" IDL
to standardize the syntax (the semantics depends on the feature set of the implementation).
It makes it hard to try out these different libraries when they require rewriting
the message schema each time.
@billiegoose
billiegoose / data-over-http.md
Last active August 22, 2017 03:28
Embedding data in HTTP messages - an exhaustive analysis

Embedding data in HTTP messages - an exhaustive analysis

Hypertext Transport Protocol (HTTP) is the de facto protocol for sending data over the Internet. Today in addition to transporting hypertext documents, it is used to transport images, stylesheets, JavaScript, fonts - nearly everything in a web page. Rarely do developers pause to question why this is. Lately, I've been thinking a lot about HTTP and its relation to APIs and web apps. This document contains my thoughts on the usefulness of HTTP requests as envelopes for sending data.

HTTP requests consist of at least 7 pieces: the path, the query string, the method, the status, the headers, the body, and cookies. (Technically cookies are a subcategory of headers but they have additional behaviors that make them worth examining separately.) This article examines each of them from the perspective of their utility for carrying arbitrary data. Note: This article only looks at HTTP/1.

Least general

REST APIs often make use of HTTP methods and respo

@billiegoose
billiegoose / util.bash
Created January 14, 2016 23:01
A huge collection of Bash utility functions. Could come in handy!
#!/bin/bash -e
# Author: gdbtek (Nam Nguyen)
# Repo: https://github.com/gdbtek/ubuntu-cookbooks
# License: MIT
###################
# ARRAY UTILITIES #
###################
function arrayToString()
@billiegoose
billiegoose / mergelog.py
Created December 9, 2015 17:00 — forked from seanh/mergelog.py
A custom merge driver for git, for automatically merging my 'log.txt' file in a simplistic way.
#!/bin/env python
"""mergelog
This is a custom merge driver for git. It should be called from git
with a stanza in .git.config like this:
[merge "mergelog"]
name = A custom merge driver for my log.txt file.
driver = ~/scripts/mergelog %O %A %B %L
recursive = binary
@billiegoose
billiegoose / upsert.sql
Created November 9, 2015 16:45 — forked from KyleGobel/upsert.sql
Insert/Update Upsert Trigger in Postgres
CREATE OR REPLACE FUNCTION upsert_user()
RETURNS trigger AS
$upsert_user$
declare
existing record;
begin
if (select EXISTS(select 1 from users where user_id = NEW.user_id)) then
select user_name, user_class, user_age into strict existing from users where user_id = new.user_id;
/* Straight stolen from http://bl.ocks.org/dwtkns/4686432 */
window.worlddata = {"type":"Topology","transform":{"scale":[0.03600360036003601,0.017366249624962495],"translate":[-180,-90]},"objects":{"land":{"type":"MultiPolygon","arcs":[[[0]],[[1]],[[2]],[[3]],[[4]],[[5]],[[6]],[[7,8]],[[9,10]],[[11]],[[12]],[[13]],[[14]],[[15]],[[16]],[[17]],[[18]],[[19]],[[20]],[[21]],[[22]],[[23]],[[24]],[[25]],[[26]],[[27]],[[28,29]],[[30]],[[31]],[[32]],[[33]],[[34]],[[35]],[[36]],[[37]],[[38]],[[39]],[[40]],[[41,42]],[[43]],[[44]],[[45]],[[46,47,48,49]],[[50]],[[51]],[[52]],[[53]],[[54]],[[55]],[[56]],[[57]],[[58]],[[59]],[[60]],[[61,62]],[[63]],[[64]],[[65]],[[66]],[[67]],[[68]],[[69]],[[70]],[[71]],[[72]],[[73]],[[74]],[[75,76]],[[77]],[[78]],[[79]],[[80]],[[81]],[[82]],[[83]],[[84]],[[85]],[[86]],[[87]],[[88]],[[89,90]],[[91]],[[92]],[[93]],[[94]],[[95]],[[96]],[[97]],[[98]],[[99]],[[100]],[[101]],[[102]],[[103]],[[104]],[[105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,
@billiegoose
billiegoose / vanilla-cookies.js
Created January 24, 2015 02:23
Vanilla Cookies - a dead simple yet full-featured JavaScript cookie library
// Vanilla Cookies - a dead simple yet full-featured JavaScript cookie library
// derived from http://stackoverflow.com/a/19189846
/*********************************************************
Gets the value of a cookie.
**********************************************************/
getCookie = function(sName)
{
var oCrumbles = document.cookie.split(';');
for(var i=0; i<oCrumbles.length;i++)
@billiegoose
billiegoose / Express Parameter Parsing Demo.md
Last active August 29, 2015 14:09
Simple Express Parameter Parsing Demo

Simple Express Parameter Parsing Demo

  1. git clone https://gist.github.com/a5656b01c35d6f25dda7.git demo
  2. cd demo
  3. npm install
  4. npm start

Look at the purty code. See how the magic be done.

@billiegoose
billiegoose / git-log-alias.sh
Created May 21, 2014 15:45
git lg: the best git log alias
#!/bin/bash
git config --global --unset alias.lg; git config --global alias.lg "log --graph --abbrev-commit --decorate --date=relative -10 --format=format:'%C(bold blue)%h%C(reset) %C(bold yellow)%d%C(reset) %C(white)%s%C(reset) %C(green)(%ar)%C(reset) %C(dim white)- %an%C(reset)'"