Skip to content

Instantly share code, notes, and snippets.

View markmcspadden's full-sized avatar

Mark McSpadden markmcspadden

View GitHub Profile
@markmcspadden
markmcspadden / long_url
Created April 8, 2011 06:30
Ruby library for following out short urls to their end destination. LongUrl.new('http://t.co/fadsfs').longize
require 'net/http'
require 'uri'
class LongUrl
attr_accessor :short_url
attr_reader :long_url
def initialize(short_url)
@short_url = short_url
@markmcspadden
markmcspadden / phone_numberize.rb
Created December 17, 2010 05:47
Add hyphens in the right places for phone numbers...simulates real time input
require 'test/unit'
class PhoneNumberizeTest < Test::Unit::TestCase
# MM2: The one liner....and the one called by the tests
# yes it's ugly...I would probably not like to pick up someone else's code and see this ;)
def phone_numberize(number)
number.gsub(/#{/(\d{#{number.length-10}})/ if number.length>10}(\d{3})(\d{3})?(\d{1,4})/,"\\1-\\2-\\3-\\4").gsub("--","-").chomp("-")
end
@markmcspadden
markmcspadden / 2010 Year in Code.rb
Created December 7, 2010 16:13
My most shameful and most favoritest Ruby chunks of 2010.
# Part of the Dallas Ruby "A Year in Code" December 2010 meeting.
# http://groups.google.com/group/dallasrb/browse_thread/thread/1c114671b17dd81f
# Shame
# Yes it was committed.
# Yes I did come up with something better before it went to production. :)
<% 60.times do %>&nbsp;<% end %>
# In this model, we'll use a Markov chain to calculate probabilities associated with "Tweeting"
# A few code helpers for our exercise
class Float
def to_percentage
self*100
end
end
# Now let's define our states
module ApplicationHelper
def site_name
@@site_name ||= MyConfig['site_name']
end
end
+--------------------------------------------------------+
| Name | Time (ms) | Requests/s | IO (KB/s) | Errors |
+--------------------------------------------------------+
| baseline | 1310.3 | 0.8 | 3.9 | 14 |
+--------------------------------------------------------+
+-----------------------------------------------------------------------------------------------------------------------------------------------+
| % Baseline | Name | Time (ms) | Requests/s | IO (KB/s) | Errors |
+-----------------------------------------------------------------------------------------------------------------------------------------------+
| 1.11929 | Using named scopes for late recommendations | 1466.6 | 0.7 | 3.5 | 14 |
| 1.17813 | Actually implementing named scopes for late recommendations into controller | 1543.7 | 0.6 | 3.8 | 14 |