Skip to content

Instantly share code, notes, and snippets.

View bhuga's full-sized avatar

Ben Lavender bhuga

View GitHub Profile
# Note that as in the SIOC reference documents, the extended SIOC types
# ontology is referred to as sioc_t.
It would seem that 'reference implementations' of existing ontologies are
actually quite difficult in Spira.
sioc:topic references an RDF Resource. That Resource may optionally be a
sioc_t:Category or sioc_t:Tag. sioc_t:Category is a subclass of skos.Concept,
but sioc_t:Tag is its own thing.
@bhuga
bhuga / gist:406468
Created May 19, 2010 16:00
JRuby enumerator bug
# Demonstrates a JRuby difference with RDF enumerators
require 'rdf'
require 'rdf/ntriples'
include RDF
s = Statement.new(FOAF.age, FOAF.age, FOAF.age)
r = Repository.new
r.insert(s)
#!/usr/bin/env ruby1.9
#
$:.unshift('./lib')
require 'linkeddata/repository'
require 'spira'
repo = LinkedData::Repository.new
uri = RDF::URI('http://www.bbc.co.uk/programmes/b00jnwlc#programme')
require 'promise'
four = promise { 2 + 2 }
puts "respond_to? :odd? #{four.respond_to?(:odd?)}"
# => true
puts "respond_to? :asdfsa? #{four.respond_to?(:asdfasdf?)}"
# => false
#!/usr/bin/env ruby1.9
require 'rdf'
require 'rdf/rdfxml'
require 'rdf/ntriples'
require 'rdf/isomorphic'
s1 = %(<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
class ThreadTest
def initialize
# kicks off the thread, and only afterwards assigns thread to @t
@t = Thread.new { joiner }
end
def joiner
# without this sleep, will sometimes crash,
# as @t is not yet the thread, so will try to call @t.join on nil
I hacked up methodmissing's promise to rename it to ExtPromise. Then I edited the benchmark program like so:
require "benchmark"
require "ext/promise/promise"
require "promise"
TESTS = 1000
Benchmark.bmbm do |results|
# Picked inspect instead of undefined, as the pure-ruby promise will raise an
# exception on undefined instead of return the promise value
ben:promising-future ben$ rake bench; rake1.9 bench; jrake bench
(in /Users/ben/Repos/promising-future)
Rehearsal ----------------------------------------------------------
Nothing 0.000000 0.000000 0.000000 ( 0.004472)
Nothing(Promise) 0.010000 0.000000 0.010000 ( 0.009008)
Nothing(Future) 0.120000 0.050000 0.170000 ( 0.168207)
A method 0.000000 0.000000 0.000000 ( 0.005997)
A method(Promise) 0.010000 0.000000 0.010000 ( 0.012526)
A method(Future) 0.130000 0.040000 0.170000 ( 0.171445)
#== 0.000000 0.000000 0.000000 ( 0.004996)
@bhuga
bhuga / spira
Created October 18, 2010 10:58
first draft. Needs implementation of @setup, @teardown, @query.
#!/usr/bin/env ruby1.9
# local spira bug fix for bnode objects with Types::Any
$:.unshift '~/repos/spira/lib'
require 'spira'
require 'rdf/n3'
require 'rdf/isomorphic'
DAWG = RDF::Vocabulary.new('http://www.w3.org/2001/sw/DataAccess/tests/test-dawg#')
MF = RDF::Vocabulary.new('http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#')
QT = RDF::Vocabulary.new('http://www.w3.org/2001/sw/DataAccess/tests/test-query#')
@bhuga
bhuga / RDF.rb encoding error when fetching remote files
Created November 14, 2010 00:25
Local copy of the file works, fetching directly over remote fails. Something wrong with standard library?
root@ip-10-251-122-82:/home/lavender/spocq/src/test/rspec/tests/data-r2/i18n# curl http://tmp.datagraph.org.s3.amazonaws.com/import/33f361f0-d1b2-012d-f3cf-0023df827da6 > curl
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
113 795 113 795 0 0 47522 0 --:--:-- --:--:-- --:--:-- 56785
root@ip-10-251-122-82:/home/lavender/spocq/src/test/rspec/tests/data-r2/i18n# diff curl normalization-01.ttl
root@ip-10-251-122-82:/home/lavender/spocq/src/test/rspec/tests/data-r2/i18n# ls -al curl normalization-01.ttl
-rw-r--r-- 1 root root 795 2010-11-14 00:21 curl
-rw-r--r-- 1 lavender lavender 795 2010-10-29 05:46 normalization-01.ttl
root@ip-10-251-122-82:/home/lavender/spocq/src/test/rspec/tests/data-r2/i18n# irb1.9