Skip to content

Instantly share code, notes, and snippets.

View jiphex's full-sized avatar

James Hannah jiphex

View GitHub Profile
@jiphex
jiphex / backup_mysql.sh
Created August 3, 2011 09:23
Remote MySQLdump backup with Rsync driver
#! /bin/bash
# script to backup MySQL data to remote server
# James Hannah - January 2009
# set some variables
FILENAME="`date +mysqldump-%Y-%m-%d-%H:%M:%S`.sql"
LOCALFILE="/home/sql_backup/$FILENAME"
LOCKFILE="/tmp/sqlbackup.lock"
BACKUPSERVER="10.1.1.1"
MYSQLPASS="secretsgohere"
@jiphex
jiphex / apple-bluetooth-kb-f20.md
Last active February 14, 2023 13:58
Pairing an Apple Bluetooth keyboard with Fedora 20

For some reason, this didn't work with the standard GUI bluetooth tools, so I did the following

  1. Run the command-line bluetoothctl tool
  2. type "agent on"
  3. type "scan on"
  4. press the button on your keyboard, the light should flash if it's not paired with anything else
  5. type "devices" (this shows the list of devices)
  6. type "trust xxxx" where xxxx is the keyboard MAC
  7. type "connect xxxx" where xxxx is the keyboard MAC
  8. type "pair xxxx" where xxxx is the keyboard MAC
@jiphex
jiphex / README.md
Last active January 27, 2023 12:05

Running a script/service when a filesystem is mounted

I recently discovered how to do this for a JASMIN thing, and figured it may be useful.

Scenario

I would like this script/binary to be run automatically whenever a certain filesystem is mounted.

Use cases:

  • You want a quotacheck to be run to create the aquota.user file every time a tmpfs is mounted
  • You want to do something to a block device before it is mounted (e.g mkfs, fsck, unlock with some encryption key)
package main
import (
"context"
"fmt"
"net"
"os"
"time"
log "github.com/sirupsen/logrus"

IPv6-only LAN with OpenBSD

My ISP provides IPv6 for their home broadband networks, soon other ISPs will too (notably BT who are running a trial of it at the moment). Unless they do it in some insane way, this means that every broadband subscriber will be allocated a /64 of IPv6 space to do with as they please.

The normal way to use this is to "dual-stack" your network, keeping DHCPv4 to hand out NAT-ed RFC1918 addresses to your machines while also using SLAAC to advertise your IPv6 prefix from the router so that machines on the network can autoconfigure themselves an IPv6 address.

If you only want to access IPv6 sites from networked machines, you can disable DHCPv4 altogether on your network, and subject to some caveats[1] your machines will work just fine when they access sites with working AAAA records (such as Facebook and Google).

The problem comes when your machines try and access websites which don't have AAAA records - these will just display a browser error.

@jiphex
jiphex / purge.rb
Created November 14, 2011 10:13
Ruby Varnish Purge Script
#!/usr/bin/env ruby
# Ruby varnish purger
require 'net/http'
module Net
class HTTP::Purge < HTTPRequest
METHOD='PURGE'
REQUEST_HAS_BODY = false
RESPONSE_HAS_BODY = true
@jiphex
jiphex / bashrc.sh
Created November 24, 2008 20:27
My bash/vim/git environment
#! /bin/bash
# James Hannah - Bash Prompt.
# If no prompt, quit here.
[ -z "$PS1" ] && exit
# Get the important things sorted first
export EDITOR=vim
# Lets define some colors
@jiphex
jiphex / harwellbus.rb
Created May 14, 2018 12:45
Harwell campus bus stop live departures for CLI
#!/usr/bin/env ruby
require 'net/http'
require 'json'
u = URI('https://fcc.transportapi.com/v3/uk/bus/stop/340000368SHE/live.json?group=no&nextbuses=yes')
res = Net::HTTP.get(u)
b = JSON.load(res)
fs = "%4s %-18s %5s"
h = fs % %w(Bus Towards Time)
puts h
@jiphex
jiphex / upgdiff.rb
Created July 10, 2012 13:36
CentOS Yum Upgrade Diff script
# upgdiff.rb
#
# Prints the change in versions that will happen if "yum upgrade" is
# run on this CentOS/RHEL server, and if any of the upgrades will come
# from third party repositories.
#
# For example:
#
# [root@server] $ ruby upgdiff.rb
# yum-utils: 1.1.16-14.el5.centos.1 ==> 1.1.16-21.el5.centos
@jiphex
jiphex / 123reg2tinydns.rb
Last active February 21, 2017 16:39
123reg to TinyDNS converter
require 'ipaddr'
require 'ostruct'
require 'json'
require 'pp'
data = JSON.load(STDIN)["json"]
ZONE = data['dns']['zone']
STDERR.puts "DNS 123REG BS for [#{ZONE}]"
exit if ZONE.nil?
def ttl(rec)