This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Sample code to traverse RDF list with RDFLIB. | |
author: Manuel Salvadores (msalvadores@gmail.com) | |
rdf containers are a pain in general, quite annoying to handle them. | |
To get all the authors for a given article like in your case you could do | |
something like the code I am posting below. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
author: Manuel Salvadores (msalvadores@gmail.com) | |
Code sample in answer from Stack Overflow: | |
http://stackoverflow.com/questions/5289189/how-to-change-tag-name-with-beautifulsoup/5289523#5289523 | |
""" | |
import BeautifulSoup | |
if __name__ == "__main__": | |
data = """ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" author: Manuel Salvadores http://msalvadores.me " | |
" My notes on using git/github " | |
#---- workflow on remote public forked repositories ---- | |
#checkouts master branch from a forked github repo | |
git clone <git path to my forked repo> | |
#adds origin for futures merges/pulls | |
git remote add <name_origin> <git path to original repo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import urllib,urllib2 | |
import traceback | |
import pdb | |
import time | |
import json | |
import os | |
def query(q,epr,f='text/plain'): | |
params = {'query': q} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import timeit | |
DATA = 'abcdef' | |
def bytearr(): | |
bytesn = 1024 * 1024 * 5 | |
s = bytearray(bytesn) | |
i = 0 | |
while i < bytesn: | |
s[i] = DATA[i%len(DATA)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'pry' | |
module Test | |
module Settings | |
def self.included(base) | |
base.extend(ClassMethods) | |
end | |
module ClassMethods | |
attr_accessor :settings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public ResultSet executeQuery(String queryString) throws Exception { | |
Query query = QueryFactory.create(queryString) ; | |
QueryEngineHTTP qexec = QueryExecutionFactory.createServiceRequest(this.service, query) | |
qexec.addParam("apikey", this.apikey) | |
ResultSet results = qexec.execSelect() ; | |
return results; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json,urllib2,urllib,traceback, sys | |
def query(q,apikey,epr,f='application/json'): | |
try: | |
params = {'query': q, 'apikey': apikey} | |
params = urllib.urlencode(params) | |
opener = urllib2.build_opener(urllib2.HTTPHandler) | |
request = urllib2.Request(epr+'?'+params) | |
request.add_header('Accept', f) | |
request.get_method = lambda: 'GET' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package test; | |
import java.io.PrintStream; | |
public class TestOutput { | |
public static void outputFiltered(String label, PrintStream out) { | |
for (byte b : label.getBytes()) { | |
if (Character.isLetterOrDigit((char)b)) { | |
out.print((char)b); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import urllib2 | |
import urllib | |
import traceback | |
import sys | |
def query(q,apikey,epr,f='application/json'): | |
"""Function that uses urllib/urllib2 to issue a SPARQL query. | |
By default it requests json as data format for the SPARQL resultset""" |
NewerOlder