Skip to content

Instantly share code, notes, and snippets.

View MJGTwo's full-sized avatar
🔧
🤖💤💭⚡🐑

Michael Gardner MJGTwo

🔧
🤖💤💭⚡🐑
View GitHub Profile
@MJGTwo
MJGTwo / d4.js
Last active December 4, 2019 18:31
aoc 2019 day 4 solution
const parse = text => text.split("-").map(bound => +bound);
const range = (upperBound, lowerBound = 0) =>
[...Array(upperBound - lowerBound).keys()]
.map(i => i + lowerBound)
.map(i => `${i}`);
const generate = bounds => range(bounds[1], bounds[0]);
const rule1 = /^0*1*2*3*4*5*6*7*8*9*$/; //number to the right is greater than or equal to previous number
const rule2 = /\d*(\d)\1\d*$/; //there is at least one duplicate neighbor
const rule3 = sequence =>
@MJGTwo
MJGTwo / d2.js
Created December 3, 2019 19:04
AOC 2019 answer
const parse = text => text.split(",").map(el => +el);
let backupMemory = parse(input);
const optCode = number => (a, b) =>
({
1: a + b,
2: a * b,
99: null
}[number]);
const readFromMemory = (memory, location) => memory[location];
const writeToMemory = (memory, location, value) => (memory[location] = value);
@MJGTwo
MJGTwo / d3.js
Last active December 3, 2019 18:46
i1 = "R8,U5,L5,D3";
i2 = "U7,R6,D4,L4";
const dx = { L: -1, R: 1, U: 0, D: 0 };
const dy = { U: -1, D: 1, R: 0, L: 0 };
const parse = steps => steps.split(",");
const toString = pos => `${pos[0]},${pos[1]}`;
wire1 = parse(i1);
wire2 = parse(i2);
length = 0;
x = 0;
@MJGTwo
MJGTwo / wf
Created September 19, 2019 15:49
script for a mac to show the password of the wifi it's connected to.
#!/bin/bash
# usage: $wf "mynetworkname"
security find-generic-password -ga "$1" | grep "password:"
@MJGTwo
MJGTwo / counterReducer.ts
Last active September 19, 2019 15:26
an example of redux using 3 actions for a counter: increment, decrement, and reset.
// ./counter/types.ts
export interface CounterState {
value: number;
}
export const INCREMENT_COUNTER = "INCREMENT_COUNTER";
export const DECREMENT_COUNTER = "DECREMENT_COUNTER";
export const RESET_COUNTER = "RESET_COUNTER";
@MJGTwo
MJGTwo / curry.ts
Created August 20, 2019 19:00
A TypeScript function that converts aggregating functions into currying functions if they have the same types. Original idea by Jaco Pretorius.
type aggregateFn<T> = (...args: T[]) => T;
interface curryFn<T> extends aggregateFn<T> {
(...args: T[]): curryFn<T>;
}
const curry = <T>(fn: aggregateFn<T>): curryFn<T> => (
...args: any[]
): curryFn<any> | any =>
args.length ? curry(fn.bind.apply(fn, [undefined].concat(args))) : fn();
@MJGTwo
MJGTwo / g
Created June 23, 2019 16:34
A more robust "git status" script I found years ago and keep at `/usr/local/bin/g`. `chmod +x` it and you're good to go.
#!/bin/bash
if [[ $(($RANDOM % 5)) = 0 ]]
then git fetch; clear; echo "Fetched";
else
clear;
fi
echo 'Branches:'
git branch;
@MJGTwo
MJGTwo / uuid.ts
Created June 18, 2019 19:09
Useful uuid script. Made by Jeff Ward, updated to TypeScript by me.
const lut: string[] = [];
for (let i = 0; i < 256; i++) {
lut[i] = (i < 16 ? '0' : '') + i.toString(16);
}
/*
* Fast UUID generator, RFC4122 version 4 compliant.
* @author Jeff Ward (jcward.com).
* @license MIT license

Keybase proof

I hereby claim:

  • I am mjgtwo on github.
  • I am mjg2 (https://keybase.io/mjg2) on keybase.
  • I have a public key ASC7ZLMeD-yAuD7W7Jz6eH564NtIpuvGt9lgIHCHZmcjIgo

To claim this, I am signing this object:

@MJGTwo
MJGTwo / dash-listen-1.py
Last active November 2, 2015 16:23 — forked from eob/dash-listen-1.py
import logging
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)#Surpress's small errors from Scapy
from scapy.all import *
def arp_display(pkt):
if pkt.haslayer(ARP): #makes sure it is ARP
if pkt[ARP].op == 1: #who-has (request)
if pkt[ARP].psrc == '0.0.0.0': # ARP Probe
print "ARP Probe from: " + pkt[ARP].hwsrc