Skip to content

Instantly share code, notes, and snippets.

@tomgidden
tomgidden / .gitignore
Last active December 27, 2016 19:02
Control 433MHz mains switches from an ESP8266 (with 433MHz Tx board) via MQTT, using Arduino
config.h
@tomgidden
tomgidden / pressure_mat_1.js
Last active December 17, 2016 14:59
Espruino test code for Velostat + copper based mat (i-Mattress-Sens-U-Pedic 2000)
var ipins = [A3, A4, A5];
var opins = [B2, B3, B4];
var xs = opins.length;
var ys = ipins.length;
function readCol(x) {
var j, k, res=[];
// First, set the column lines to either +3.3V or "pin open circuit"
@tomgidden
tomgidden / milosmells.php
Last active November 2, 2016 21:26
Who is Milo, and what does he smell of?
<?php
// This demonstrates a quirk of the Slack API, whereby uploading a post containing ' - '
// will insert the string `milosmells14159fb1f6f04f8f98297f08f96d2c1ba1317a5e`
//
// Who is Milo, and what does he smell of?
// Fill in a valid Slack API token below.
$params = [
@tomgidden
tomgidden / Benchmark PHP iterator, foreach, array_walk.README.md
Last active March 19, 2019 15:12
PHP benchmark foreach / Iterator / array_walk for transformation of array

This benchmarks transformation of a large array (many members):

  1. Use foreach to construct a static transformed array
  2. Use an Iterator to transform dynamically on-the-fly
  3. Use array_walk to construct a static transformed array

Results:

The naive "foreach" loop is fastest.

@tomgidden
tomgidden / README
Last active January 15, 2021 16:00
Adafruit Bluefruit LE Micro iOS control for iBooks
To control iBooks, you can activate VoiceOver, mute it (as you don't actually want voice),
select the page progress bar, and then use up/down keyboard buttons.
You can set Settings→General→Accessibility→Accessibility Shortcut = VoiceOver to set
triple-click of Home to (de-)activate VoiceOver.
AT+BLEHIDCONTROLKEY=0x0223 # Sends iOS Home button
AT+BLEHIDCONTROLKEY=0x30 # Sends iOS Power button
AT+BLEHIDCONTROLKEY=0xb8 # Sends iOS Show Keyboard (Eject)
AT+BLEHIDCONTROLKEY=0xb0 # Sends iOS Play
@tomgidden
tomgidden / jmysql
Last active November 17, 2015 14:26
Invoke `mysql` command using parameters from Joomla configuration.php
#!/bin/bash
YELLOW="\033[1;33m"
GREEN="\033[1;32m"
RED="\033[1;31m"
NO_COLOUR="\033[0m"
DIR=$PWD
FN=
@tomgidden
tomgidden / KingpulRH216C.pm
Created October 15, 2015 11:42
Perl driver for Kingpul RH216C scrolling LED sign
package MessageSign::KingpulRH216C;
use vars qw($VERSION);
($VERSION) = '$Revisioning$' =~ /\$Revisioning:\s+([^\s]+)/;
@ISA = qw( Exporter );
use POSIX qw|strftime|;
use strict;
@tomgidden
tomgidden / jasper-setup.sh
Last active September 18, 2015 08:41 — forked from vampjaz/jasper-setup.sh
Automatic setup and install of Jasper (http://jasperproject.github.io/)
#!/bin/bash
# Jasper install script (http://jasperproject.github.io/)
# Must be run as root (i.e. sudo setup.sh)
apt-get update
apt-get upgrade --yes
apt-get install vim git-core espeak python-dev python-pip bison libasound2-dev libportaudio-dev python-pyaudio subversion autoconf libtool automake gfortran --yes
sed "s/options snd-usb-audio index=-2/options snd-usb-audio index=0" /etc/modprobe.d/alsa-base.conf>/etc/modprobe.d/alsa-base.conf
@tomgidden
tomgidden / add_joomla_superuser
Created September 15, 2015 14:15
Dependency-free PHP script to add users to Joomla via the database
#!/usr/bin/env php
<?php
// Add Super User to Joomla database.
// Execute './add_joomla_superuser' with no parameters for help.
//
// Thrown together by Tom Gidden <[email protected]> to scratch an itch.
//
// Yes, it could all be done via code in Joomla, but this is meant to be
// relatively dependency-free. We've got loads of Joomla sites using a
@tomgidden
tomgidden / wsrep_notify_slack
Created February 25, 2015 21:32
Send wsrep / galera notifications for mysql clusters to a slack.com webhook
#!/usr/bin/env python
# configure this in my.cnf on a Galera-based MySQL-alike server:
# wsrep_notify_cmd=/usr/local/sbin/wsrep_notify_slack
# by Tom Gidden <[email protected]>
url = 'https://hooks.slack.com/services/XXXXXXX/XXXXXXXX/XXXXXXXX'
import argparse