Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am bbwharris on github.
  • I am bbwharris (https://keybase.io/bbwharris) on keybase.
  • I have a public key ASCIBkyKOykAjy2rFKN8Mm7nL2VidkFrWTutGAZoH-GhLQo

To claim this, I am signing this object:

@bbwharris
bbwharris / stud.rb
Last active October 20, 2015 21:49
require 'formula'
class Stud < Formula
url 'https://github.com/bumptech/stud/tarball/a9b5aca962219ef013afaa73fec4676bb7c056a3'
version '0.3-a9b5aca962'
homepage 'https://github.com/bumptech/stud'
sha256 '448ab2d87dd69dd7db8f5c994c55b692a8748e4228865b0be5af1df41c17ca51'
depends_on 'libev'
#depends_on 'openssl'
@bbwharris
bbwharris / longest_palindrome.rb
Created August 16, 2012 14:16
Naive Longest Palindrome
# Not the fastest, but working
def longest_palindrome(input_string)
# default to the first letter, so we return 'a' palindrome if none found
palindrome = input_string.first
max = input_string.size
# Windows over possible substrings and tests for a palindrome
max.downto(0) do |last|
0.upto(max) do |first|
substring = input_string.slice(first..last)
@bbwharris
bbwharris / to_roman.rb
Created August 16, 2012 04:12
Naive Inaccurate to_roman
# Doubt 100% accurate answer, but seems somewhat correct.
TRANSLATOR = {
1000 => 'M',
900 => 'CM',
500 => 'D',
400 => 'CD',
100 => 'C',
90 => 'XC',
50 => 'L',
@bbwharris
bbwharris / us_state_loader.rake
Created February 22, 2012 03:56
States with Abbreviations, Rails, Ruby
namespace :states do
desc "load state names and abbreviations"
task :load => :environment do
states = {
"Alabama" => "AL",
"Alaska" => "AK",
"Arizona" => "AZ",
"Arkansas" => "AR",
"California" => "CA",
"Colorado" => "CO",
@bbwharris
bbwharris / inject_vs_readability.rb
Created December 16, 2011 05:09
Inject vs. Readability
# There is more than one way to skin a cat, different coders prefer different methods.
include ActionView::Helpers
class Link < Struct.new(:title, :url); end
a = Link.new("Google", "http://www.google.com")
b = Link.new("Hacker News", "http://news.ycombinator.com")
array_of_links = [a, b]
@bbwharris
bbwharris / test_failure_error.txt
Created December 6, 2011 15:28
DJ Failure Cucumber
Given delayed jobs are run # step_definitions/common_steps.rb:1
---
- !ruby/object:Delayed::Backend::ActiveRecord::Job
attributes:
id: 1
priority: 0
attempts: 1
handler: |+
--- !ruby/struct:Delayed::PerformableMethod
object: !ruby/object:Page
@bbwharris
bbwharris / anagram.rb
Created November 16, 2011 16:33
Anagram Kode Kata
require 'digest/sha1'
class Anagram
attr :anagrams
def initialize(file)
@anagrams = {}
File.open(file).each do |word|
add_word_to_anagrams_hash(build_key(word.chomp),word.chomp)
end
@bbwharris
bbwharris / mixins.scss
Created August 24, 2011 02:42
SCSS Mixins
@mixin linked_image($image,$width,$height,$xoffset,$yoffset) {
background: url($image) no-repeat $xoffset $yoffset;
display: block;
width: $width;
height: $height;
text-indent: -9999px;
overflow: hidden;
}
@mixin italic_stack {
font-style: italic;
@bbwharris
bbwharris / gist:1143879
Created August 13, 2011 14:03
Irrelevant?
module ActiveRecord
class Base
# FROM http://www.xcombinator.com/2008/08/11/activerecord-from_xml-and-from_json-part-2/
def self.from_hash( hash )
h = hash.dup
h.each do |key,value|
h[key].map! { |e| reflect_on_association(key.to_sym ).klass.from_hash e } if value.is_a?(Array)
h[key] = reflect_on_association(key.to_sym).klass.from_hash(value) if value.is_a?(Hash)
end