Skip to content

Instantly share code, notes, and snippets.

View IanWhitney's full-sized avatar

Ian Whitney IanWhitney

View GitHub Profile
@IanWhitney
IanWhitney / gist:4557251
Created January 17, 2013 16:27
Getting rid of the Podcast app and returning to Narnia
1) In iTunes, go to Apps, find the Podcasting app. Select it and delete it.
2) Still in iTunes, click on your phone (or ipod touch, ipad, etc).
3) Click Podcasts
4) Check "Sync Podcasts"
5) Sync your phone
@IanWhitney
IanWhitney / gist:4562057
Last active December 11, 2015 06:49
Setting up and using a text search field in redis.
Movies.each do |movie|
$redis.set "title_search:#{movie.title}", "#{movie.id}"
End
search_string = "titanic"
matching_keys = $redis.keys "title_search:*#{search_string}*"
matched_ids = []
matching_keys.each do |key|
matched_ids << $redis.get(key)
@IanWhitney
IanWhitney / controller_stubbing.rb
Created February 13, 2013 19:07
Stubbing a controller method. I had to do this to test an API controller that required authorization.
def setup
@controller.stubs(:token_valid?).returns(true)
end
@IanWhitney
IanWhitney / gist:4955714
Created February 14, 2013 19:42
Using inject to take two arrays and use them to populate a hash
@required_keys = [:email_address,:subject]
@optional_keys = [:email_from]
@params = {:email_address=>"test@test.com", :subject=>"email subject", :email_from=>"hi@test.com", :extra=>"not used"}
all_params = (@required_keys + @optional_keys).inject({}) do |result, element|
result[element] = @params[element]
result
end
=> {:email_address=>"test@test.com", :subject=>"email subject", :email_from=>"hi@test.com"}
@IanWhitney
IanWhitney / custom_enumerable.rb
Created March 14, 2013 15:46
Required methods for a custom enumerable if you want to pass it to PartialRenderer.
require 'forwardable'
class CustomEnum
extend Forwardable
include Enumerable
def_delegators :@collection, :size, :each, :blank?
attr_accessor :collection
def initialize()
self.collection = []

That watching bad movies is 'bad for you'

There are two arguments presented here. The first is that watching bad movies is somehow boring and awful. The second is that people who say they enjoy bad movies actually enjoy the mocking of those movies and the people who made them.

The first argument can be true, but it depends wholly on the movie and the situation. Watching, say, Blood Freak by yourself is a pretty dire experience that I wouldn't recommend. Watching Blood Freak with some friends and a few drinks? That's a fun shared experience. Years later you can say, "Remember when we watched that movie about the guy who turned into a blood-thirsty turkey?" and have a good time reminiscing.

This isn't just true of bad movies, it's true of all movies, an art form that was designed for the communal experience.

JJHo and JT extend their second argument by joking about reading bad novels or listening to bad music, as if no one does those. So why would anyone do this for movies?

@IanWhitney
IanWhitney / times.csv
Created January 6, 2014 16:05
Mirroring task completion time
2014-01-05T12:54:59-0600 6.5937
2014-01-05T12:56:11-0600 6.6516
2014-01-05T12:56:14-0600 4.6443
2014-01-05T12:56:44-0600 6.3162
2014-01-05T12:57:26-0600 6.2678
2014-01-05T12:58:03-0600 6.2010
2014-01-05T12:58:32-0600 5.8272
2014-01-05T12:59:04-0600 7.2103
2014-01-05T12:59:55-0600 7.2239
2014-01-05T13:00:37-0600 7.7785
# Referenced in Design Is Refactoring post http://designisrefactoring.com/2016/02/03/factories/
# This code takes the previous example and extends it. Classes can now define 'roles' they satisfy
# and each class can satisfy more than one role.
#
# At load time, these roles are examined and recorded in registries.
# In this example there's a CampusLikeRegistry that contains every class that says it's campus-like.
# But you could have any number of registries.
require 'singleton'
require 'forwardable'
Clojure
Empty board
Board comparison
Attacking
C++
Can't occupy same space
Attacking
ECMA