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 / example-error.js
Last active February 19, 2022 10:18
Require AWS Lambda handler to invoke callback before exit (prevent Node exit until handler invokes callback)
const lambda_handler = require('lambda-handler');
exports.handler = lambda_handler(( event, ctx, done ) => {
// This will log a handled error to CloudWatch and return the error to AWS Lambda
throw 'BOOM!';
});
@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 / composable_enums_demo.rb
Last active January 20, 2021 01:39
Composable Enumerators in Ruby
# @author Erik Elmore <erik@erikelmore.com>
# This is getting a little out of hand... :dizzy_face:
# For printing trace output for demonstration
module Status
def status( method_name, args = [], extra = nil )
extra = ' => %s' % extra if extra
puts '%s#%s(%s)%s' % [self.class, method_name, args.join(', '), extra]
end
end
@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 () {