Skip to content

Instantly share code, notes, and snippets.

Sands Fish sandsfish

Block or report user

Report or block sandsfish

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View ngram-analysis.py
# all_summary is the data here. in this case, just a lot of text records collapsed into on corpus string
# Prep data for NLTK Analysis
import nltk.collocations
tokens = nltk.word_tokenize(all_summary)
text = nltk.Text(tokens)
# Remove stop-words, convert to lower-case, remove all non-alpha characters
from nltk.corpus import stopwords
stopwords = stopwords.words('english')
@sandsfish
sandsfish / mc_heart-disease.py
Created May 13, 2014
"Heart Disease" Phrase WordCount Query on Media Cloud
View mc_heart-disease.py
import mediacloud
import json
mc_query = u'+"heart disease"'
mc_filter = u'+publish_date: [2010-01-01T00:00:00Z TO 2011-01-01T00:00:00Z]'
print('query: ' + mc_query)
print('filter: ' + mc_filter)
mc = mediacloud.api.MediaCloud('MY_API_KEY')
@sandsfish
sandsfish / python-simple-scrape.py
Created Dec 18, 2013
Very simple example of using Python and Requests to scrape the results from a search interface.
View python-simple-scrape.py
# For non-trivial scraping, better to use Scrapy or Beautiful Soup...
# - http://doc.scrapy.org/en/latest/intro/tutorial.html
# - http://www.crummy.com/software/BeautifulSoup/
import requests
r = requests.get("http://sacbee.com/search_results?aff=1100&q=robot")
r
# <Response [200]>
View MezMatrix001.pde
float time = 0;
float radius = 0;
void setup() {
background(5);
size(displayWidth,displayHeight, OPENGL);
noStroke();
}
void draw() {
@sandsfish
sandsfish / ReadHTTPData.pde
Created Mar 23, 2013
Minimal setup to use Apache's HTTPClient in a Processing sketch.
View ReadHTTPData.pde
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.HttpResponse;
import org.apache.http.HttpEntity;
// http://hc.apache.org/httpcomponents-client-ga/tutorial/html/fundamentals.html - Apache HttpClient
// https://forum.processing.org/topic/http-post-processing - Integration with Processing (different from above)
// https://code.google.com/p/processing/source/browse/trunk/processing/java/libraries/net/examples/HTTPClient/HTTPClient.pde?r=7950 - Messy.
// https://github.com/francisli/processing-http - Unnecessary?
@sandsfish
sandsfish / getMARCField Example.r
Created Feb 12, 2013
R function to parse out list of specific field/sub-field from MARC/XML
View getMARCField Example.r
library(XML)
getMARCField = function(marc_doc, tag, code) {
xpath = paste("/m:collection/m:record/m:datafield[@tag='", tag, "']/m:subfield[@code='", code, "']", sep="")
return(xpathApply(marc_doc, xpath, namespaces=c("m"), xmlValue))
}
vs = xmlRoot(xmlParse('vail-first-3500.xml'))
field100a = getMARCField(vs, '100', 'a')
@sandsfish
sandsfish / try-tx.rb
Created Dec 18, 2012
RDF.rb transaction delete failing with gems/rdf-0.3.11/lib/rdf/mixin/mutable.rb:124:in `delete': undefined method `query' for #<RDF::Transaction:0x1e2bde(graph: nil, deletes: 0, inserts: 0)> (NoMethodError)
View try-tx.rb
#!/Users/sands/.rvm/rubies/ruby-1.8.7-p371-i386/bin/ruby
require 'rubygems'
require 'rdf'
require 'rdf/ntriples'
include RDF
repository = RDF::Repository.load("http://rdf.rubyforge.org/doap.nt")
# reports correct predicate URI...
# DOAP.name: http://usefulinc.com/ns/doap#name
@sandsfish
sandsfish / doc-info-snippet.txt
Created Jun 22, 2012
multiple committee members HTML fields
View doc-info-snippet.txt
<div id="committee-members"><table id="att4" style="display">
<tbody><tr>
<td><input type="text" class="input-medium" id="committeeFirstName4" name="committeeFirstName4"></td>
<td><input type="text" class="span1" id="committeeMiddleInitial4" name="committeeMiddleInitial4"></td>
<td><input type="text" class="input-medium" id="committeeLastName4" name="committeeLastName4"></td>
@sandsfish
sandsfish / Submit.java
Created Jun 4, 2012
Submit Controller Authentication Wiring
View Submit.java
package controllers;
import play.*;
import play.mvc.*;
import play.mvc.Http.Header;
import java.util.*;
import java.util.Map.Entry;
import org.tdl.vireo.model.RoleType;
@sandsfish
sandsfish / Submit.java
Created Jun 4, 2012
Submit Controller Authentication
View Submit.java
package controllers;
import play.*;
import play.mvc.*;
import play.mvc.Http.Header;
import java.util.*;
import java.util.Map.Entry;
import org.tdl.vireo.model.RoleType;
You can’t perform that action at this time.