Skip to content

Instantly share code, notes, and snippets.

View patmaddox's full-sized avatar
🤔
Trying to figure out how to look up comments I've left

Pat Maddox patmaddox

🤔
Trying to figure out how to look up comments I've left
View GitHub Profile
@patmaddox
patmaddox / goofy_ruby_methods.rb
Created April 14, 2011 09:18
goofy ruby methods
module Kernel
def mapme(*selectors)
selectors.map {|s| send(s) }
end
def mapkeys(*selectors)
Hash[selectors.zip(mapme(*selectors))]
end
end
$ bundle exec cucumber
Using the default profile...
..............................................................................................................................................................................................................................................................................................................................................................................................F-...F---F-----F----.F-F---F------...F-F-----F----------------.F-F---F-------------------------------.F-F-----F----------------------------------------.F-F---F---F---F----F----F---F---F---F---F---F---F------F---F---F----F-----F---F---F---F----F-----F---F---F---F----F-----F---F---F---F----F-----F---F------F----------------------------------------.F-F---F---F---F---F---F---F---F---F---F---F---F---F---F---
(::) failed steps (::)
expected "ruby: no such file to load -- bundler/setup (LoadError)\n" to include "does another thing"
Diff:
@@ -1,2 +1,2 @@
-does another thing
@patmaddox
patmaddox / My question.txt
Created April 11, 2011 23:07
Question about case-insensitive columns in Rails
Hola Rails people. I have a column in my database that I need to treat
as case-insensitive. The standard solution to this is to downcase the
value before inserting it into the database, and when doing
searches. My problems with this are:
1. I have to make calls to String#downcase in several places where I
*really* mean "this is case-insensitive"
2. I can only provide automatic-downcasing when going through the API
I provide. Anyone calling MyClass.where(:name => foo) has to know to
@patmaddox
patmaddox / lazy_ivar_init.rb
Created April 1, 2011 10:02
lazy ivar initialization?
class SomethingDoer
def initialize
lazy_init(:foo) { Foo.new }
end
def do_something
@foo.something # doesn't blow up because it auto-init'd
end
end
@patmaddox
patmaddox / 1_user.rb
Created March 10, 2011 00:40
I suck at mongoid
class User
include Mongoid::Document
references_one :best_friend, :class_name => "Person"
references_one :worst_enemy, :class_name => "Person"
end
@patmaddox
patmaddox / 1_before.rb
Created March 7, 2011 07:03
Wondering what people think. Gratuitous refactoring, or marvelous use of Ruby?
module API
class Version1 < Grape::API
version 'v1'
resource :hotels do
get '/' do
if [:latlng, :query].all? {|key| params[key].blank? }
error! 'Please pass in latlng|query'
end
subscription("12345") do
plan(:amount => 12.34)
credit_card(:number => 1)
signup(:success)
renewal(:success)
renewal(:failure)
payment(:success)
end
@patmaddox
patmaddox / 01_routes.rb
Created December 7, 2010 19:12
Rails 2.3.5 routing sanity check
ActionController::Routing::Routes.draw do |map|
map.namespace(:admin) do |admin|
admin.resource :subscription, :member => { :upgrade => :post } do |subscription|
subscription.resources :payments
end
end
end
module Codebreaker
class Game
def initialize(output)
@output = output
end
def start
@output.puts("Welcome to Codebreaker!")
@output << "You smell bad"
end
end
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Create and share movies of your drawings and voice! -- Show &amp; Tell for iPad</title>
<link rel="stylesheet" href="/css/master.css" type="text/css" media="screen" title="no title" charset="utf-8">
</head>
<body>