Skip to content

Instantly share code, notes, and snippets.

View bithive's full-sized avatar

bithive bithive

  • Reed College
  • Portland, OR
View GitHub Profile
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 / 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'
)
@bithive
bithive / power_mate.rb
Last active August 29, 2015 14:06
A class for getting events from a Griffin PowerMate
#!/usr/bin/env ruby
# Ruby interface for Griffin PowerMate
require 'usb'
class PowerMate
VENDOR_ID = 0x077d
PRODUCT_ID_NEW = 0x0410
PRODUCT_ID_OLD = 0x04AA
@bithive
bithive / webhook.rb
Created August 12, 2014 18:50
Stripe CTF 2.0 Level 8
require 'json'
require 'net/http'
require 'socket'
require 'uri'
# first argument is the url for the passworddb server
uri = URI.parse ARGV.shift
$passdb = Net::HTTP.new uri.host, uri.port
# second argument is the local port for our webhook
@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