Skip to content

Instantly share code, notes, and snippets.

View dsample's full-sized avatar

Duncan Sample dsample

View GitHub Profile
CmdUtils.CreateCommand({
name: "magicious",
takes: {"tags": noun_arb_text},
homepage: "http://www.sample.me.uk/ubiquity/",
author: { name: "Duncan Sample" },
description: "Adds the current page to both Delicious and Magnolia",
help: "To run this you will first need to set the credentials by Ubiq'ing magicious-credentials. Then simply Ubiq magicious with the tags you want to save",
license: "MPL",
preview: function( pblock ) {
var doc = Application.activeWindow.activeTab.document;
CmdUtils.CreateCommand({
name: "mobilecode",
homepage: "http://mobib.org/",
author: { name: "Duncan Sample" },
description: "Shows a mobile code for the current page.",
license: "MPL",
preview: function( pblock ) {
var document = context.focusedWindow.document;
var style = Application.prefs.getValue("mobilebarcode.style", "QR");
var size = Application.prefs.getValue("mobilebarcode.size", "M");
@dsample
dsample / jaikubackup.php
Created January 1, 2012 14:28
A backup script for Jaiku.
<?php
# Username you want to download the posts for (eg. 'dsample')
$username = '';
# Login information taken from browser cookies - NOT YOUR PLAINTEXT PASSWORD
$jaikuuser = ''; #eg. 'dsample@jaiku.com'
$jaikupassword = ''; #will look random like 'asdfasdfasdfasdfasdfasdfasdfasdf'
# Number of pages of post listings to scrape (0 for all)
@dsample
dsample / android_xml_to_po.rb
Last active December 17, 2015 13:19
A converter from Android's strings.xml to gettext PO format for use with online translation services like PO Editor and Launchpad. Store it in a directory within your Android project. It will output a strings_<locale>.po file. You can store 'context' information (to help translators) in a YAML file with the string names as keys and context descr…
#!/usr/bin/ruby
require 'nokogiri'
require 'fileutils'
require 'yaml'
require 'optparse'
@PROJECT_ID_VERSION = 'ttrscoreboard-android'
@REPORT_MSGID_BUGS_TO = '' # Where to report (A URL or email address)
@dsample
dsample / README.md
Created January 31, 2014 01:18
Simple WebSocket event mirror

This is a simple WebSockets app which demostrates how an event could be sent from one browser to another device's browser.

The code was adapted from Martyn Loughran's em-websocket tutorial article http://rubylearning.com/blog/2010/10/01/an-introduction-to-eventmachine-and-how-to-avoid-callback-spaghetti/ which was published as a Gist https://gist.github.com/mloughran/604404

The idea would be to eventually make it into a snippet which could be launched from a browser bookmarklet to add synchronisation between browsers on all kinds of devices.

@dsample
dsample / espruino_coloured_lights.js
Created February 21, 2014 00:31
A set of patterns for the Espruino to use a WS2811 RGB LED strips which change with the press of the on-board button. Defaulted to connect to pin B15 and 50 LEDs
/*var sensor = require("HC-SR04").connect(C6,C7,function(dist) {
console.log(dist+" cm away");
});
setInterval(function() {
sensor.trigger(); // send pulse
}, 500);
*/
SPI2.setup({baud:3200000, mosi:B15});
var rgb = new Uint8Array(50*3);
@dsample
dsample / download_gems.rb
Last active August 29, 2015 13:57
Downloads the gem files for the given gem, along with all of it's dependencies
require 'net/http'
require 'json'
require 'fileutils'
HTTP_PROXY = URI 'http://proxy:80'
DOWNLOAD_DIRECTORY = 'gems'
def http_connection(host, port, use_ssl, &block)
proxy_connection = Net::HTTP::Proxy(HTTP_PROXY.host, HTTP_PROXY.port)
@dsample
dsample / 2010_uk_general_elections.json
Last active July 4, 2016 21:33
How might the 2010 UK General Election results have looked if we had been using the D'Hondt method of calculating seat allocation.
{
"Wales": {
"population": 2265125,
"constituencies": [
"Aberavon",
"Aberconwy",
"Alyn & Deeside",
"Arfon",
"Blaenau Gwent",
"Brecon & Radnorshire",
@dsample
dsample / server.rb
Last active August 29, 2015 14:28
A few examples of loading data from an external server using JavaScript. The sinatra script is intended to be run as two websites. http://example.com and http://example.net. The client on http://example.com is trying to load a resource from http://example.net. Not all of these approaches work successfully.
#!/usr/bin/env ruby
require 'sinatra'
require 'json'
# set :bind, 'example.com'
set :port, '80'
get '/data.jsonp' do
headers 'Access-Control-Allow-Origin' => 'http://example.com'
@dsample
dsample / docker_install_scripts.md
Last active May 19, 2017 13:51
Install Docker on Mac OS X from binaries rather than the Docker Toolbox. Prerequisite: jq

These scripts will help you install Docker, Docker Compose, and Docker Machine.

Make sure you have jq available first.