Skip to content

Instantly share code, notes, and snippets.

View jhamon's full-sized avatar

Jennifer Hamon jhamon

View GitHub Profile
@jhamon
jhamon / clever-api.rb
Created June 23, 2014 18:17
Finding the average number of students per section with the Clever API.
require 'net/https'
require 'json'
uri = URI('https://api.clever.com/v1.1/sections?limit=379')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
request = Net::HTTP::Get.new(uri.request_uri)
@jhamon
jhamon / gravatar.rb
Created May 2, 2014 10:18
Build the gravitar image avatar url from a user email address.
require 'openssl'
def gravitar_url(email)
base = 'http://www.gravatar.com/avatar/'
base + OpenSSL::Digest::MD5.new(email).to_s
end
@jhamon
jhamon / class-variables-through-closure.js
Created April 23, 2014 20:12
Another way to achieve private class variables using closure.
var Cat = (function () {
var numberOfCats = 0;
var Cat = function (name) {
this.name = name;
numberOfCats += 1;
}
Cat.prototype.numberOfCats = function () {
return numberOfCats;
// setInterval implemented using setTimeout
function mySetInterval(fn, delay) {
setTimeout(function () {
fn();
mySetInterval(fn, delay);
}, delay)
}
@jhamon
jhamon / class-variable.js
Created April 20, 2014 11:42
Shared mutable state among "instances of a class" in javascript.
// In this gist, I explain how to achieve mutable shared state
// between "instances of a class", i.e. objects with a shared
// prototype. This mimics how "class variables" are used
// in other languages with classical inheritance.
// Not something you want to do all the time, obviously, but it could
// be handy in some situations.
function Cat() {
// increment the class variable each time a constructor is used.
@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}