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
View keybase.md

Keybase proof

I hereby claim:

  • I am samullen on github.
  • I am samullen (https://keybase.io/samullen) on keybase.
  • I have a public key ASCXrrHQGs_AlnftyrLbcSM3YXg2vd28mo__mejPhoOrBQo

To claim this, I am signing this object:

@samullen
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
samullen / heroku_import.sh
Last active Dec 23, 2015
function to import heroku database into a local postgres database Usage: heroku_import <appname> <database name>
View heroku_import.sh
function heroku_import {
app=$1
database=$2
dumpfile="/tmp/${database}.dump"
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
samullen / productivity.sh
Last active Jan 30, 2019
The two most productivity increasing Bash functions ever written.
View productivity.sh
function worktime {
echo "# WORKTIME" | sudo tee -a /etc/hosts > /dev/null
while read -r line; do
echo "127.0.0.1 ${line}"
done < $HOME/.blocked_sites | sudo tee -a /etc/hosts > /dev/null
}
function slacktime {
flag=0
while read -r line; do
@samullen
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
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
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}')]"}
end
@samullen
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"
end
# Since I already have the Google alert set up...
def cofounder
"Samuel Mullen"
end
@samullen
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?/)
$1.to_i.send($2)
end
end
@samullen
samullen / ip2int.rb
Created Oct 11, 2010
IP to Integer and back
View ip2int.rb
# IP to Integer
ip = IPAddr.new('255.255.255.255')
puts ip.to_i
# Integer to IP
ipnum = 4294967295
ip = IPAddr.new(ipnum, 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.