Skip to content

Instantly share code, notes, and snippets.

View IronSavior's full-sized avatar

Erik Elmore IronSavior

View GitHub Profile
@IronSavior
IronSavior / simple-demux-stream.js
Created September 12, 2017 00:40
Simple stream demuxer
const {Readable, Writable} = require('stream');
const PRIVATE = Symbol('private state accessor');
// Writable stream that routes each chunk through one of its output streams as determined by a user-supplied fdunction.
//
// An output stream is dynamically created whenver the channel selector function returns a new channel ID. The channel
// IDs may be any value which can function as a Map's key. Listeners to the "channel" event will receive a new Readable
// channel output stream when a new channel is created.
//
// Please note that this stream respects backpressure signaled by its outputs. This means that the overall throughput
@IronSavior
IronSavior / cgow_coroutine.py
Created January 4, 2018 01:02
Conway's Game of Life via Python Coroutines / Generators
# Conway's Game of Life via Python coroutines
# Inspired by https://effectivepython.com/2015/03/10/consider-coroutines-to-run-many-functions-concurrently/
from enum import Enum
from collections import namedtuple
from itertools import islice, count, product, chain, repeat, accumulate, starmap
from functools import partial, lru_cache
from time import sleep
import operator as op
@IronSavior
IronSavior / README.md
Last active September 5, 2018 21:03
Xen Dom0 on Debian Stretch with VLAN (with and without Open vSwitch)

Xen Dom0 on Debian Stretch

Version 2018-01-17: Erik Elmore :octocat: [email protected]

Install Dom0 System

Use the conventional Debian installer to install the base system. Disk layout:

  • 256M boot ext4. Needs to be big enough for all kernel versions and modules for guests
  • Rest of the disk to LVM2. Create logical volumes for:
    • root ext4 (8G-16G)
    • swap (optional, whatever size you like)
@IronSavior
IronSavior / s3_list_objects_stream.js
Last active December 6, 2018 02:18
S3.listObjectsV2 as stream
"use strict";
const {Readable} = require('readable-stream');
const {S3} = require('aws-sdk');
// Convert the given S3::listObjectsV2 request to a Readable stream
// req should be an un-sent S3::listObjectsV2() request
// opts are typical stream options. Object mode is required.
function s3_list_stream( req, opts ){
opts = Object.assign({}, opts, {read, objectMode: true});
const stream = new Readable(opts);
@IronSavior
IronSavior / make-git-dag-alias.sh
Created January 24, 2020 22:51
Custom git log graph
#!/bin/bash
commit='%C(dim yellow)%h'
time='%C(bold yellow)%ad'
author='%C(dim cyan)%an'
refs='%C(auto)%d'
subject='%C(dim white)%s'
fmt="$commit $time $author ${refs}%n${subject}%n"
git config --global alias.dag "log --graph --date=relative --pretty=format:'${fmt}'"
@IronSavior
IronSavior / start-ssh-agent.sh
Last active September 20, 2020 18:23
Start SSH agent at login
#!/usr/bin/env bash
# Write paths to keys to autoload in ~/.autoload-ssh-keys
env=~/.ssh/agent.env
autoload=~/.autoload-ssh-keys
agent_load_env () { test -f "$env" && . "$env" >| /dev/null ; }
agent_start () {
@IronSavior
IronSavior / hmtc.sh
Created January 22, 2021 20:44
Old traffic shaper script
#!/bin/bash
# Heavy Metal Traffic Control (HMTC)
# Erik Elmore 2005-06-11
# Based on concepts from WonderShaper
### Configuration ###
# Set this to your WAN interface
INTERFACE=eth0
# Upstream Parameters #
@IronSavior
IronSavior / mean_luma.go
Last active February 5, 2022 01:27
Compute mean luma of image files
package main
import (
"fmt"
"image"
"image/color"
_ "image/jpeg"
"os"
)
@IronSavior
IronSavior / google-oauth.js
Last active February 17, 2022 00:01
Google OAuth2 for local app
const fs = require('fs')
const { google } = require('googleapis')
const http = require('http')
const open = require('open')
const { promisify } = require('util')
const config = {
auth_scopes: [
'https://www.googleapis.com/auth/drive.readonly',
],
@IronSavior
IronSavior / main.go
Created April 21, 2022 23:42
It is possible for an interface to be un-satisfied by a superset interface value (and this is dumb)
package main
///
/// Genderated code:
///
type GeneratedQueries interface {
A() error
B() error
}