Skip to content

Instantly share code, notes, and snippets.

View jiphex's full-sized avatar

James Hannah jiphex

View GitHub Profile
@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"
@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 / 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)
@jiphex
jiphex / 0-symbiosis-with-github.com_hlandau_acme.md
Last active April 21, 2016 08:58
Symbiosis with github.com/hlandau/acme

Instructions for using github.com/hlandau/acme with Symbiosis

  • Install the binary from the repo
  • Run acmetool quickstart, choose the Proxy option, and enable the cronjob
  • Add this line after the <VirtualHost...:80 stanzas in the config files in /etc/symbiosis/apache.d: ProxyPass "/.well-known/acme-challenge" "http://127.0.0.1:402/.well-known/acme-challenge"
  • Enable apache mod_proxy - a2enmod proxy_http
  • Copy the attached hook into /usr/lib/acme/hooks and make it executable
  • Run acmetool want domain.tld www.domain.tld for any domains you want to be secured
@jiphex
jiphex / generators.py
Last active November 5, 2015 10:50
How Python generators work
def x(items):
print('before loop')
for x in items:
print ('before yield')
yield "xx %s yy" % x
print('after yield')
print('after loop')
for i in x(list((1,2,3,4))):
print "zz %s aa" % i
@jiphex
jiphex / [email protected]
Last active September 7, 2015 15:09
Systemd unit for lxc (e.g systemctl start lxc@containername)
[Unit]
Description=LXC %i
Requires=lxc.service
[Service]
ExecStart=/usr/bin/lxc-start --name=%i
ExecStop=/usr/bin/lxc-stop --name=%i
[Install]
WantedBy=multi-user.target
### Keybase proof
I hereby claim:
* I am jiphex on github.
* I am jiphex (https://keybase.io/jiphex) on keybase.
* I have a public key whose fingerprint is AA0D 95BB B25B 595A 14B9 6906 25E1 4B9F 86A2 49D4
To claim this, I am signing this object:

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 / README.md
Last active August 29, 2015 14:23
OpenBSD Battery widget for awesome 3.5

Include this in your ~/.config/awesome/rc.lua file and then add the widget at the same place you add your clock.

Output is like 69%[123] - the number in the square brackets is the minutes remaining (or ??)

Colour will be green if charging, white if battery is high, yellow if low or red if critical.