Skip to content

Instantly share code, notes, and snippets.

View rumkin's full-sized avatar
🧠
Getting deeper

Paul Rumkin rumkin

🧠
Getting deeper
View GitHub Profile
@rumkin
rumkin / ssh-proxy.sh
Created September 25, 2014 10:00
Node debug proxy for vagrant
vagrant ssh -- -L 5858:127.0.0.1:5858 -N
@rumkin
rumkin / btrfs-partition-with-file.sh
Last active August 29, 2015 14:16
Create btrfs partition from file
# Partition file
FILE=/tmp/drive
# Mount directory
MOUNT=/mnt/drive
# Allocate 10Gb empty file
fallocate -l 10G $FILE
# Mount file to loop back device
losetup /dev/loop0
# Create btrfs _without RAID_
@rumkin
rumkin / inspectorrc
Created September 25, 2015 16:33
node-inspector priest configuration
{
"web-port": 8000,
"hidden": ["node_modules/", "tests/", "/node_modules/"],
"preload": true
}
@rumkin
rumkin / curve25519.js
Created November 17, 2015 09:21
VanillaJS Curve25519 implementation
// Snarfed from http://savannah.gnu.org/task/?6432
// Ostensibly Copyright (c) 2007 Michele Bini, GPL
var c255lbase32chars = "abcdefghijklmnopqrstuvwxyz234567";
var c255lbase32values = {"a":0, "b":1, "c":2, "d":3, "e":4, "f":5, "g":6, "h":7, "i":8, "j":9, "k":10, "l":11, "m":12, "n":13, "o":14, "p":15, "q":16, "r":17, "s":18, "t":19, "u":20, "v":21, "w":22, "x":23, "y":24, "z":25, "2":26, "3":27, "4":28, "5":29, "6":30, "7":31 };
function c255lbase32encode(n, x) {
var c;
var r = "";
for (c = 0; c < 255; c+=5) {
r = c255lbase32chars.substr(c255lgetbit(n, c) + c255lgetbit(n, c+1)*2 + c255lgetbit(n, c+2)*4 + c255lgetbit(n, c+3)*8 + c255lgetbit(n, c+4)*16, 1) + r;
@rumkin
rumkin / moop.js
Last active January 16, 2016 09:08
// Extend class
function extend (proto) {
var Super = this;
var ctor;
if (proto.hasOwnProperty('constructor')) {
ctor = proto.constructor;
} else {
ctor = function () {
Super.apply(this, arguments);
;(function(){
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* SHA-256 implementation in JavaScript (c) Chris Veness 2002-2014 / MIT Licence */
/* */
/* - see http://csrc.nist.gov/groups/ST/toolkit/secure_hashing.html */
/* http://csrc.nist.gov/groups/ST/toolkit/examples.html */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* jshint node:true *//* global define, escape, unescape */
'use strict';
@rumkin
rumkin / result.txt
Last active June 21, 2016 12:23
Monomorphic vs megamorphic vs typed modes benchmark
Monomorphic x 1,989 ops/sec ±1.90% (71 runs sampled)
Megamorphic x 47.27 ops/sec ±1.03% (58 runs sampled)
Typed x 2,550 ops/sec ±2.10% (57 runs sampled)
@rumkin
rumkin / maps-vs-objects.bench.js
Created June 21, 2016 12:13
Compare objects with variadic property set versus Map
const Benchmark = require('benchmark');
const suite = new Benchmark.Suite;
// Test data set size
const n = process.env.SET_SIZE || 100000;
// Megamorphic objects array
const objects = Array(n);
// Array of map instances
const maps = Array(n);
@rumkin
rumkin / pretty-json.js
Created July 5, 2016 16:19
Prettify json passed to stdio and output to stdout
#!/usr/bin/env node
// Stdin JSON prettifier
// Partially based on https://gist.github.com/kristopherjohnson/5065599
const {inspect} = require('util');
const {stdin, stdout} = process;
var input = '';
@rumkin
rumkin / middleware.js
Created August 8, 2016 11:56
Koa boilerplate code
import Router from 'koa-router';
export function moduleMiddleware(options = {}) {
const router = new Router();
router.get('/', async (ctx, next) => {
// ... do some job
});
return router;