Skip to content

Instantly share code, notes, and snippets.

View abrisse's full-sized avatar

Aymeric Brisse abrisse

View GitHub Profile
@abrisse
abrisse / process.rb
Created December 2, 2021 11:35
Ruby RDF SPARQL Generator
require 'sparql'
module RDF
class Literal
##
# Returns the object SPARQL representation
#
# @param [Hash{Symbol => Object}] options ({})
# options passed for the generation
# @return [String]
@abrisse
abrisse / gist:8315484
Created January 8, 2014 11:29
Bunny Thread Problem
BUNNY = Bunny.new
BUNNY.start
def run
ch = BUNNY.create_channel
exchange = ch.exchange('osb.modules', :type => :topic, :durable => true)
ch.close
end
t = []
# --------------------------------------------------------
# Rendering of a single view
# --------------------------------------------------------
# users/show.rabl
object :@user
condition(->(user) { true }) do
node(:xx) do
@abrisse
abrisse / gist:5271364
Created March 29, 2013 14:58
Extract Instruments from Freebase using the 'freebase-api' gem
require 'freebase-api'
FreebaseAPI.session = FreebaseAPI::Session.new(:env => :sandbox, :key => 'FREEBASE_KEY', :query_options => { :lang => :fr })
FreebaseAPI.logger.level = Logger::UNKNOWN
instruments = FreebaseAPI.session.mqlread([{
:type => '/music/instrument',
:id => nil,
:name => nil
}])
require 'rdf'
result = RDF::NTriples::Reader.new('<http://dbpedia.org/resource/Fitch_Ratings2> <http://dbpedia.org/ontology/wikiPageRedirects2> <http://dbpedia.org/resource/Fitch_Group2>')
if result.count > 0
puts result.statements.first.nil? # displays false
end
result.rewind
@abrisse
abrisse / gist:3003094
Created June 27, 2012 10:04
amq-protocol encode_properties should not try to encode nil values
def self.encode_properties(body_size, properties)
pieces, flags = [], 0
properties.each do |key, value|
if value
i, f, result = self.send(:"encode_#{key}", value)
flags |= f
pieces[i] = result
end
end
module Transport
# Common transport layer for http transfers.
class HTTP
# Builder for the http transport layer requests.
class RequestBuilder
def initialize_request_path
uri = URI.parse @url
module Spira::Types
##
# A {Spira::Type} for integer values. Values will be associated with the
# `XSD.integer` type.
#
# A {Spira::Resource} property can reference this type as
# `Spira::Types::Integer`, `Integer`, or `XSD.integer`.
#
# @see Spira::Type