Skip to content

Instantly share code, notes, and snippets.

View samullen's full-sized avatar

Samuel Mullen samullen

View GitHub Profile
@samullen
samullen / table.mkdn
Created February 22, 2020 18:12 — forked from ngs/table.mkdn
Unicode character table

A

Description Entity Preview
A With Acute, Latin Capital Letter Á Á
A With Acute, Latin Small Letter á á
A With Breve, Latin Small Letter ă ă
A With Caron, Latin Small Letter ǎ ǎ
A With Circumflex, Latin Capital Letter  Â
A With Circumflex, Latin Small Letter â â
@samullen
samullen / keybase.md
Created September 19, 2019 18:18
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 / productivity.sh
Last active January 30, 2019 18:46
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 "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 / heroku_import.sh
Last active December 23, 2015 07:18
function to import heroku database into a local postgres database Usage: heroku_import <appname> <database name>
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 / timeframe.rb
Created August 22, 2013 20:06
Wanting opinions on the each method. Am I doing this right?
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 December 27, 2011 20:09
Validator class for validating the absence of value in a field if other conditions are met.
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 December 26, 2011 16:44
User defined finders for Capybara
Capybara.add_selector(:link) do
xpath {|rel| ".//a[contains(@rel, '#{rel}')]"}
end
@samullen
samullen / gist_seo_test.rb
Created February 5, 2011 04:26
I want to know if Google can read gists embedded in sites. This block of code will hopefully help me determine that
# 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 December 9, 2010 23:24
Calculates seconds to more english friendly time periods (1 hour, 2 days, etc.)
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 October 11, 2010 20:44
IP to Integer and back
# 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.