Skip to content

Instantly share code, notes, and snippets.

View JoshuaGross's full-sized avatar

Joshua Gross JoshuaGross

View GitHub Profile
@JoshuaGross
JoshuaGross / bst.js
Created April 27, 2017 06:36
JavaScript binary search tree + tests
/**
* Copyright 2017, Joshua Gross, All Rights Reserved.
* Released under the MIT license.
*/
/**
* Each BST is represented as its own root.
* BSTs have no rebalancing, so tree shape can get gnarly real quick!
*/
function BST (key, value, left, right) {
@JoshuaGross
JoshuaGross / docker-line.md
Last active April 19, 2017 20:07
Install and configure DogStatsD to run container-local

Installing

Add this line to a Dockerfile to install and configure DogStatsD in the container. Requires that apt-get is available on the system.

This script will install curl in your environment but not remove it; you should uninstall it if you don't want it available in the container.

These script uses md5sum to validate all external scripts that are

@JoshuaGross
JoshuaGross / FIX.md
Created November 28, 2016 07:20
OS X El Capitan, "Reason: image not found" - Python library loading error resolution

Python "image not found" error resolution

This is an error that seems to occur on OS X El Capitan. You may see errors like this that did not occur before:

$ ./my_python_script.py
Traceback (most recent call last):
  File "./my_python_script.py", line 17, in <module>
    import psycopg2
 File "/Users/joshuagross/miniconda2/envs/my_env/lib/python2.7/site-packages/psycopg2/__init__.py", line 50, in 
@JoshuaGross
JoshuaGross / keybase.md
Created November 20, 2016 22:47
Keybase identity verification

Keybase proof

I hereby claim:

  • I am joshuagross on github.
  • I am joshuagross (https://keybase.io/joshuagross) on keybase.
  • I have a public key whose fingerprint is DC5B 28F6 29F9 D09B BFB9 7FC3 ABF0 5BA3 4B8D 6DFD

To claim this, I am signing this object:

@JoshuaGross
JoshuaGross / README.md
Created November 17, 2016 23:31
Having trouble with networking in a Docker container?

Recently I've experienced strange issues with networking inside of Docker containers - like being unable to ping google.com from inside a container, and all of the common suggestions around DNS resolution not helping.

It turns out that Docker will copy your computer's default DNS settings into a container. If you change your DNS settings at some point - either manually or because your machine accepts defaults from your router/provider - the settings inside your cached Docker layers may no longer match what's on your machine, and certain DNS resolutions will fail in unusual ways.

My fix: docker run -it {image} /bin/bash manually (for example, docker run -it python:2.7 bash) to find the root image that is unable to resolve the domain you're interested in, and then remove the culprit with docker rmi {hash}.

@JoshuaGross
JoshuaGross / pg-running-queries-age.sql
Created September 30, 2016 22:12
PG running queries with age in seconds
# Requires pg-datediff: https://gist.github.com/JoshuaGross/18b9bb1db8021efc88884cbd8dc8fddb
select datid, query, DateDiff('second', query_start::timestamp, NOW()::timestamp) from pg_stat_activity;
@JoshuaGross
JoshuaGross / buffer-to-shell.md
Created September 27, 2016 17:07
Translate Node Buffer into shell-friendly binary echo
console.log('echo -e "' + buf.reduce((s, x) => s + '\\x' + x, '') + '"');

Shell:

echo -e "\x85\x0\x2\x68\x0\x32\x194\x41\x247\x13\x33\x183\x212\x148\x92\x165\x68\x193\x4\x214\x164\x10\x90\x65\x80\x193\x114\x14\x255\x164\x18\x165\x77\x65\x0\x0\x9\x0\x50\x55"
@JoshuaGross
JoshuaGross / sdiff_empty.c
Last active September 22, 2016 21:56 — forked from fnoble/sdiff_empty.c
single diff measurement question (intersection of two structs via prns)
// Compiles with gcc -O0 sdiff_empty.c
// After running your sdiff function once, it will run
// a second time on canned data and compare your results with
// known outputs.
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <stdio.h>
#include <inttypes.h>
@JoshuaGross
JoshuaGross / typeclass.hs
Created May 14, 2016 04:26
Haskell - important typeclasses and cotypeclasses
-- none of this is terribly interesting, mostly here for reference
class Functor (f :: * -> *) where
fmap :: (a -> b) -> f a -> f b
(<$) :: a -> f b -> f a
-- The same as Functor!
-- http://stackoverflow.com/questions/34732571/why-there-is-no-cofunctor-typeclass-in-haskell/34732721
class Cofunctor (f :: * -> *) where
fmap :: (b -> a) -> f b -> f a
@JoshuaGross
JoshuaGross / node-cli-json.sh
Created April 6, 2016 23:03
Process JSON on the command-line with Node
echo "{ \"param\": 234 }" | node -e 'var input = ""; process.stdin.on("data", function (d) { input += d.toString(); }); process.stdin.on("close", function () { console.log(JSON.parse(input).param); });'