Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / load_graph.py
Created September 10, 2012 20:35
Load an external graph to a Jena SDB model.
#! /usr/bin/env jython
"""
Load a graph into a given SDB model.
"""
import glob
import sys
import os
import optparse
@lawlesst
lawlesst / sparql_unique_uri.py
Created September 21, 2012 20:09
Helper to create a random identifier for a resource via Sparql.
from SPARQLWrapper import SPARQLWrapper, JSON, N3
exists = """
SELECT *
WHERE {
OPTIONAL{<%(next_uri)s> ?p ?o}.
OPTIONAL{?s2 ?p2 <%(next_uri)s>}.
}
"""