Skip to content

Instantly share code, notes, and snippets.

@lawlesst
lawlesst / ldapBackEnd.py
Created October 19, 2010 23:56
For connecting Django auth to LDAP.
"""
Add below to settings.py
AUTHENTICATION_BACKENDS = (
'ldapBackend.LDAPBackend',
'django.contrib.auth.backends.ModelBackend',
)
Requires python-ldap
@lawlesst
lawlesst / VIVO SPARQL Update API
Last active August 30, 2018 20:05
Example of using SPARQLWrapper to update data in VIVO .
Sample scripts for using the VIVO SPARQL Update API in PHP, Python.
https://wiki.duraspace.org/display/VIVO/The+SPARQL+Update+API
@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 / export_vivo.py
Last active February 7, 2018 09:30
Jython script to connect to VIVO via SDB and export a model.
"""
Jython script to connect to VIVO via SDB and export a model.
Requires Jython 2.5 or later. Download from: http://www.jython.org/downloads.html
Assumes the VIVO harvester is on your path.
- change the database connection information to point to your VIVO database.
- change the model name to specify the VIVO model you would like to export.
- change the output_file name to the location where you want to save the RDF.
- for larger models you will want to increase the memory available to Java.
@lawlesst
lawlesst / generate_listview.py
Last active August 11, 2017 17:39
A Python script to parse VIVO list view config XML files and issue SPARQL queries contained within them.
"""
Utility script to parse VIVO listViewConfig.xml files.
Requires
- rdflib_sparql
- SPARQLWrapper
Run as
$ python generate_listview.py /path/to/listViewConfig-awardOrHonor.xml
@lawlesst
lawlesst / vivordfalchemy.py
Last active June 29, 2017 19:05
Reading and writing RDF for VIVO using RDFAlchemy.
import csv
from pprint import pprint
import urllib
from rdflib import Namespace
from rdfalchemy import rdfSingle
from rdfalchemy.rdfSubject import rdfSubject
from rdflib import Literal, BNode, Namespace, URIRef
from rdflib import RDF, RDFS, Graph, OWL
@lawlesst
lawlesst / top10_by_language_pages.csv
Last active October 17, 2016 02:40
baseball and wikidata fame
We can make this file beautiful and searchable if this error is corrected: It looks like row 10 should actually have 5 columns, instead of 4. in line 9.
name,pages,rank,wikidata,baseball_ref
Babe Ruth,55,1,http://www.wikidata.org/entity/Q213812,http://www.baseball-reference.com/players/r/ruthba01.shtml
Ichiro Suzuki,52,2,http://www.wikidata.org/entity/Q600,http://www.baseball-reference.com/players/s/suzukic01.shtml
Yogi Berra,46,3,http://www.wikidata.org/entity/Q367566,http://www.baseball-reference.com/players/b/berrayo01.shtml
Jackie Robinson,42,4,http://www.wikidata.org/entity/Q221048,http://www.baseball-reference.com/players/r/robinja02.shtml
Joe DiMaggio,40,5,http://www.wikidata.org/entity/Q297142,http://www.baseball-reference.com/players/d/dimagjo01.shtml
Jim Thorpe,39,6,http://www.wikidata.org/entity/Q221482,http://www.baseball-reference.com/players/t/thorpji01.shtml
Hank Aaron,36,7,http://www.wikidata.org/entity/Q215777,http://www.baseball-reference.com/players/a/aaronha01.shtml
Mickey Mantle,30,8,http://www.wikidata.org/entity/Q345004,http://www.baseball-reference.com/players/m/mantlmi01.shtml
Alex Rodriguez,29,9,http://www.wikidata.org/entity/Q558664
@lawlesst
lawlesst / incites_batch_lookup.py
Last active October 6, 2016 18:59
Lookup UTs in AMR and output to CSV.
"""
Look up batches of UTs in InCites.
Run as:
$ python incites_batch_lookup.py sample_file.csv outputfile.csv
"""
import csv
@lawlesst
lawlesst / vivo-sparql-datasource-config.json
Last active August 17, 2016 17:58
Config for LDF Server VivoSparqlDatasource
{
"title": "Linked Data Fragments server",
"datasources": {
"local-vivo": {
"title": "VIVO",
"type": "VivoSparqlDatasource",
"description": "local VIVO",
"settings": {
"endpoint": "http://localhost:8080/vivo/api/sparqlQuery",
@lawlesst
lawlesst / amr.xml
Last active August 15, 2016 15:10
Sample call and response for Links AMR web service
<?xml version="1.0" encoding="UTF-8" ?>
<request xmlns="http://www.isinet.com/xrpc41" src="app.id=InternalVIVODemo">
<fn name="LinksAMR.retrieve">
<list>
<!-- authentication -->
<map>
<val name="username">xxx</val>
<val name="password">xxx</val>
</map>
<!-- what to to return -->