Skip to content

Instantly share code, notes, and snippets.

_virsh_vm_name()
{
virsh list --all --name "${@}"
}
_virsh_vol_name()
{
virsh vol-list default | sed '1,2d' | awk '{print $1}'
}
@ccooke
ccooke / vsp
Last active August 29, 2015 14:13
A vim wrapper to automatically open files in vsplit in the correct order, passing through arguments correctly
#!/bin/bash
PARAM_OPTS=( )
function get_param_opts {
(( ${#PARAM_OPTS[@]} > 0 )) && return
PARAM_OPTS=( $( vim -h | sed -n -e '/^ *-[-a-z]* </s/ <.*$//p' ) )
}
vim_args=""
files=( )
require 'thread'
require 'marshall'
class Commit < Exception
end
class Rollback < Exception
end
class AbortTransaction < Rollback
# This is UNRELEASED code.
# There is currently no license to use it; that will come later
# This code was written while working for Betfair and will be released publicly later
require 'thread'
module MethodInterception
private
module Abominate
def replace_object new_object
raise Exception.new( "Ia! Ia! Cthulhu Fhtagn!" ) unless instance_variable_defined? "@i_know_this_is_an_abomination"
context = class << self ; self ; end
new_object.instance_variables.each do |var|
instance_variable_set( var, new_object.instance_variable_get( var ) )
end
class String
KEYWORD_REGEX = /(?:|[^%])(%\((\w+)\))/
def keyreplace! &block
while match = self.match( KEYWORD_REGEX )
offsets = match.offset( 1 )
replacement = block.call( match[2].to_sym ) || ""
self[ offsets[0] ... offsets[1] ] = replacement
@ccooke
ccooke / match_class.rb
Created July 20, 2011 17:03
A recursive function to check if source data matches a valid pattern
module Kernel
def match_class?( class_spec )
case class_spec
when Class
# A plain value
return false unless self.is_a? class_spec
when Hash
# When we expect a keyed enumerator
return false unless self.method(:each)
# A hashlike each will return two values
@ccooke
ccooke / netapp.rb
Created September 2, 2011 16:46
Fragment of Zabbix template generation for Netapps
oid ".iso.org.dod.internet.private.enterprises.netapp.netapp1" do
mib "NETWORK-APPLIANCE-MIB" # Won't be needed when we can snmpwalk directly
key "netapp.sysStat.cpu.cpuBusyTimePerCent", graph("CPU", :yaxisside => GRAPH_AXIS_RIGHT ) + trigger( :>, 60 )
key "netapp.sysStat.cpu.cpuContextSwitches", graph("CPU")
key "netapp.sysStat.cpu.cpuInterrupts", graph("CPU")
key "netapp.sysStat.cpu.cpuUpTime", trigger( :<, :lastval, :critical, "Filer has rebooted" )
key "netapp.sysStat.autosupport.autosupportFailedSends", trigger( :>, 1 )
@ccooke
ccooke / zbxprox-plugin-mysql.pl
Created October 3, 2011 10:18
Zabbix mysql plugin
# Plugin for zbxprox.pl, which is not yet released (2011-10-03)
{
'name' => "Mysql",
'config' => {
'host' => '127.0.0.1',
'user' => 'client',
'pass' => 'XXXXXXXXXXXXXXXXX',
'command' => "show status",
'cachetime' => 15
@ccooke
ccooke / MultiplexClasses.rb
Created February 29, 2012 17:20
A module to allow a class to be split into several root-level subclasses
# Define the helper functionality we'll use
module MultiplexClass
# Set up some variables...
def self.extended(base)
base.class_exec do
# The class we will take subclasses from
@_multiplex_subclass_parent = self
# A hash of the tagged subclasses createed so far