Skip to content

Instantly share code, notes, and snippets.

View MichaelSnowden's full-sized avatar

Michael Snowden MichaelSnowden

View GitHub Profile
@MichaelSnowden
MichaelSnowden / taskmanager.hs
Last active December 9, 2017 21:29
Haskell Todo list CLI
import Data.List
import Prelude hiding (id, pure)
import System.Directory
import System.Exit
import System.IO
import System.IO.Error
import System.Process
import Text.Read
data Route
import cv2
import numpy as np
import sys
if len(sys.argv) < 3:
print 'Usage: python match.py <template.png> <image.png>'
sys.exit()
template_path = sys.argv[1]
template = cv2.imread(template_path, cv2.IMREAD_UNCHANGED)
@MichaelSnowden
MichaelSnowden / nopeek.user.js
Last active March 3, 2025 06:39
User script to prevent peeking in Duolingo. Download tampermonkey, and then click 'raw' on this page and it should install the script for you.
// ==UserScript==
// @name NoPeekDuolingo
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Prevents peeking in Duolingo practice sessions
// @author Michael Snowden
// @match https://www.duolingo.com/practice
// @grant none
// @require http://code.jquery.com/jquery-latest.js
// ==/UserScript==
@MichaelSnowden
MichaelSnowden / image_recognition.py
Last active November 4, 2016 07:46
Naive Bayes. Make sure to have the datasets from http://yann.lecun.com/exdb/mnist/ if you're using this
from operator import add, mul
from functools import reduce
from math import log
NUM_PIXELS = 784
NUM_ROWS = 28
NUM_COLS = 28
def display(x_X):
@MichaelSnowden
MichaelSnowden / json.py
Created October 24, 2016 04:28
A simple JSON parser that hasn't been tested much
def parse(s):
return value(s)[1]
def stringify(o, indent=0):
if isinstance(o, dict):
if not o:
return '{}'
return '{\n' + ",\n".join(' ' * (indent + 4) + "'" + k + "' : " + stringify(v, indent + 4) for k, v in o.items()) + '\n' + ' ' * indent + '}'
if isinstance(o, list):
if not o:
@MichaelSnowden
MichaelSnowden / maxflow.py
Created October 20, 2016 00:45
Edmonds-Karp without reverse flow? I don't know if this works.
def maxflow(E, s, t):
while True:
prev = {}
q = [s]
while q:
u = q.pop(0)
for v in E[u]:
if v not in prev and E[u][v].cap > E[u][v].flow:
prev[v] = u
q.append(v)
@MichaelSnowden
MichaelSnowden / ac3.py
Last active September 12, 2016 17:38
AC3
def ac3(X, D, R1, R2):
for x in X:
D[x] = set(vx for vx in D[x] if x not in R1 or R1[x](vx))
arcs = set((x, y) for x in R2 for y in R2[x])
while arcs:
x, y = arcs.pop()
c = len(D[x])
D[x] = set(vx for vx in D[x] if any(R2[x][y](vx, vy) for vy in D[y]))
@MichaelSnowden
MichaelSnowden / UnionBankTransactionHistoryDownloader.java
Created July 15, 2016 08:04
Download transaction history from UnionBank to store in a database after the 18 month period or something.
import lombok.*;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.Select;
import java.io.File;
"Lessons left: " + Array.prototype.map.call(document.getElementsByClassName("lessons-left"), a => a.innerText).filter(s => s.length > 0).map(v => +v[2] - v[0]).reduce((a, b) => a + b)
@MichaelSnowden
MichaelSnowden / Example.java
Created July 15, 2016 07:42
Simple demonstration for rethrowing exceptions with Java lambdas without external libraries
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.Arrays;
import java.util.function.Function;
import java.util.stream.Collectors;
public class Example {
interface ExceptionalFunction<T, R> {
R apply(T t) throws Exception;