Skip to content

Instantly share code, notes, and snippets.

Samuel Mullen samullen

Block or report user

Report or block samullen

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile

Keybase proof

I hereby claim:

  • I am samullen on github.
  • I am samullen ( on keybase.
  • I have a public key ASCXrrHQGs_AlnftyrLbcSM3YXg2vd28mo__mejPhoOrBQo

To claim this, I am signing this object:

samullen / todo.rb
Last active Aug 29, 2015
Very basic todo script for use in an "Intro to Ruby" project I'm developing.
View todo.rb
#!/usr/bin/env ruby
require "date"
class Todo
attr_accessor :complete
attr_reader :name, :due_on
def initialize(name, due_on=nil, complete=false)
@name = name
samullen /
Last active Dec 23, 2015
function to import heroku database into a local postgres database Usage: heroku_import <appname> <database name>
function heroku_import {
heroku pgbackups:capture --app $app
curl -o $dumpfile `heroku pgbackups:url --app ${app}`
pg_restore --verbose --clean --no-acl --no-owner --jobs 4 -d $database $dumpfile
samullen /
Last active Jan 30, 2019
The two most productivity increasing Bash functions ever written.
function worktime {
echo "# WORKTIME" | sudo tee -a /etc/hosts > /dev/null
while read -r line; do
echo " ${line}"
done < $HOME/.blocked_sites | sudo tee -a /etc/hosts > /dev/null
function slacktime {
while read -r line; do
samullen / timeframe.rb
Created Aug 22, 2013
Wanting opinions on the each method. Am I doing this right?
View timeframe.rb
class Timeframe
include Enumerable
attr_accessor :start_time, :end_time
ONEDAY = 24 * 60 * 60
def initialize(start_time, end_time)
@start_time = start_time
@end_time = end_time
samullen / absence_validator.rb
Created Dec 27, 2011
Validator class for validating the absence of value in a field if other conditions are met.
View absence_validator.rb
class AbsenceValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
return unless value
if options.empty? # don't know why you would want this
record.errors[attribute] << "must be blank"
elsif options[:all] && options[:all].all? {|sym| record.read_attribute(sym)}
record.errors[attribute] << "must be blank if the following attributes are defined: #{options[:all].join(', ')}"
elsif options[:any] && options[:any].any? {|sym| record.read_attribute(sym)}
record.errors[attribute] << "must be blank if any of the following attributes are defined: #{options[:any].join(", ")}"
samullen / finders.rb
Created Dec 26, 2011
User defined finders for Capybara
View finders.rb
Capybara.add_selector(:link) do
xpath {|rel| ".//a[contains(@rel, '#{rel}')]"}
samullen / gist_seo_test.rb
Created Feb 5, 2011
I want to know if Google can read gists embedded in sites. This block of code will hopefully help me determine that
View gist_seo_test.rb
# Ruby class named after my company. Why not get the possible SEO?
class Phalanx
def foo
puts "Fooman was here"
# Since I already have the Google alert set up...
def cofounder
"Samuel Mullen"
samullen / timeperiod_to_seconds.rb
Created Dec 9, 2010
Calculates seconds to more english friendly time periods (1 hour, 2 days, etc.)
View timeperiod_to_seconds.rb
def calculate_seconds(period)
if period.match(/(\d+).+?(second|minute|hour|day|week|month|year)s?/)
samullen / ip2int.rb
Created Oct 11, 2010
IP to Integer and back
View ip2int.rb
# IP to Integer
ip ='')
puts ip.to_i
# Integer to IP
ipnum = 4294967295
ip =, Socket::AF_INET).to_s
# If you store the ipnum in MySQL, make sure to use unsigned into for the field.
You can’t perform that action at this time.