Skip to content

Instantly share code, notes, and snippets.

View dsample's full-sized avatar

Duncan Sample dsample

View GitHub Profile
import os
import pygame
import time
import random
class pyscope :
screen = None;
def __init__(self):
"Ininitializes a new pygame screen using the framebuffer"
@dsample
dsample / README.md
Created November 16, 2016 12:08
A JavaScript snippet to help 'leave' many repositories where you have been added as a contributor

I got added as a contributor in ~400 repositories in my organisation by accident. This JavaScript helped me undo that problem. Just head over to https://github.com/settings/repositories, change the logic for which repositories you want to leave and then run the leaveOne as many times as necessary.

@dsample
dsample / README.md
Created August 11, 2016 18:54
Node-RED Flows

These Node-RED snippets accompany a blog post I wrote about using Docker and Node-RED on a Raspberry Pi to integrate IoT devices.

@dsample
dsample / progress.html
Created February 7, 2016 21:43
A simple countdown timer with progress bar. We used it to show the progress of our pregnancy.
<div class="progress" style="border: 1px solid #999">
<div id="progress-bar" style="border-right: ; background-color: #96f; height: 10px; width: 0%"></div>
</div>
<div id="countdown"></div>
<script type="text/javascript">
function getDaysRemaining(endtime){
var t = Date.parse(endtime) - Date.parse(new Date());
var days = Math.floor( t/(1000*60*60*24) );
return days;
@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.

@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 / 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 / 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 / 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 / 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.