Skip to content

Instantly share code, notes, and snippets.

@efatsi
efatsi / switch.py
Created November 5, 2012 15:52 — forked from brettbuddin/switch.py
The code that powered the Twerrible Towel (http://twerribletowel.com). It processed 44,610 relevant tweets over the course of 5 days.
#!/usr/bin/env python
import sys
import random
from ctypes import *
from Phidgets.Devices.InterfaceKit import InterfaceKit
from Phidgets.PhidgetException import PhidgetErrorCodes, PhidgetException
try:
kit = InterfaceKit()
kit.openPhidget()
@efatsi
efatsi / log
Created October 29, 2012 15:36
Started POST "/avatars" for 127.0.0.1 at 2012-10-29 11:35:49 -0400
Processing by AvatarsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"VpFNQxYczGC3d/m+HlC8ski3vPCIwJu8xbmb70HpJ7I=", "avatar"=>{"image"=>#<ActionDispatch::Http::UploadedFile:0x007f8b2fae2ec0 @original_filename="vigeclones.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"avatar[image]\"; filename=\"vigeclones.jpg\"\r\nContent-Type: image/jpeg\r\n", @tempfile=#<File:/var/folders/j3/zdf8571x7cx8q0mwm2c_r57r0000gn/T/RackMultipart20121029-23346-bh66db>>}, "commit"=>"Add Image"}
Command :: identify -format %wx%h '/var/folders/j3/zdf8571x7cx8q0mwm2c_r57r0000gn/T/vigeclones20121029-23346-1qx7yn.jpg[0]'
Command :: identify -format %m '/var/folders/j3/zdf8571x7cx8q0mwm2c_r57r0000gn/T/vigeclones20121029-23346-1qx7yn.jpg[0]'
Command :: identify -format %m '/var/folders/j3/zdf8571x7cx8q0mwm2c_r57r0000gn/T/vigeclones20121029-23346-1qx7yn.jpg[0]'
Command :: convert '/var/folders/j3/zdf8571x7cx8q0m
Time.zone = ActiveSupport::TimeZone[-6].name
InterviewSlot.new(:start_time => Time.new(2012, 7, 7, 11, 30), :end_time => Time.new(2012, 7, 7, 12, 15))
got: "Saturday July 7th from 9:30 to 10:15 AM"
Time.zone = ActiveSupport::TimeZone[-5].name
InterviewSlot.new(:start_time => Time.new(2012, 7, 7, 11, 30), :end_time => Time.new(2012, 7, 7, 12, 15))
got: "Saturday July 7th from 10:30 to 11:15 AM"
Time.zone = ActiveSupport::TimeZone[-4].name
InterviewSlot.new(:start_time => Time.new(2012, 7, 7, 11, 30), :end_time => Time.new(2012, 7, 7, 12, 15))
#!bash
#
# bash completion support for core Git.
#
# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
# Distributed under the GNU General Public License, version 2.0.
#
# The contained completion routines provide support for completing:
#
class Email
def initialize(address)
@address = address
end
def address
@address.strip
end
class Invitation < ActiveRecord::Base
attr_accessible :email_body, :email_subject, :project_id, :email_addresses
attr_accessor :email_addresses
belongs_to :project
validates_presence_of :project, :email_subject, :email_body, :email_addresses
validate :email_addresses_are_valid
class Email
def initialize(address)
@address = address
end
def valid?
@address.match(email_regex)
end
validates_presence_of :name, :if => :require_name, :on => :update
validates_presence_of :email, :if => :require_email, :on => :update
validates_presence_of :phone, :if => :require_phone, :on => :update
def method_missing(name)
if name.to_s =~ /require_\w+/
project.present? && project.send(name)
else
super
end
@efatsi
efatsi / Gemfile
Created October 11, 2012 22:30 — forked from mackermedia/Gemfile
Capybara-webkit
group :test, :development do
gem 'capybara'
gem 'capybara-webkit'
gem 'database_cleaner'
end
@efatsi
efatsi / day.rb
Created September 28, 2012 21:10
Refactoring question
def has_a_thing_at(time)
any_events_at?(time) || any_interview_slots_at?(time) || any_free_slots_at?(time)
end
def any_events_at?(time)
events.where("start_time <= ? and end_time > ?", time, time).any?
end
def any_interview_slots_at?(time)
interview_slots.where("start_time <= ? and end_time > ?", time, time).any?