Skip to content

Instantly share code, notes, and snippets.

View patrobinson's full-sized avatar

Patrick Robinson patrobinson

View GitHub Profile
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)
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]});
}
}
}
}
@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
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;
perl -e 'use strict; my %a; my $a; $a{"1"} = 0; $a = 1; print "$a{$a}\n$a\n";'
@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