Skip to content

Instantly share code, notes, and snippets.

View anolson's full-sized avatar
👋

Andrew Olson anolson

👋
View GitHub Profile
@anolson
anolson / luhn_checksum.rb
Created May 15, 2012 14:43
Luhn Checksum
class LuhnChecksum
attr_accessor :number
def initialize(number = "")
@number = number
end
def valid?
calculate_checksum % 10 == 0
end
@anolson
anolson / output
Created February 21, 2012 21:52
Find saddle points in a matrix
Saddle point found at: [1, 3]
No saddle points found
Saddle point found at: [1, 3]
@anolson
anolson / simple_ed_authenticator.rb
Created December 14, 2011 15:44
Simple class for authenticating people against VT EDAuth Ldap.
require 'rubygems'
require 'net/ldap'
class SimpleEdAuthenticator
HOST, PORT, BASE_DN = 'authn.directory.vt.edu', 636, 'ou=People,dc=vt,dc=edu'
def initialize(options = {})
@authenticated = false
@attributes = {}
@anolson
anolson / log_producer.rb
Created November 10, 2011 21:53
Log streaming in ruby.
class LogProducer
attr_accessor :streams
def initialize(options = {})
@streams = Hash.new
@filename = options[:filename]
add_stream(options[:stream])
end
@anolson
anolson / sendfile.rb
Created August 26, 2011 21:01
Upload a file to Strava
#!/usr/bin/env ruby
require 'net/smtp'
require 'optparse'
module SendFile
class CommandlineOptions
attr_accessor :options
require "test/unit"
class TestFibonachi < Test::Unit::TestCase
def test_fibonachi_numbers
numbers = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765]
numbers.each_with_index { |number, index|
assert_equal number, Fibonachi.number(index)
}
@anolson
anolson / dialog.js
Created March 2, 2011 20:31
Super simple ajax javascript dialog
document.observe('dom:loaded', function(){
$('click_me').observe('click', function(event) {
activateDialog(event);
});
});
function activateDialog(event) {
var element = Event.findElement(event);
fetchDialogContent(element.href);
event.stop();
@anolson
anolson / ride4ruby.rb
Created January 11, 2011 21:21
January Contest: Ride4Ruby
#!/usr/bin/env ruby
require 'net/http'
require 'rexml/document'
module Ride4Ruby
GOOGLE_MAPS_API_KEY = "your google key"
@states = ["Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "District of Columbia", "Florida", "Georgia", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming"]
class Location
@anolson
anolson / google_geocode.rb
Created January 9, 2011 20:41
Simple Google geocoder with HTTParty.
require 'rubygems'
require 'httparty'
module Google
module Geocode
class RequestDenied < StandardError; end
class Client
include HTTParty
@anolson
anolson / model.rb
Created December 21, 2010 20:02
ActiveRecord like model with validations and dynamic attributes
require 'rubygems'
require 'active_model'
require 'active_support'
class Model
include ActiveModel::Validations
include ActiveModel::Conversion
extend ActiveModel::Naming
def initialize(attributes = {})