Skip to content

Instantly share code, notes, and snippets.

@beauvais
beauvais / gist:1253325
Created September 30, 2011 10:00
SPARQL for Flemish Art
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX gac: <http://data.kasabi.com/dataset/government-art-collection/schema/>
SELECT ?work ?name ?image ?page WHERE {
?subject skos:prefLabel "Flemish School".
?work dct:subject ?subject;
@beauvais
beauvais / csv-chop
Created October 18, 2011 18:35
CSV Chopping
csvFile = csv.reader(open('thing.csv', 'rU'), delimiter=',')
header = next(csvFile)
for row in csvFile:
devStatus = row[4]
address = row[14]
commercial = row[12]
comment = row[20]
industry = row[10]
@beauvais
beauvais / error.py
Created October 18, 2011 20:40
print row range
csvFile = csv.reader(open('survey.csv', 'rb'), delimiter=',')
header = next(csvFile)
for row in csvFile:
devStatus = row[4]
address = row[14]
commercial = row[12]
# note = row[20]
industry = row[10]
if row[20]:
@beauvais
beauvais / csv.py
Created October 20, 2011 23:16
Python for tagging in CSV
# assign variable to a csv file read by csv.reader
csvFile = csv.reader(open('/Users/Zach/Desktop/survey.csv', 'rb'), delimiter=',')
# identify header row
header = next(csvFile)
# loop rows in csv file, and identify variables for fields
for row in csvFile:
if row[20] < 0:
continue
@beauvais
beauvais / sparql.txt
Created October 28, 2011 13:09
SPARQL to find winning parties
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX def: <http://data.kasabi.com/dataset/european-election-results/def/>
PREFIX cube: <http://purl.org/linked-data/cube#dataset>
Select ?label
WHERE {
?subject rdfs:label ?label ;
?p <http://data.kasabi.com/dataset/european-election-results/2009/political_groups/seats_won> .
}
@beauvais
beauvais / iced-tea
Created December 9, 2011 16:45
foodista cocktail
@prefix dcterm: <http://purl.org/dc/terms/> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix ns1: <http://linkedrecipes.org/schema/> .
<http://data.kasabi.com/dataset/foodista/recipe/3QWJPYHF> a <http://linkedrecipes.org/schema/Recipe>;
ns1:ingredient <http://data.kasabi.com/dataset/foodista/food/DSVFF8DN>,
<http://data.kasabi.com/dataset/foodista/food/FBPQ4456>,
<http://data.kasabi.com/dataset/foodista/food/HSBJL3L8>,
<http://data.kasabi.com/dataset/foodista/food/JGYY7HZX>,
<http://data.kasabi.com/dataset/foodista/food/N5VJMXRC>,
@beauvais
beauvais / crab-recipes.txt
Created February 10, 2012 17:08
Crab Recipes in Kasabi's Food dataset
Sample SPARQL query to find Crab Recipes in Kasabi's [food](http://kasabi.com/dataset/food) dataset.
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX recipe: <http://linkedrecipes.org/schema/>
SELECT ?label ?recipe WHERE {
<http://data.kasabi.com/dataset/food/foods/crab> recipe:ingredient_of ?recipe .
?recipe a recipe:Recipe .
?recipe rdfs:label ?label .
@beauvais
beauvais / gist:1901080
Created February 24, 2012 13:55
partial email match
#! /usr/bin/python
import sys
import csv
import re
csv.writer(open('out.csv', 'wb'),).writerows(row for row in csv.reader(open('in.csv', 'rb')) if len(row) >= 6 and "gmail" in row[5])
@beauvais
beauvais / gist:1924661
Created February 27, 2012 15:28
Python CSV error
16. header = next(csvFile)
line 16, in <module>
header = next(csvFile)
_csv.Error: new-line character seen in unquoted field - do you need to open the file in universal-newline mode?
@beauvais
beauvais / gist:4089103
Created November 16, 2012 17:14
clippings_and_highlights
Dive Into Python (Mark Pilgrim)
- Highlight on Page 11 | Loc. 218-19 | Added on Monday, June 13, 2011, 09:54 PM
You KNOW HOW OTHER books go on and on about programming fundamentals, and finally work up to building a complete, working program? Let's skip all that.
==========
Dive Into Python (Mark Pilgrim)
- Note on Page 11 | Loc. 219 | Added on Monday, June 13, 2011, 09:54 PM
Often love this approach to learning, but appreciate context too.