Skip to content

Instantly share code, notes, and snippets.

View patrobinson's full-sized avatar

Patrick Robinson patrobinson

View GitHub Profile
@patrobinson
patrobinson / gist:7610241
Last active December 29, 2015 03:49
Mutex locking with bash
unset $LOCKED
LOCKFILE="/tmp/lockfile"
function waitlock
{
while [ -d "$LOCKFILE" ]; do
sleep 10
done
}
function lock
perl -e 'use strict; my %a; my $a; $a{"1"} = 0; $a = 1; print "$a{$a}\n$a\n";'
my $datastoreSystem = Vim::get_view(mo_ref => $host->configManager->datastoreSystem);
my @unbound = $datastoreSystem->QueryUnresolvedVmfsVolumes();
foreach my $dstore (@unbound) {
my $volume = ${$dstore}[0];
if($volume->{'vmfsLabel'} ne $vmfsLabel) {
print "Unresolved VMFS volume ".$volume->{'vmfsLabel'}." found but does not match ".$vmfsLabel."\n";
next;
}
my @extpaths;
@unbound_volumes = host.configManager.datastoreSystem.QueryUnresolvedVmfsVolumes
fail "No unresolved VMFS volumes found" if @unbound_volumes.empty?
@volume = nil
@unbound_volumes.each do |dstore|
next unless dstore.is_a? RbVmomi::VIM::HostUnresolvedVmfsVolume
# Unless this volume matches our vmfsLabel skip it
function(newDoc, oldDoc, userCtx, secObj) {
for (var field in newDoc) {
if(/^_/.test(field) == false && typeof newDoc[field] == "string") {
if(/^(\{|\[)/.test(newDoc[field])) {
throw ({forbidden : field + " field doesn't contain valid JSON:\n" + newDoc[field]});
}
}
}
}
def javascript_class_type value
class_of = lambda { |klass| value.kind_of?(klass) }
case
when class_of.call(String)
return "string"
when class_of.call(Fixnum), class_of.call(Float)
return "number"
when class_of.call(FalseClass), class_of.call(TrueClass)
return "boolean"
when class_of.call(Array)
@patrobinson
patrobinson / README.md
Created March 23, 2015 12:40
ServiceNow Dashing config

ServiceNow dashing Meter

Shows the number of results returned by a query to ServiceNow

Usage

Add the following to your Gemfile gem 'rs_service_now'

@patrobinson
patrobinson / gist:3ff278f264fdb1384a87
Last active August 29, 2015 14:18
Get Puppet 2.7 to work with Ruby 1.9
# I can't believe I'm doing this horrible hack, but Puppet 2.7 doesn't support
# Ruby versions above 1.8.7. Due to all the testing requirements
# we need to run Ruby 1.9.3. The only bug I've hit so far with Puppet 2.7
# and Ruby 1.9.3 is the lack of a "collect" method for a String
# which just needs to return an array of itself
# Turns out this is an undocumented feature in Ruby 1.8
#
# Add this to your spec_helper.rb file for use with rspec-puppet
class String
def collect
-module(chop).
-export([guess/3]).
-define(equal(Actual, Guess), Guess == Actual).
-define(lower(Actual, Guess), Guess > Actual).
guess(Actual, First, Last) ->
Guess = binary_guess(First, Last),