Skip to content

Instantly share code, notes, and snippets.

View jhamon's full-sized avatar

Jennifer Hamon jhamon

View GitHub Profile
@jhamon
jhamon / pre-commit
Created January 18, 2014 10:27
JSHint pre-commit hook. To use, place into .git/hooks/ and make executable with chmod. Modified from this SO answer: http://stackoverflow.com/questions/15703065/github-setup-pre-commit-hook-jshint
#!/bin/sh
files=$(git diff --cached --name-only --diff-filter=ACM | grep ".js$")
if [ "$files" = "" ]; then
exit 0
fi
pass=true
for file in ${files}; do
@jhamon
jhamon / time_series.rb
Last active December 31, 2015 01:49
#merge! will merge together time series data in O(m) time where m is the length of the shorter time series data set. Run specs with `rspec time_series_spec.rb --color --format doc`. See also `ruby time_series_benchmarks.rb` to see how #merge! performs on a very large receiver array. The non-bang #merge is always slow and has poor memory performa…
require 'date'
class TimeSeries
attr_reader :data, :date
def initialize(data, date)
raise ArgumentError unless data.is_a?(Array) && date.is_a?(Date)
raise ArgumentError, "TimeSeries cannot be empty" if data.empty?
@data = data
@date = date
@jhamon
jhamon / companies.dat
Created November 25, 2013 20:50
Discover random tech companies quickly. `ruby get-jobbed.rb 3` to launch browser tabs for three random tech companies.
http://jobs.37signals.com/
http://42floors.com/jobs
http://www.fourthandgrand.com/jobs
http://www.500friends.com/jobs
http://www.72lux.com/careers.html
https://docs.google.com/a/appacademy.io/spreadsheet/viewform?formkey=dFhTLUJURWFqTmFDVkhGRm52VVZfNmc6MQ
http://www.academia.edu/hiring
http://www.accellion.com
http://www.achaogen.com/
http://www.activelylearn.com/jobs
@jhamon
jhamon / text_analyzer.rb
Created November 21, 2013 22:30
To run from the command line, pass one filename as an argument. `ruby text_analyzer.rb text_file_to_analyze.txt`
class TextAnalyzer
def initialize(raw_text)
@text = raw_text
self.normalize
@words = self.tokenize
end
def tokenize
@text.split(" ")
end
@jhamon
jhamon / resume.tex
Last active December 28, 2015 02:19
Skeleton latex resume. To use, first download and install a LaTeX distribution. Mac users should grab the installer at https://www.tug.org/mactex/ (warning: large file). Next, alter this file and compile it to pdf on the command line using `pdflatex resume.tex`. `resume.pdf` should be created.
\documentclass[12pt]{article}
\usepackage{fullpage}
\usepackage{enumitem}
\usepackage{xhfill}
\usepackage[width=5.5in, height=9in]{geometry}
\pagestyle{empty}
\raggedbottom
\raggedright
\setlength{\tabcolsep}{0in}
\usepackage[colorlinks=true, urlcolor=red]{hyperref}
@jhamon
jhamon / gist:7425894
Created November 12, 2013 05:21
My terminal prompt.
PS1="\[\e[0;33;49m\]\n\W\[\e[0m\e[0;34;49m\] \$ \[\e[0m\]"
@jhamon
jhamon / num_to_code.rb
Last active December 25, 2015 18:19
Iteratively converting a FixNum into a base 62 string representation.
require 'CMath'
URLSAFE_CHARS = '0123456789' +
'abcdefghijklmnopqrstuvwxyz' +
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
def num_to_code(decimal_number, base=62)
raise "Invalid base" unless (2..62).include?(base)
raise ArgumentError unless decimal_number > 0
class Cat < ActiveRecord::Base
validates :name, exclusion: { in: %w(Garfield Sylvester Tom Felix),
message: "No celebrity cat names allowed."}
validates :hair_length, inclusion: { in: %w(long_hair short_hair hairless),
message: "%{value} is not a valid hair length" }
validates :age, numericality: { only_integer: true,
message: "Only integer ages are allowed."
class Object
def self.new_attr_accessor(*attr_names)
# Metaprogramming implementation of the
# self.attr_accessor class method
attr_names.each do |attr_name|
define_method(attr_name) do
instance_variable_get("@#{attr_name}")
end
class User
# ... clipped for brevity
def save
# Create a new row in the users table
if @id.nil?
QuestionsDatabase.instance.execute(<<-SQL, @fname, @lname)
INSERT INTO
users (fname, lname)
VALUES