Skip to content

Instantly share code, notes, and snippets.

Avatar

Ryan Graham rmg

View GitHub Profile
@rmg
rmg / 00-NOTES.md
Last active Jun 19, 2018
node-tar corner case
View 00-NOTES.md

These are hexdumps of the tarball added in https://github.com/npm/node-tar/pull/187

  • 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
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
BEGIN {
# multi-line records, go!
RS=""
# our input fields are lines, but our output is tab-delimited
OFS="\t"
@rmg
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) {
logger.info({user: user}, 'New user');
return db.users.hmset(id, serializeUser(user))
@rmg
rmg / README.md
Last active Jan 31, 2017
Bowling Game Kata in JavaScript
View README.md

Bowling Game Kata in JavaScript

git clone git@gist.github.com:35d39ab94e659bff436fca096f2c5e37.git bowling
cd bowling
npm install
npm test
@rmg
rmg / README.md
Last active Jul 6, 2016
JS bind operator
View README.md

Idea:

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

// shorthand
function sillyClone(input) {
  var acc = [];
  input.forEach(acc.push&());
  return acc;
@rmg
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) {
return;
}
@rmg
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('https://nodejs.org/dist/index.json', 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
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
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
#else
View keybase.md

Keybase proof

I hereby claim:

  • I am rmg on github.
  • I am rmg (https://keybase.io/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:

You can’t perform that action at this time.