Skip to content

Instantly share code, notes, and snippets.

View bithive's full-sized avatar

bithive bithive

  • Reed College
  • Portland, OR
View GitHub Profile
@bithive
bithive / totp.rb
Created May 23, 2011 23:19
Generate Google Authenticator codes in Ruby (requires base32 gem)
#!/usr/bin/env ruby
require 'rubygems'
require 'base32'
require 'openssl'
int = 30
now = Time.now.to_i / int
key = Base32.decode File.read('secret.key').strip
042880e55eee827a2612c04df675f4233e2bf421cbd39d7f14af3fbda3535c5e2ca404a6df98ae9b004bae3bf477393f22dfb00621d18fc62c8ab9451d0ab397db;
@bithive
bithive / iscsi-multi-chap.sh
Created February 1, 2017 00:34
Shell script to log in to multiple iSCSI targets, e.g. on an AWS Storage Gateway
#!/bin/bash
# Adapted for Debian from
# http://backdrift.org/how-to-connect-to-multiple-iscsi-targets-requiring-different-usernames-and-passwords
# Set $InitiatorName
. /etc/iscsi/initiatorname.iscsi
# Storage Gateway IP
PORTAL=172.31.2.56
@bithive
bithive / coin_acceptor.rb
Created December 20, 2013 23:08
A simple class for reading values from the DG600F coin acceptor sold by SparkFun (https://www.sparkfun.com/products/11636)
#!/usr/bin/env ruby
# A simple class for reading values from the DG600F coin acceptor sold by
# SparkFun (https://www.sparkfun.com/products/11636)
#
# The coin acceptor must be configured to send three bytes per coin; see section
# 8.6 of the manual.
#
# You can configure the serial device and baud rate, e.g.:
#
@bithive
bithive / ip.pm
Created June 17, 2013 20:32
Perl module for nginx which displays the value of REMOTE_ADDR
package ip;
use nginx;
sub handler {
my $r = shift;
my $ip = $r->remote_addr;
$r->send_http_header("text/html");
$reply = <<END;
@bithive
bithive / create-iscsi-zvol.sh
Last active December 16, 2015 07:29
Bash script for creating ZFS volumes on SmartOS and sharing them over iSCSI
#!/bin/sh
bold=$(tput bold)
norm=$(tput sgr0)
ENV=""
GUID=""
NAME=""
NEWVOL=""
OLDVOL=""
@bithive
bithive / clone.rake
Last active December 10, 2015 01:09
A Rake task for destructively copying one environment's database to another, preserving IDs. Should support different database adapters, but aborts if the schema versions don't match. Not recommended for large tables.
namespace :clone do
desc 'destructively copy the source environment database to the target'
task :database, [:source, :target] => :environment do |t, args|
source = args[:source].to_sym
target = args[:target].to_sym
versions = {}
[ source, target ].each do |db|
ActiveRecord::Base.establish_connection db
@bithive
bithive / cert-watch.rb
Created October 17, 2012 22:13
SSL Certificate Expiration
#!/usr/bin/env ruby
require 'date'
certs = []
regex = /([\w\-\.]+):\s+Not After : (.+)/
today = Date.today
%x[grep -H 'Not After' #{ARGV.shift}].each_line do |line|
data = regex.match line
@bithive
bithive / arp.rb
Created June 3, 2011 22:16
ARP for eth0:*
#!/usr/bin/env ruby
# ARPs for all the IPs aliased to this machine.
data = %x[ifconfig -a].split /\n\n/
data.each do |block|
d = /(eth\d:\d+)\s+/.match(block)
a = /inet addr:(\d+\.\d+\.\d+\.\d+)/.match(block)
@bithive
bithive / gist:e115a85f75d31f0230dd
Created March 20, 2015 00:35
Use aws-sdk gem with radosgw
Aws::S3::Client.new(
access_key_id: ENV['AWS_ACCESS_KEY'],
secret_access_key: ENV['AWS_SECRET_KEY'],
region: 'default',
endpoint: 'http://s3.example.org',
signature_version: 's3'
)