Skip to content

Instantly share code, notes, and snippets.

View jiphex's full-sized avatar

James Hannah jiphex

View GitHub Profile
@jiphex
jiphex / stackedit.md
Created February 12, 2014 13:49
Markdown Test

Hello

Things

@jiphex
jiphex / 00_crazy_uwsgi.md
Created February 6, 2014 13:21
00_crazy_uwsgi.md

So uwsgi is pretty crazy:

# ./bin/uwsgi --help|wc -l
857

I'm using it under runit to manage some graphite processes, the problem I was having, was that I simply couldn't get it to restart with sv t, or stop with sv d.

Turns out, this is because UWSGI's default behaviour is to "brutally reload" when it receives the TERM signal, unlike most other things you'd use under runit which would normally die.

Luckily, one of uwsgi's 857 options fixes this:

@jiphex
jiphex / instructions.md
Last active November 12, 2015 05:18
Static OpenVPN between two hosts

Static OpenVPN configuration between a single pair of hosts

So you've got two boxes, separated by some kind of network that you're not in control of, and you'd like to encrypt traffic between them. You're not going to have multiple clients connecting to each other, just these two boxes.

As of OpenVPN 2, it's possible to configure the hosts in peer-to-peer mode, with static keying, meaning that the actual VPN setup is super easy:

  1. Install OpenVPN (>=2) on both boxes, the standard Wheezy version is fine.
  2. Generate a static key as follows: openvpn --genkey --secret /path/to/somewhere/secret.key
  3. Copy the secret key to both boxes over a secure channel (e.g SSH)
  4. Create /etc/openvpn/p2p.conf on both boxes as show in box1.vpn.cnf and box2.vpn.cnf below

TBS6280 with PCTV DVB-S2 USB Stick

I've recently struggled to get the following two pieces of DVB hardware to work together on the same machine:

The instructions below apply to Debian Wheezy (7.0) with the [wheezy-backports][wb] repository enabled

The problem is this: Linux 3.2 (available from [wheezy-backports][wb]) comes with a [driver][em28xx] which works fine for the DVB-S2 USB stick, but doesn't come with any drivers at all for the TBS6280 (they

@jiphex
jiphex / apple-bluetooth-kb-f20.md
Last active August 14, 2024 18:04
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 / bigv.rb
Created September 26, 2013 11:30
CLI BigV price calculator. May not be accurate.
#!/usr/bin/env ruby1.9.1
# encoding:utf-8
#
require 'ostruct'
require 'optparse'
vm = OpenStruct.new {}
vm.memory = 1
vm.cpu = 1
@jiphex
jiphex / markall.rb
Created September 25, 2013 13:14
Mark all mail (and maildirs, recursively) as read within the given Maildir. Requires the 'maildir' gem.
#!/usr/bin/env ruby
require 'maildir'
class Maildir
def subdirectories
dirs = Dir.glob(File.join(@path,"*")).find_all{|a|File.directory?(a)}
dirs.map{|a|Maildir.new(a)}
end
def read_all!
#!/usr/bin/env ruby
DISKS = %w(/ /something /somewhere/else)
DISKS.each do |d|
(fs,blocks,used,available,cap,mount) = %x[df -P #{d}].lines.drop(1).first.split
cap = cap.to_i
puts "alert on #{fs} at #{mount} (#{cap}%)" if cap > 85
end
@jiphex
jiphex / mauvegemversion.rb
Created July 2, 2013 11:31
Send a single mauve alert about any outstanding gem updates on a host. See projects.bytemark.co.uk/projects/mauvealert
#!/usr/bin/env ruby1.8
# Alert about available gem updates
require 'mauve/sender'
require 'mauve/proto'
require 'mauve/mauve_time'
require 'rubygems'
require 'gems'
@jiphex
jiphex / sort_redirects.rb
Last active December 17, 2015 07:59
Sorts a bunch of lines like this: Redirect 301 /foo/bar http://stuff Redirect 301 /foo/bar/baz/ http://stuff in a way that means that the more-specific paths appear after the shorter ones, with some intelligence.
#!/usr/bin/env ruby1.9
# Sorts a bunch of lines like this:
# Redirect 301 /foo/bar http://stuff
# Redirect 301 /foo/bar/baz/ http://stuff
# in a way that means that the more-specific paths appear before the
# shorter ones, with some intelligence.
require 'set'
class Redirect