Skip to content

Instantly share code, notes, and snippets.

bradland / base642ip
Created Mar 5, 2014
Convert IP address to/from base64 encoded format for BOOTP DHCP configuration in OS X Server (or other applications).
View base642ip
#!/usr/bin/env ruby
# Based on answer found here:
require 'base64'
class App
def run(arg)
bradland / csvanalyze.rb
Last active Aug 29, 2015
Boilerplate CSV analysis script
View csvanalyze.rb
#!/usr/bin/env ruby
require 'csv'
require 'ostruct'
require 'optparse'
require 'i18n'
require 'set' # this should only be required until i18n updates to new rev
require 'active_support/core_ext/string/inflections'
I18n.enforce_available_locales = true # I18n spams warn unless this is set
bradland / rescue.rb
Last active Aug 29, 2015
Trap vs rescue for handling ctrl-C during script execution.
View rescue.rb
# Using a block allows you to limit the scope of the Interrupt handling code,
# as well as providing the opportunity to provide a meaningful exit code. For
# more information on exit codes, see:
sleep 10
rescue Interrupt
$stderr.puts "Stopped sleeping..."
exit 130
bradland / unicode_box_drawing.rb
Created Dec 10, 2014
All unicode box drawing characters
View unicode_box_drawing.rb
('2500'.to_i(16)..'257F'.to_i(16)).map { |i| [i.to_s(16), [i].pack('U')] }.each { |c| puts "%s: %s" % [c[0], c[1]] };0
View audio_text.rb
require_relative 'lib/portaudio'
class AudioTest
include PortAudio
def initialize
@devices = get_devices
bradland / string_replacement.rb
Last active Aug 29, 2015
String replacement/removal method benchmarks.
View string_replacement.rb
require 'benchmark'
alias e puts
N = "\n"
N_TIMES = 550_000 # Run it n times.
e 'We will next compare the elimination of the character "f"'
e 'by comparing the methods .delete .gsub and .tr'+N+N
# Our Test String comes next.
View pry_long_time.rb
class Foo
attr_accessor :baz, :qux, :quux, :corge, :grault, :garply, :waldo, :fred, :plugh, :xyzzy, :thud
def initialize(bar)
@bar = bar
@baz = 'baz'
@qux = 'qux'
@quux = 'quux'
@corge = 'corge'
@grault = 'grault'
@garply = 'garply'
View datebench_ips.rb
#!/usr/bin/env ruby
require 'benchmark/ips'
require 'time'
if defined?(JRUBY_VERSION)
JODA_FMT = org.joda.time.format::DateTimeFormat.for_pattern("Y-M-d H:m:s Z")
def joda_time(time)
View byte_buffer.rb
class ByteBuffer
attr_reader :bytes
# A ByteBuffer accepts encoded string buffers and unpacks them to an
# internal array of bytes stored using fixnum so that binary operations can
# be easily performed.
def initialize(buffer, mode)
case mode
when 'a' # arbitrary string; converts to ascii char code (this is faster than String#ord)
@bytes = buffer.unpack('C*')
View ghosttest.c
/* ghosttest.c: GHOST vulnerability tester */
/* Credit: */
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#define CANARY "in_the_coal_mine"