Skip to content

Instantly share code, notes, and snippets.

View beezly's full-sized avatar

Andrew Beresford beezly

View GitHub Profile
@beezly
beezly / disksnmp.rb
Created October 23, 2011 19:08
nagios plugin to read free disk space in ruby using snmp
#!/usr/bin/ruby
require 'rubygems'
require 'nagios-probe'
require 'snmp'
require 'optparse'
class NagiosDiskCheck < Nagios::Probe
attr_reader :perfdata
def initialize(opts = {})
@beezly
beezly / gist:1595352
Created January 11, 2012 16:02
Beezobot!
class Player
@@health = 0
@@direction = :forward
@@mode = :attack
def taking_damage(warrior)
@@health > warrior.health
end
def next_thingy(spaces)
@beezly
beezly / list-ownership.rb
Created January 17, 2012 16:19
List editors of shared documents
require 'rubygems'
require 'gdata'
MAX_RETRIES = 5
LOGIN_USER = "administrator@yourdomain.com"
LOGIN_PASSWORD = "administratorpassword"
# Login and use version 3 of the api (only v3 allows admin access to files)
client = GData::Client::DocList.new
@beezly
beezly / puppetlabs.repo
Created January 18, 2012 14:13
Puppet Labs Yum file
[puppetlabs]
name=Puppet Labs
baseurl=http://yum.puppetlabs.com/el/$releasever/products/$basearch
enabled=1
gpgcheck=1
gpgkey=http://yum.puppetlabs.com/RPM-GPG-KEY-puppetlabs
@beezly
beezly / gist:2470561
Created April 23, 2012 12:13
Shell script to clear up IPC where no processes are attached
for i in `ipcs -m | awk '{ print $2 }'`; do ipcs -m -i $i | grep '\snattch=0$'; if [ $? -eq 0 ]; then ipcrm -m $i; fi; done
@beezly
beezly / jsonp.patch
Created April 30, 2012 15:48
Allow Nagios v-shell to support json-p format
Index: controller.php
===================================================================
--- controller.php (revision 1931)
+++ controller.php (working copy)
@@ -56,6 +56,23 @@
header('Location: '.BASEURL);
}
+function is_valid_callback($subject)
+{
@beezly
beezly / gist:3121789
Created July 16, 2012 09:28
SHA512 crypt function
use String::Random qw(random_regex);
sub encrypt {
my $password = shift;
my $salt = random_regex('[0-9A-Za-z./]{16}');
return crypt($password,'$6$'.$salt);
}
@beezly
beezly / gist:3189207
Created July 27, 2012 17:13
Input validation for Mike
<?php
// validate our inputs
try {
// check to ensure we are passed the correct parameters
if ( empty($id) )
throw new Exception('id not defined');
if ( empty($uname) )
throw new Exception('uname not defined');
@beezly
beezly / gist:3722171
Created September 14, 2012 14:17
Monstrosity
find -type f -exec ls -E {} \; | awk '{ print $9 " " $6 " " $7 }' | awk -F/ '{ print $3 " " $2 }' | sort -n > s ; for i in `awk '{ print $1 }' < s | uniq`; do cp -p `grep "^$i" s | awk '{ print $2 " " $3 " " $4 }' | sort -n | tail -1 | awk '{ print $3 }'`/$i out/; done
@beezly
beezly / gist:3827209
Created October 3, 2012 14:28
Moustachify TrafficScript
$body = http.getResponseBody();
$newBody = string.regexsub ( $body ,
'<img([^>]+)src=([\'"])([^\'"]+)',
'<img$1src=$2http://mustachify.me/?src=http://www.shef.ac.uk/$3',
'gi' );
http.setResponseBody($newBody);