Skip to content

Instantly share code, notes, and snippets.

View amundo's full-sized avatar
🫥
(0)

Patrick Hall amundo

🫥
(0)
  • Massachusetts
  • 21:01 (UTC -12:00)
View GitHub Profile
@amundo
amundo / base.py
Created April 14, 2013 17:47 — forked from sweemeng/base.py
from bottle import Bottle
from sqlalchemy import create_engine
from sqlalchemy import MetaData
from sqlalchemy import Table
# Main Web App
app = Bottle()
# Configuration for sqlalchemy
# source https://scraperwiki.com/scrapers/malaysian_mp_profile/
@amundo
amundo / output.sh
Created July 5, 2013 19:05
What .edu sites exist that are anagrams of UCSB?
Desktop/$ ./ping2.py
http://ucsb.edu True
http://ucbs.edu False
http://uscb.edu True
http://usbc.edu False
http://ubcs.edu False
http://ubsc.edu False
http://cusb.edu False
http://cubs.edu False
http://csub.edu True
import json
data = {"nodes":[{"nodename":"foo"},{"nodename":"bar"}]}
print json.dumps(data)
nodes = data["nodes"]
nodes.sort(key=lambda node: node['nodename'])
data["nodes"] = nodes
print json.dumps(data)
@amundo
amundo / gist:6653652
Created September 21, 2013 19:58
A couple of changes to example4.html from this great article by Jos Dirksen (http://www.smartjava.org/content/exploring-html5-web-audio-visualizing-sound) are sufficient to get it running in Firefox Aurora.
38,39c38,40
< // create the audio context (chrome only for now)
< var context = new webkitAudioContext();
---
> // create the audio context -- covers Firefox and Chrome
> var AudioContext = AudioContext || webkitAudioContext;
> var context = new AudioContext();
70c71,73
< javascriptNode = context.createJavaScriptNode(2048, 1, 1);
---
function readFile(file) {
var reader = new FileReader();
var deferred = $.Deferred();
reader.onload = function(event) {
deferred.resolve(event.target.result);
};
reader.onerror = function() {
deferred.reject(this);
import nltk
from nltk.corpus import brown
pronouns = 'i me my us we he she it her his its they them their'.split()
news_text = brown.words(categories='news')
fdist = nltk.FreqDist([w.lower() for w in news_text])
# worst bar chart in human history
for p in pronouns:
@amundo
amundo / brown_vs_reuters_pronouns.py
Created January 23, 2014 19:25
This is a simplistic comparison of pronoun frequencies in (a) the Brown corpus under the 'news' category and (b) the whole of the Reuters corpus.
import nltk
from nltk.corpus import brown, reuters
pronouns = 'I me my us we he she it her his its they them their'.split()
#news_text = brown.words(categories='religion')
brown_text = brown.words(categories='news')
reuters_text = reuters.words()
import matplotlib.pyplot as plt
import numpy as np
from nltk.corpus import inaugural
def count_vowels(word):
return len([c for c in word.lower() if c in 'aeiou'])
words = set(inaugural.words())
lengths = [len(w) for w in words]
vowel_count = [count_vowels(w) for w in words]
@amundo
amundo / futz.py
Created March 11, 2014 05:31
futzing with python encodings.
>>> some_ethiopic = [u"\u1234", u"\u1235", u"\u1236"]
>>> for s in some_ethiopic:
... print s, unicodedata.name(s)
...
ሴ ETHIOPIC SYLLABLE SEE
ስ ETHIOPIC SYLLABLE SE
ሶ ETHIOPIC SYLLABLE SO
>>> # ok, now we want to put these in a dictionary:
... names = {}
>>> for s in some_ethiopic: names[s] = unicodedata.name(s)
@amundo
amundo / depunctuate.py
Last active August 29, 2015 13:57
A simple depunctuator with and without regexes
def depunctuate(raw, badletters):
"""
return a copy of the string raw with all of
badletters removed
"""
fixed = ''
for letter in raw:
if letter not in badletters:
fixed += letter
return fixed