Skip to content

Instantly share code, notes, and snippets.

View njh's full-sized avatar

Nicholas Humfrey njh

View GitHub Profile
@njh
njh / bbc_now_next_mqtt.rb
Created February 5, 2012 23:19
Submit BBC Programme Now and Next to MQTT
#!/usr/bin/env ruby
require 'rubygems'
require 'json'
require 'net/http'
require 'uri'
require 'mqtt'
require 'pp'
NOW_NEXT_RADIO_URL = 'http://www.bbc.co.uk/iplayer/ion/multinownext/service_type/radio/format/json'
{
"artist": {
"artist_type": "Person",
"name": "Terence Trent D'Arby",
"sort_name": "D'Arby, Terence Trent",
"gid": "91f603ca-b126-42a2-9c29-820ca687347c",
"disambiguation": null,
"begin_date": "1962-03-15",
"end_date": null,
"wikipedia_article": {
@njh
njh / mqtt-eventsource.rb
Created April 14, 2012 14:09
Subscribe to MQTT messages in browser using HTML5 Server-Sent Events
#!/usr/bin/env ruby
require 'rubygems'
require 'eventmachine'
require 'em-mqtt'
require 'sinatra/base'
require 'thin'
class WebApp < Sinatra::Base
@njh
njh / create_webid_rdf.php
Created April 16, 2012 11:33
Create RDF for a WebId using EasyRdf
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . '../lib/');
require_once "EasyRdf.php";
EasyRdf_Namespace::set('cert', 'http://www.w3.org/ns/auth/cert#');
$graph = new EasyRdf_Graph();
$bob = $graph->resource('https://bob.example/profile#me', 'foaf:Person');
$bob->addLiteral('foaf:name', 'Bob');
$bob->addResource('foaf:weblog', 'http://bob.example/blog');
@njh
njh / _README.md
Last active October 5, 2019 12:06
Shell script to create a WebID certificate using OpenSSL
#!/usr/bin/perl
use strict;
open(TSV, "freebase-sameas-dbpedialite-20120424.tsv") or die "Failed to open file: $!";
my %map;
while(<TSV>) {
my ($freebase, $dbpedialite) = split(/\s+/);
@njh
njh / webid_display.php
Created July 28, 2012 14:03
Example of getting certificate for a WebId
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . '../lib/');
require_once "EasyRdf.php";
$webid = 'http://www.aelius.com/njh#me';
$graph = new EasyRdf_Graph($webid);
$graph->load();
$person = $graph->resource($webid);
@njh
njh / hddtemp-cosm.sh
Created August 13, 2012 21:41
Send hard disk temperature to cosm.com
#!/bin/sh
COSM_API_KEY="abcdefghijk"
DATASTREAM="/v2/feeds/70987/datastreams/0.csv"
hddtemp -u C -n /dev/sda | \
mosquitto_pub -d -h api.cosm.com -u "$COSM_API_KEY" -t "$DATASTREAM" -s
@njh
njh / respondto_slim.php
Created August 19, 2012 22:35
respondTo example in Slim
<?php
require 'Slim/Slim.php';
// Prepare app
$app = new Slim(array(
'negotiation.enabled' => true
));
$app->get('/books/:id:format', function ($id) use ($app) {
@njh
njh / gist:3614362
Created September 3, 2012 22:51
American Poets
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . '../lib/');
require_once "EasyRdf.php";
EasyRdf_Namespace::set('dbpedia', 'http://dbpedia.org/ontology/');
EasyRdf_Namespace::set('dbprop', 'http://dbpedia.org/property/');
$sparql = new EasyRdf_Sparql_Client('http://dbpedia.org/sparql');