Skip to content

Instantly share code, notes, and snippets.

@lawlesst
lawlesst / get_next.py
Created August 26, 2012 21:59
Helper to get a random number identifier for a given namespace in a Jena model.
"""
Get the nextURI for the given namespace.
Jython interpretation of getNextURI here:
http://svn.code.sf.net/p/vivo/vitro/code/branches/dev-sdb/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/jena/JenaIngestUtils.java
"""
def get_next_uri(namespace, model):
from com.hp.hpl.jena.rdf.model import SimpleSelector
@lawlesst
lawlesst / transform.py
Created August 16, 2012 13:26
XSLT with saxon in Jython
"""
Use saxon to do XSLT with Jython
See http://codingwithpassion.blogspot.com/2011/03/saxon-xslt-java-example.html
Pass in arguments
- 1 xslt
- 2 xml source
- 3 xml output
@lawlesst
lawlesst / vivo_vocab.py
Created August 15, 2012 15:08
Jython class containing the vocabulary for Vivo 1.5 core. For use with Jython and Jena.
"""
Vivo vocab generated with jena.schemagen.
"""
from com.hp.hpl.jena.rdf.model import *
from com.hp.hpl.jena.ontology import *
class Vivo(object):
def __init__(self):
m_model = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM, None );
@lawlesst
lawlesst / expired_searches.sh
Created July 16, 2012 12:35
Cleans the search history table in Vufind.
#!/bin/sh
#removes expired searches in Vufind search history table
EXPIRE_DATE=`date --date="-2 day" +%Y-%m-%d`
echo "Vufind - deleting expired search sessions from $EXPIRE_DATE."
mysql -u $1 --password=$2 -e "delete from search where (saved=0 AND created<=\"${EXPIRE_DATE}\")" vufind
@lawlesst
lawlesst / test.php
Created May 19, 2012 18:38
PHPUnit tests for a prime number calculator.
---- test.php ----
/**
* Unit tests for the prime number calculator included
*
*
*/
<?php
@lawlesst
lawlesst / calcprime.php
Created May 19, 2012 18:37
PHP functions for calculating prime numbers.
<?php
/**
* Check to see if a given integer is prime.
*
* Adapted from this Python implementation http://pthree.org/2007/09/05/prime-numbersin- python/
* This list of the first 10,000 prime numbers is also helpful http://primes.utm.edu/lists/small/10000.txt
*
* @param int $number the number to check to see if it is prime.
* @return boolean true if the number is prime, false if not.
@lawlesst
lawlesst / index.html
Created May 19, 2012 18:36
View code for a basic PHP app that calculates prime numbers.
<!DOCTYPE html>
<html>
<link rel="stylesheet" href="http://blueprintcss.org/blueprint/screen.css" type="text/css">
<link rel="stylesheet" href="http://blueprintcss.org/blueprint/plugins/fancy-type/screen.css" type="text/css" media="screen, projection">
<style>
body {
padding: 3em;
}
h2 a, a.number:hover, p.startover a:hover {
@lawlesst
lawlesst / pubmed.py
Created May 18, 2012 01:01
Parser for retrieving PubMed metadata
"""
Lookup PMIDS and parse the returned metadata into the BibJSON format.
See: http://www.ncbi.nlm.nih.gov/books/NBK25499/#chapter4.ESearch
"""
from lxml import etree
import urllib
from pprint import pprint
@lawlesst
lawlesst / ballpark_costs_03_11.csv
Created March 24, 2012 20:13
Various costs for ballparks - compiled from reports from teamarketing.com
Year Short Name Team Ticket Change Ticket Beer Drink Dog Parking Program Cap FCI Change
2011 diamondbacks Arizona Diamondbacks 15.74 0.1 60.5 4.0014 3.7524 2.75 10.0 0.0 7.0 120.96 0.05
2011 braves Atlanta Braves 19.38 0.0 49.26 6.7516 4.5022 4.5 12.0 0.0 15.0 169.02 0.029
2011 orioles Baltimore Orioles 23.9 0.021 43.72 6.2518 2.0016 2.5 8.0 5.0 15.0 174.1 0.011
2011 redsox Boston Red Sox 53.38 0.02 172.51 7.2512 4.002 4.5 27.0 5.0 20.0 339.01 0.013
2011 cubs Chicago Cubs 46.9 -0.012 103.47 6.5016 3.0015 4.5 25.0 5.0 20.0 305.6 -0.012
2011 whitesox Chicago White Sox 40.67 0.052 99.77 6.5016 3.0014 3.5 23.0 4.0 13.0 258.68 0.036
2011 reds Cincinnati Reds 20.56 0.071 60.23 5.5012 1.0012 1.0 17.0 4.0 18.0 162.24 0.073
2011 indians Cleveland Indians 18.49 -0.164 60.56 4.5012 4.7524 4.25 12.0 0.0 20.0 170.96 -0.053
2011 rockies Colorado Rockies 19.5 0.0 36.5 5.5016 3.2518 3.25 8.0 5.0 14.0 161.0 0.0
@lawlesst
lawlesst / gist:2184245
Created March 24, 2012 15:23 — forked from anonymous/gist:2184239
Hot dog pricing data
hotdog_years = ["2011", "2010", "2009"]
hotdog_data = [{"Team":"Boston Red Sox","TeamID":"redsox","2011":4.5,"2010":4.5,"2009":4.5},
{"Team":"New York Yankees","TeamID":"yankees","2011":3,"2010":3,"2009":3},
{"Team":"Chicago Cubs","TeamID":"cubs","2011":4.5,"2010":4.25,"2009":3},
{"Team":"Chicago White Sox","TeamID":"whitesox","2011":3.5,"2010":3.25,"2009":3.25},
{"Team":"New York Mets","TeamID":"mets","2011":5,"2010":5,"2009":4.75},
{"Team":"Philadelphia Phillies","TeamID":"phillies","2011":3.75,"2010":3.75,"2009":3.75},
{"Team":"Los Angeles Dodgers","TeamID":"dodgers","2011":5,"2010":5,"2009":5},
{"Team":"St. Louis Cardinals","TeamID":"cardinals","2011":4.25,"2010":4,"2009":4},
{"Team":"Houston Astros","TeamID":"astros","2011":4.75,"2010":4.75,"2009":4.75},