Skip to content

Instantly share code, notes, and snippets.

View JoshuaGross's full-sized avatar

Joshua Gross JoshuaGross

View GitHub Profile
@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
Last active April 9, 2022 04:10
Freeing up extra disk space inside a Docker container

Freeing up extra disk space inside a Docker container

Sometimes while running a command inside of a docker container, the container itself will run out of disk space and things can fail (sometimes in strange ways). This is not a guide on how to allocate resources, but a quick cookbook on how to free up disk space inside a container. See below for links to more resources and reading.

If at all possible, just run Docker with increased disk space

See Limit disk size and bandwidth of a Docker container.

Resize an aufs volume

@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 / pg-datediff.sql
Created September 30, 2016 22:11
PostGres custom DATEDIFF function (from http://www.sqlines.com/postgresql/how-to/datediff)
CREATE OR REPLACE FUNCTION DateDiff (units VARCHAR(30), start_t TIMESTAMP, end_t TIMESTAMP)
RETURNS INT AS $$
DECLARE
diff_interval INTERVAL;
diff INT = 0;
years_diff INT = 0;
BEGIN
IF units IN ('yy', 'yyyy', 'year', 'mm', 'm', 'month') THEN
years_diff = DATE_PART('year', end_t) - DATE_PART('year', start_t);
@JoshuaGross
JoshuaGross / pg-running-queries.sql
Created September 30, 2016 22:04
List running queries in PostGres
select * 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); });'