Skip to content

Instantly share code, notes, and snippets.

View jamesdavidson's full-sized avatar

James Davidson jamesdavidson

View GitHub Profile
@jamesdavidson
jamesdavidson / queue.c
Last active August 29, 2015 14:18
A queue of integer values, implemented as a linked-list.
// A queue of integer values, implemented as a linked-list.
// Careful, don't pop the queue if it's empty!
// Copyright (c) James Davidson 2015.
// Publicly released under the terms of the MIT License.
// For educational purposes only, obviously; no warranty implied.
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>
@jamesdavidson
jamesdavidson / euclids.hs
Created April 18, 2015 06:34
Euclid's algorithm
-- Euclid's algorithm for calculating the greatest-common-divisor.
gcd :: Integer -> Integer -> Integer
gcd x y =
if r == 0 then y else (gcd y r)
where r = (mod x y)
/*
Software serial multple serial test
Receives from the hardware serial, sends to software serial.
Receives from software serial, sends to hardware serial.
The circuit:
* RX is digital pin 2 (connect to TX of other device)
* TX is digital pin 3 (connect to RX of other device)
@jamesdavidson
jamesdavidson / pom.xml
Created April 19, 2016 08:30
Removing extraneous artifacts from the Java SDK for AWS
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>example.lambda</groupId>
<artifactId>jisho-b36491</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>jisho-b36491</name>
<url>http://maven.apache.org</url>
<dependencies>
@jamesdavidson
jamesdavidson / MYSQL.txt
Last active January 4, 2019 03:51
Notes from automating the installation of MySQL on CentOS.
So, what did I try?
Well, first I tried to find a CMS that didn't need MySQL. Painful.
Then, I tried installing MySQL. They have made this very hard to
automate.
Then, I tried running MySQL in a Docker container. The first annoying
thing here was that I needed a specific version of Docker's API but that
also meant a specific version of the Python library and adding
@jamesdavidson
jamesdavidson / wowza.pp
Created April 6, 2018 05:37
Puppet code to configure Nginx to proxy Wowza and SHOUTcast streams.
# install and configure Wowza Streaming Engine
class profile::wowza {
# Placeholder to install Wowza Streaming Engine (WowzaStreamingEngine-4.7.1-linux-x64-installer.run)
$config = hiera('wowza')
$audio_upstream = 'http://localhost:1935'
$wowza_upstream = 'http://localhost:8088'
$shoutcast_upstream = 'http://localhost:8000'
# The following URLs are for management:
@jamesdavidson
jamesdavidson / asdf.tf
Created May 2, 2018 06:39
Experimental job queue system
variable jobnumber {
default = "201802061831"
}
provider aws {
region = "ap-southeast-2"
}
resource aws_sqs_queue asdf {
receive_wait_time_seconds = 20 # enable long polling by default
@jamesdavidson
jamesdavidson / subtract.py
Created May 2, 2018 06:42
Subtracts one list of address ranges from another list of ranges, returning a list of addresses as /32 ranges.
#!/usr/bin/env python
# This program requires two filename arguments. Each file should contain a list
# of address ranges (CIDR blocks). The output will be a list of address which
# are in the first list but not the second expressed as /32 ranges.
from __future__ import unicode_literals
import sys
import ipaddress
@jamesdavidson
jamesdavidson / tls_connect.js
Last active February 19, 2019 06:34
Open a TLS connection to a remote host on and verify its cert.
/* Open a TLS connection to a remote host and verify its cert.
* Usage: node tls_connect.js -connect thewest.com.au:443
*/
var tls = require('tls');
var i = process.argv.indexOf('-connect');
var connect = process.argv[1+i].split(':');
var servername = connect[0];
var port = Number(connect[1]);
if (0 < i && connect && servername && port) {
@jamesdavidson
jamesdavidson / convenient_temporary_credentials_20180823.tf
Created August 23, 2018 13:43
Terraform code to set up a convenient and secure way to get temporary credentials for AWS.
// ## Goal
//
// A convenient and secure way to get temporary credentials for AWS which I can use
// with Terraform or the Python CLI. Sort of like `saml2aws` but in the browser.
//
// ## Implementation
//
// A client-side JS app which uses Cognito and IAM resources as the backend.
//
// 1) Open the app