Skip to content

Instantly share code, notes, and snippets.

@rmg
rmg / 00-NOTES.md
Last active June 19, 2018 18:22
node-tar corner case

These are hexdumps of the tarball added in isaacs/node-tar#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 April 18, 2018 01:00
Alpine Linux Package Utils
# 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 September 17, 2017 02:00
Promises to async/await
// 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 January 31, 2017 03:52
Bowling Game Kata in JavaScript

Bowling Game Kata in JavaScript

git clone [email protected]:35d39ab94e659bff436fca096f2c5e37.git bowling
cd bowling
npm install
npm test
@rmg
rmg / README.md
Last active July 6, 2016 02:10
JS bind operator

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 June 29, 2016 18:31
Wrapper for net.connect to test if a host can be connected to on a given tcp port
'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 01:08
Create a private buffer on an http response
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 February 10, 2016 15:55
mktmpio examples
# 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 February 5, 2016 18:43
Zombie Screen
#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
@rmg
rmg / keybase.md
Created July 29, 2015 17:53
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: