Skip to content

Instantly share code, notes, and snippets.

View IronSavior's full-sized avatar

Erik Elmore IronSavior

View GitHub Profile
@IronSavior
IronSavior / conway.go
Created July 14, 2023 14:30
Conway's Type-Safe Game of Life
package main
import (
"fmt"
)
type Loc struct { X, Y int }
func (l Loc) Neighbors() []Loc {
neighbors := make([]Loc, 0, 8)
@IronSavior
IronSavior / activity.js
Created October 26, 2022 00:07
Google Drive / Drive Activity API
const { google } = require('googleapis');
const config = {
auth_scopes: [
'https://www.googleapis.com/auth/drive.activity.readonly',
],
}
async function activity_for({ ancestorName, itemName }) {
@IronSavior
IronSavior / matcher_test.go
Created May 4, 2022 00:37
Use Gomega matchers with gomock
package matcher_test
import (
"fmt"
"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
@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
}
@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 / 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 / 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 / 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 / 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 / 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);