Skip to content

Instantly share code, notes, and snippets.

View sstelfox's full-sized avatar

Sam Stelfox sstelfox

View GitHub Profile
@sstelfox
sstelfox / docstring_test.rb
Created May 21, 2014 19:25
Using a DOCSTRING within a call time argument to a method.
def test(one, str, two)
puts str
end
test(3, <<EOM, 6)
This is a multiline string in some madness version fo the format
EOM
@sstelfox
sstelfox / train_watch.sh
Created June 1, 2014 16:31
Stupid bash tricks? Stupid bash tricks.
#!/bin/bash
touch readysetgo
clear
while [ -f readysetgo ]; do
sleep 0.1
done
sl
@sstelfox
sstelfox / email_regex.rb
Last active August 29, 2015 14:03
Email Validation Regex
# According to RFC1123 the following characters may appear in a host name:
#
# * A to Z ; upper case characters
# * a to z ; lower case characters
# * 0 to 9 ; numeric characters 0 to 9
# * - ; dash
#
# Additionally the host name must obey the following rules:
#
# * A host name (label) can start or end with a letter or a number
@sstelfox
sstelfox / return_test.rb
Created July 1, 2014 19:44
Testing what happens when returning out of a block
module Klass
def self.counter
Thread.current[:counter] ||= 0
end
def self.counter=(value)
Thread.current[:counter] = value
end
def self.yield_with_counter
@sstelfox
sstelfox / host_override.sh
Created July 9, 2014 02:14
Override the linux library responsible for the host file too allow for alternate locations
#!/bin/bash
OVERRIDE_PATH="./lib_overrides"
COMMAND="${1}"; shift
ARGUMENTS="$@"
mkdir -p ${OVERRIDE_PATH}
# Ensure the host file exists at our new location
@sstelfox
sstelfox / number_list_summarization.rb
Created July 11, 2014 16:07
Playing around with list summarization
# Generate a list of all the possible port numbers with 1/80 randomly removed
# from the list.
ar = (1...(2 ** 16)).to_a.select { |i| rand(80) != 0 }
# Build a summary of the list
prev = ar[0]
summary = ar.slice_before do |e|
prev, prev2 = e, prev
prev2.succ != e
end.map do |a|
@sstelfox
sstelfox / otp_auth.rb
Created July 22, 2014 13:17
Simple authenticator
#!/usr/bin/env ruby
require 'openssl'
DEFAULT_INTERVAL = 30
module Base32
Base32Error = Class.new(RuntimeError)
CHARS = "abcdefghijklmnopqrstuvwxyz234567".each_char.to_a
@sstelfox
sstelfox / Gemfile
Last active August 29, 2015 14:08
A fast and dirty parser for turning a kismet XML file into a more organized KML file.
source "https://rubygems.org"
gem 'nokogiri'
gem 'ruby_kml'
#!/usr/bin/env ruby
require 'csv'
require 'liquid'
require 'ostruct'
module Engine
def self.compound(name = nil, &blk)
rule_list.push(CompoundRule.new(name, &blk))
end
@sstelfox
sstelfox / gist:562e1a4f52fd0668dc6a
Created December 29, 2014 14:52
retry_block.rb
def retry_block
retry_count ||= 0
yield
rescue => e
retry_count += 1
if retry_count >= 5
puts "Fatal aborting..."
raise e
else
puts "Error #{retry_count}: #{e.message}"