Skip to content

Instantly share code, notes, and snippets.

View natematias's full-sized avatar

J. Nathan Matias natematias

View GitHub Profile
import mediacloud
import json
mc = mediacloud.api.MediaCloud('')
# query mentions of civic hacking
res = mc.sentenceList('( hacking AND civic ) OR ( hackathon AND civic)', '+publish_date:[2013-01-01T00:00:00Z TO 2014-04-19T00:00:00Z] AND +media_sets_id:1')
#print "found " + res['response']['numFound'] + " sentences"
story_ids = []
[story_ids.append(i) for i in [y["stories_id"] for y in res["response"]["docs"]] if not story_ids.count(i)]
@natematias
natematias / Part of Speech Tagging
Last active August 29, 2015 14:01
Tagging parts of speech in NLTK
import nltk
from urllib import urlopen
# download alice in wonderland
url = "http://www.gutenberg.org/cache/epub/11/pg11.txt"
raw_text = urlopen(url).read()
tokens = nltk.word_tokenize(raw_text)
freq_dist = nltk.FreqDist(tokens)
#freq_dist.plot(50, cumulative=False)
@natematias
natematias / QueryCLIFF.py
Created May 22, 2014 19:44
Accessing a CLIFF server from Python
import nltk
import urllib
import json
import urllib2
from urllib import urlopen
# download From Egypt to Japan by Henry Martyn
url = "http://www.gutenberg.org/cache/epub/39474/pg39474.txt"
raw_text = urlopen(url).read()
@natematias
natematias / moby_dick_synonyms
Created May 24, 2014 13:40
Moby Dick, Synonym edition
This file has been truncated, but you can view the full file.
The Project Gutenberg EBook of Moby Dick; or The Whale, by Herman Melville This eBook is for the use of anyone anywhere at no cost and with almost no restrictions whatsoever. You may copy it, give it away or re-use it under the terms of the Project Gutenberg License included with this eBook or online at www.gutenberg.org Title: Moby Dick; or The Whale Author: Herman Melville Last Updated: January 3, 2009 Posting Date: December 25, 2008 [ EBook # 2701 ] Release Date: June, 2001 Language: English *** START OF THIS PROJECT GUTENBERG EBOOK MOBY DICK; OR THE WHALE *** Produced by Daniel Lazarus and Jonesey MOBY DICK; OR THE WHALE By Herman Melville Original Transcriber's Notes: This text is a combination of etexts, one from the now-defunct ERIS project at Virginia Tech and one from Project Gutenberg's archives. The proofreaders of this version are indebted to The University of Adelaide Library for preserving the Virginia Tech version. The resulting etext was compared with a public domain hard copy version of the t
require 'csv'
emails = CSV.read(ARGV[0])
emails.shift
full_emails = []
emails.each do |email|
if(!email[0].nil? and email[0].strip.size>0)
full_emails << email[0].strip
end
end
@natematias
natematias / popit.py
Created July 28, 2014 17:49
@natematias Popit Python Llibrary
#don't use this.
# Use https://github.com/mysociety/popit-python instead.
# But I didn't have the heart not to put it online
# after several hours of creating this, before realizing
# that a library already existed, and that
# it just hadn't appeared in my search results and
# the library wasn't listed in mySociety API documentation
import requests, json, yaml
@natematias
natematias / 365grateful_on_twitter.py
Last active August 29, 2015 14:04
Analyze 365Grateful on Twitter
#adapted from minus_context
import nltk
import feedparser
import random
import twitter
import yaml
import string
import re
from urlparse import urlparse
@natematias
natematias / Chipotle order distribution
Created February 19, 2015 03:12
Distribution of Dollars Spent at Chipotle per Order
import codecs
import json
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from scipy import stats
from dateutil import *
import math
import statsmodels.formula.api as sm
@natematias
natematias / exception_handling_class_methods.rb
Created July 14, 2015 23:34
Multiple-attempt exception handling for class methods
class SillyError < StandardError; end
module CatchAnError
def self.included base
base.extend CatchSpecific
end
module CatchSpecific
def catch_specific_error(a,stdout)
num_attempts = 0
#This script will change the existing card database for wagn so that the root template card specifies that reads will require an authenticated user rather than anonymous access as was the default
# The role encapsulating read needs authenticated user
Card.find_by_name("Basic+*tform").permit(:read, Role[:auth])