Skip to content

Instantly share code, notes, and snippets.

View markmcspadden's full-sized avatar

Mark McSpadden markmcspadden

View GitHub Profile
+--------------------------------------------------------+
| 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 |
module ApplicationHelper
def site_name
@@site_name ||= MyConfig['site_name']
end
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
@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 %>
@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 / 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 / fluidinfo-extensions.rb
Created April 8, 2011 14:19
Add a SetOfStrings class as a SERIALIZABLE_TYPE to allow a set of strings to be posted as a primitive type
module Fluidinfo
class SetOfStrings < Array; end
SERIALIZABLE_TYPES << SetOfStrings
end
# Use: strings = Fluidinfo::SetOfStrings["a", "b", "c"]
@markmcspadden
markmcspadden / nested_methods.rb
Created October 28, 2011 15:51
Ruby Nested Methods
# Scott and I came across some nested classes in some code we maintain.
# We then started talking about nested methods...and then started playing.
# After a couple of "Can you?" examples we asked the important "Why would you ever do this?"
# To be clear, I think nested methods are mostly evil (I think Scott agrees)
# Still, just maybe I can create a use case where using nested methods makes sense...
# The case below is something of a social manners exercise.
# Two instances call casual greeting methods (#hi) and interact in that way.
# However, when an instance calls a formal greeting method (#hello) all instances should elevate to formal methods
@markmcspadden
markmcspadden / 2011_best_and_worst.rb
Created December 6, 2011 17:16
My most shameful and most favorite Ruby of 2011
# Part of the Dallas Ruby "Best and Worst of 2011" showcase at the December 2011 meeting
# http://groups.google.com/group/dallasrb/browse_thread/thread/998dd95dd4677042
# Shame
@followings = current_profile.watch_events # NO LIMIT
# Fav
# Recursive Module Includes - yaml_dot_notation.rb
@markmcspadden
markmcspadden / super.rb
Created January 6, 2012 22:13
Playing around with super in module includes with itchy
class Rubyist
def check_me
puts "Rubyist"
end
end
class Chef
end