This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Timer { | |
def time[R](block: => R): Pair[Long,_] = { | |
val t0 = System.nanoTime() | |
val result = block | |
val diff = System.nanoTime() - t0 | |
// Post-timing processing can be added here, maybe | |
// an optional argument to this method? | |
Pair(diff, result) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> for(masked <- 0 until 8) { println("Bits: 0xff & masked bits (" + masked + ") => " + (256 - (255 & (1 << masked)))) } | |
Bits: 0xff & masked bits (0) => 255 | |
Bits: 0xff & masked bits (1) => 254 | |
Bits: 0xff & masked bits (2) => 252 | |
Bits: 0xff & masked bits (3) => 248 | |
Bits: 0xff & masked bits (4) => 240 | |
Bits: 0xff & masked bits (5) => 224 | |
Bits: 0xff & masked bits (6) => 192 | |
Bits: 0xff & masked bits (7) => 128 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mkdir environments | |
for env in $(knife environment list); do | |
knife environment show "${env}" --format=json > "environments/${env}.json" | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Retrieve the size of Chef cookbooks used by different organizations on the Chef server it runs on | |
# Should run as root normally since we use su to hop across to another user | |
full_org_list='' | |
full_file_list='' | |
orgs={} | |
# Getting orgs can take a while, let's hold onto the results for repeat invocations | |
if not File.exist?('.orgs-cached') | |
# NOTE: this produces 2 header lines and a footer line that has the rowcount |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo mtr --port 443 --show-ips -T $1 -4 --no-dns --mpls # not sure why I needed both --show-ips and --no-dns, hmm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from HTMLParser import HTMLParser | |
import sys | |
""" | |
ZScaler IP Page Parser | |
$ curl -sL http://ip.zscaler.com/cgi-bin/index.cgi | python zscaler-status.py | |
{"proxycloud": "zscalertwo.net", | |
"proxyhost":"zs2-*redacted*", | |
"ip": "*redacted_ip*"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for node in $(knife search node "ohai_time:[* TO $(date +%s -d '5hours ago')]" -i); do | |
knife client delete -y $node | |
knife node delete -y $node | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for u in username1 username2; do | |
# Ok, the groups are probably off but you get the point | |
useradd -p $(openssl passwd -1 ABC123def) -G primarygroup -g additionalgroups ${u} | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'find' | |
root = '/Volumes/music' # pick your path | |
Find.find(root) do |path| | |
if FileTest.directory? path and File.basename(path)[0] == '.' | |
Find.prune | |
else | |
d, f = File.split path | |
if f =~ /^(\d+(\-\d+)?.+)(\s\d+)\.(mp3)$/i | |
orig_file = File.join(d, $1 + '.' + $4) # check for existence of original file name including extension case | |
if File.readable? orig_file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wget http://stedolan.github.io/jq/download/linux64/jq || sudo apt-get -y --force-yes install jq || sudo yum install -y jq | |
aws ec2 describe-instances --filters "Name=tag:Name,Values=$NAME" \ | |
"Name=instance-state-name,Values=running" \ | |
| jq -r \ | |
".Reservations[] | .Instances[] | .InstanceId" \ | |
aws ec2 describe-volumes --filters \ | |
"Name=status,Values=available" \ | |
| jq -r ".Volumes[] | .VolumeId" \ |
OlderNewer