Skip to content

Instantly share code, notes, and snippets.

View tarmstrong's full-sized avatar

Tavish Armstrong tarmstrong

View GitHub Profile
@tarmstrong
tarmstrong / test_modified.py
Last active August 29, 2015 13:56
very rough tests for check_modified
# some test data
cell1 = {
"cell_type": "code",
"collapsed": False,
"input": [
"x",
"x",
"x",
"x",
@tarmstrong
tarmstrong / myconcordia-refresh.user.js
Created February 3, 2014 18:29
Chrome user script for refreshing myconcordia every five minutes so you don't get logged out of your portal or Moodle while you're working.
// ==UserScript==
// @match https://my.concordia.ca/*
// ==/UserScript==
// Prevent MyConcordia from logging you out every X minutes UGHGHGHGHGH
// by refreshing the page every five minutes.
setTimeout(function () {
location.href = location.href;
}, 1000 * 60 * 5);
@tarmstrong
tarmstrong / vimlastcommit.sh
Created January 2, 2014 22:06
Open the files you modified in the HEAD commit in vim.
#!/usr/bin/env bash
LAST_COMMIT_FILES=$( git log -1 --numstat --pretty="%h" | tail -n +3 | awk '{print $3}' );
vim -p $LAST_COMMIT_FILES
@tarmstrong
tarmstrong / vimunstaged.sh
Created January 2, 2014 17:53
In a git repository, open all currently modified and unstaged changes in vim. Each file is opened in a separate tab.
#!/usr/bin/env bash
MODDED_FILES=$( git ls-files --modified );
vim -p $MODDED_FILES
@tarmstrong
tarmstrong / mgu.py
Created December 5, 2013 14:54
Implementation of MGU
# Most General Unifier implementation
# - Tavish Armstrong
class Pred(object):
def __init__(self, name, args):
self.name = name
self.args = args
def apply(self, sub):
@tarmstrong
tarmstrong / ughghghghghghghg.py
Created November 29, 2013 02:43
ghgghughghghghghghghghghghg
import lib2to3.pygram
import lib2to3.pgen2.driver as driver
class Tree(object):
def __init__(self, n):
self.n = n
self.used_names = set()
def __getitem__(self, idx):
@tarmstrong
tarmstrong / make_merge_conflict.py
Created November 22, 2013 00:48
Cause a merge conflict!
# Tavish Armstrong (c) 2013
#
# make_merge_conflict.py
#
# Make a new directory, initialize a git repository within, and cause a merge conflict.
# Yes. On purpose.
import os
import subprocess
import random
#!/usr/bin/env bash
while [ 1 ];
do
cp ~/test.txt ~/test.txt.old
EVENT=$(inotifywait --format '%e' ~/test.txt);
[ $? != 0 ] && exit
[ "$EVENT" = "MODIFY" ] && echo 'file modified!'
diff ~/test.txt ~/test.txt.old
done
# two strings
A = 'abcabba'
B = 'cbabac'
# Get a list of columns and their truth values.
[[a == b for (a, b) in list(it.product(A, B))][i*6:i*6+6] for i in range(len("abcabba"))]
"""
expected_result = [[False, False, True, False, True, False],
[False, True, False, True, False, False],
@tarmstrong
tarmstrong / nbdiff.py
Created October 7, 2013 04:42
Gist of the nbdiff backend (very rough idea)
from flask import Flask
class NBDiffFlask(Flask):
def set_files(self, file1, file2):
self.file1 = file1
self.file2 = file2
app = NBDiffFlask(__name__)
@app.route("/diff.js")