Skip to content

Instantly share code, notes, and snippets.

@natritmeyer
natritmeyer / convert_duration_to_seconds.rb
Created July 28, 2015 13:14
Ruby ISO 8601 duration converter
require 'test/unit'
# implementation
class Duration
def in_seconds(raw_duration)
match = raw_duration.match(/PT(?:([0-9]*)H)*(?:([0-9]*)M)*(?:([0-9.]*)S)*/)
hours = match[1].to_i
minutes = match[2].to_i
seconds = match[3].to_f
seconds + (60 * minutes) + (60 * 60 * hours)
@natritmeyer
natritmeyer / init.pp
Last active January 3, 2016 07:59
Sensible puppet defaults
Exec {
logoutput => 'on_failure'
}
exec { 'some_command' :
#...,
logoutput => true
}
@natritmeyer
natritmeyer / thing.xml
Created October 17, 2013 20:42
xpath lesson
<?xml version="1.0"?>
<bookstore specialty="novel">
<book style="autobiography">
<author>
<first-name>Joe</first-name>
<last-name>Bob</last-name>
<award>Trenton Literary Review Honorable Mention</award>
</author>
<price>12</price>
</book>
@natritmeyer
natritmeyer / mount_smbfs.sh
Created September 19, 2013 09:40
How to mount and unmount a SMB share on Mac OS X (using mount_smbfs)
#Mounting the share is a 2 stage process:
# 1. Create a directory that will be the mount point
# 2. Mount the share to that directory
#Create the mount point:
mkdir share_name
#Mount the share:
mount_smbfs //username:password@server.name/share_name share_name/
@natritmeyer
natritmeyer / install_chromedriver.sh
Created September 11, 2013 11:42
Install chromedriver on fedora
wget https://chromedriver.googlecode.com/files/chromedriver_linux64_2.3.zip
unzip chromedriver_linux64_2.3.zip
sudo cp chromedriver /usr/bin/chromedriver
sudo chown root /usr/bin/chromedriver
sudo chmod +x /usr/bin/chromedriver
sudo chmod 755 /usr/bin/chromedriver
@natritmeyer
natritmeyer / chromedriver_centos6_fail.md
Last active December 22, 2015 15:49
Chrome, Chromedriver, CentOS6 #fail

OS:

CentOS6

Output of uname -a:

$ uname -a
Linux localhost.localdomain 2.6.32-358.2.1.el6.x86_64 #1 SMP Wed Mar 13 00:26:49 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

Chrome version:

@natritmeyer
natritmeyer / debug_httparty_request.rb
Last active November 8, 2023 15:47
How to debug HTTParty requests
class MyResource
include HTTParty
debug_output $stdout # <= will spit out all request details to the console
#...
end
@natritmeyer
natritmeyer / teenee_fizzbuzz.rb
Created August 21, 2013 11:33
Shortest ruby fizzbuzz solution... maybe...
p (1..100).map{|i|o="";o<<"Fizz" if i%3==0;o<<"Buzz" if i%5==0;o<<i.to_s if o=="";o}
#84 chars
@natritmeyer
natritmeyer / tiniest_http_client.rb
Created August 15, 2013 14:05
The world's smallest ruby http client
require 'net/http'
class HttpClient
def initialize(base_url, username = nil, password = nil)
@base_url = base_url
@username = username
@password = password
end
def get(path, headers = {})
@natritmeyer
natritmeyer / put.sh
Created July 25, 2013 10:06
PUT some XML at a resource using curl
curl -H 'Content-Type:application/xml' -X PUT -d '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><thing></thing>' http://192.168.0.1:8080/some/resource/ --user admin:password