Skip to content

Instantly share code, notes, and snippets.

View mayhewsw's full-sized avatar

Stephen Mayhew mayhewsw

View GitHub Profile
@mayhewsw
mayhewsw / convertD3graph.js
Last active August 29, 2015 14:23
Convert intelligible graph to D3 graph.
// almost d3-style graph
var graph = {"nodes" : [
{"name":"somenode"},
{"name":"somenewnode"}
],
"links":[
{"source":"somenode", "target":"somenewnode"}
]
};
@mayhewsw
mayhewsw / index.html
Last active August 29, 2015 14:23
D3 Test
<html>
<head>
<title>Put stuff here</title>
</head>
<body>
<h2>This is my block/gist!</h2>
<div id="putstuffhere"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
<script>

cs-shirt.txt is from the UIUC CS shirt. The binary digits are shaped to form a big I. The cs-shirt.py translates the shirt into text.

import sys
if len(sys.argv) != 2:
print "Usage: python nospaces.py <inputfile>"
exit()
infile = sys.argv[1]
print "Removing the spaces from " + infile + "..."
package edu.illinois.cs.cogcomp.tutorial;
import edu.illinois.cs.cogcomp.lbjava.learn.Lexicon;
import edu.illinois.cs.cogcomp.lbjava.learn.SparseNetworkLearner;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.*;
import java.util.stream.Stream;
@mayhewsw
mayhewsw / makeall.sh
Last active August 16, 2022 19:17
Data Preparer for Bible Corpus
#!/bin/sh
for f in *.xml.gz; do
if [ $f == "English.xml.gz" ] ; then
continue;
fi
python makeplaintext.py $f English.xml.gz;
done
@mayhewsw
mayhewsw / getlist.py
Last active February 18, 2016 23:02
Scrape script information from scriptsource
#!/usr/bin/python
from bs4 import BeautifulSoup
# use url: http://unicode.org/iso15924/iso15924-codes.html
with open("iso15924list.html") as f:
html_doc = f.read()
soup = BeautifulSoup(html_doc, 'html.parser')
@mayhewsw
mayhewsw / plotcm.py
Created April 22, 2016 02:18
Plot a confusion matrix.
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
import matplotlib.patches as patches
mpl.rcParams['font.family'] = "Times New Roman"
#mpl.rcParams['font.size'] = "11"
mpl.rc('pdf', fonttype=42)
@mayhewsw
mayhewsw / editdist.py
Created May 6, 2016 18:30
Edit Distance
import numpy as np
import math
import sys
np.set_printoptions(linewidth=400)
def EditDistance(s, t):
# For all i and j, d[i,j] will hold the Levenshtein distance between
# the first i characters of s and the first j characters of t.
# Note that d has (m+1) x(n+1) values.
@mayhewsw
mayhewsw / cgm.py
Created May 7, 2016 15:09
Conjugate Gradient Method
from __future__ import division
import numpy as np
Q = [[3, -1], [-1, 3]]
b = [1,0]
x = [1,1]
d = []
r = []