Skip to content

Instantly share code, notes, and snippets.

View jiphex's full-sized avatar

James Hannah jiphex

View GitHub Profile
### 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:
@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
@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 / 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 / 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 / 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
package main
import (
"context"
"fmt"
"net"
"os"
"time"
log "github.com/sirupsen/logrus"
@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)