Skip to content

Instantly share code, notes, and snippets.

View MichaelSnowden's full-sized avatar

Michael Snowden MichaelSnowden

View GitHub Profile
@MichaelSnowden
MichaelSnowden / nopeek.user.js
Last active November 26, 2016 07:59
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;
@MichaelSnowden
MichaelSnowden / duolingo.js
Last active July 15, 2016 07:49
Count remaining lessons on Duolingo. You need jQuery on the page for this. This is a great plugin for that https://chrome.google.com/webstore/detail/jquery-injector/indebdooekgjhkncmgbkeopjebofdoid/related?hl=en. Run this on the Duolingo home page to see how many lessons you have remaining https://www.duolingo.com/
"Lessons left: " + $(".lessons-left").text().split("").map((v, i) => i % 3 == 0 ? -parseInt(v) : i % 3 == 1 ? 0 : parseInt(v)).reduce((a, b) => a + b)
@MichaelSnowden
MichaelSnowden / functional.js
Created January 14, 2016 10:46
Some random Python methods implemented in JavaScript. Don't use this. It's insanely slow, and I had to remove it from my application.
function map(fn, u) {
mapped = [];
for (var x of u) {
args = [];
if (x instanceof Array) {
for (var y of x) {
args.push(y);
}
} else {
args.push(x);