Skip to content

Instantly share code, notes, and snippets.


Ryan Graham rmg

View GitHub Profile
rmg /
Last active Jun 19, 2018
node-tar corner case

These are hexdumps of the tarball added in

  • gnu-tar from gtar -cf ...
  • gnu-posix-tar from gtar --posix -cf ...
  • bsd-tar from bsdtar -cf ...

edit: I've added additional line breaks at the 512 byte boundaries to make it easier to see the tar framing.

rmg / find.awk
Created Apr 18, 2018
Alpine Linux Package Utils
View find.awk
# Print tab-separated details for the given file based on the package that owns it
# Usage:
# awk -v file=/path/to/some/file -f find.awk /lib/apk/db/installed
# multi-line records, go!
# our input fields are lines, but our output is tab-delimited
rmg / users.js
Created Sep 17, 2017
Promises to async/await
View users.js
// original Promise-only version. I try to write my functions to be pure
// when appropriate so that they are composable in to promise chains like
// this
function findOrCreateUser(id /* :string */, user /* :User */) /* :Promise<User> */ {
return db.users
.hsetnx(id, 'created_at', user.created_at.toJSON())
.then(function(isNew) {
if (isNew) {{user: user}, 'New user');
return db.users.hmset(id, serializeUser(user))
rmg /
Last active Jan 31, 2017
Bowling Game Kata in JavaScript

Bowling Game Kata in JavaScript

git clone bowling
cd bowling
npm install
npm test
rmg /
Last active Jul 6, 2016
JS bind operator


A simple shorthand for, ...) to make it nicer to work with partial function application.

// shorthand
function sillyClone(input) {
  var acc = [];
  return acc;
rmg / test-connect.js
Created Jun 29, 2016
Wrapper for net.connect to test if a host can be connected to on a given tcp port
View test-connect.js
'use strict';
var fmt = require('util').format;
var net = require('net');
module.exports = testConnection;
if (require.main !== module) {
rmg / http-client.js
Created May 22, 2016
Create a private buffer on an http response
View http-client.js
const https = require('https');
const bufSym = Symbol();
https.get('', onResponse);
function onResponse(res) {
// monkey patch using our Symbol as a key
res[bufSym] = '';
// event emitters invoke handlers using emitter as 'this'
res.on('data', accumulate);
rmg / ruby.rb
Created Feb 10, 2016
mktmpio examples
View ruby.rb
# Inspiring DSL for temp directories
Dir.mktmpdir {|dir|
# use the directory...
open("#{dir}/foo", "w") { ... }
# Provide the same ergonomics for databases
mktmpio(:postgres) {|db|
pg.connect(db) {|conn|
# use the database...
rmg / shotgun.c
Last active Feb 5, 2016
Zombie Screen
View shotgun.c
#include <errno.h>
#include <unistd.h>
#include <sys/wait.h>
#include <signal.h>
#if 0
#include <stdio.h>
#define print1 printf
#define print2 printf

Keybase proof

I hereby claim:

  • I am rmg on github.
  • I am rmg ( on keybase.
  • I have a public key whose fingerprint is 3DDA 2C71 32C7 89E3 5849 7086 1CCC AB43 A1FA 2211

To claim this, I am signing this object: