Skip to content

Instantly share code, notes, and snippets.

View jiphex's full-sized avatar

James Hannah jiphex

View GitHub Profile
#!/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 / 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!
@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 / 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

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 / 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
@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 / stackedit.md
Created February 12, 2014 13:49
Markdown Test

Hello

Things

@jiphex
jiphex / apache-weirdness.md
Created March 24, 2014 18:45
Apache Weirdness

Apache Weirdness

Today I've spent a fairly large amount of time trying to track down a weird Apache edge-case, related to how self-referential URLs are generated. This is mostly-relevant if you're running Varnish (or any HTTP proxy really), and Apache 2.4 (although this probably affects other versions of Apache as well).

The configuration I'd normally use for Varnish/Apache is this:

[client] -> [varnish on port 80] -> [apache on high port, e.g 8080]

This normally (in my experience) works fine, and can be fairly transparent to the user.

@jiphex
jiphex / sudo-weirdness.md
Created April 16, 2014 17:10
Sudo Weirdness

Sudo Weirdness

In a continuing series of documenting weird things that I find on Linux in case I have to come back to them in the future, today I came across some weirdness when trying to do something very specific with sudo.

The [sudoers man page][sudoersman] is long and complicated, it's even mentioned in an [XKCD Comic][xkcdsudoers].

In this case, I wanted to express the following:

Users in a specified group, "managed", must be able to execute /usr/bin/git as a specific (non-root) user, "person", without specifying a password.