Skip to content

Instantly share code, notes, and snippets.

View timlinquist's full-sized avatar

Tim Linquist timlinquist

View GitHub Profile
require 'uri'
require 'digest/sha1'
class BitlyURLRewriter
DOMAIN = "later.ly"
def update_domain(url)
URI.parse(url).tap { |uri| uri.host = "later.ly" }
end
@timlinquist
timlinquist / gist:3660384
Created September 6, 2012 21:08 — forked from steveburkett/gist:3659891
testing ensure
class TolerantFetcher
def self.get(url)
TimeoutNinja.try do
timeout(20) do
begin
handle = open(url)
response = handle.read
ensure
handle.try(:close!) ####### HERE
end
@timlinquist
timlinquist / custom_listener.rb
Created March 5, 2012 23:38
Custom listener for the selenium webdriver
#Used in the common/driver.rb of selenium-webdriver
L45 def for(browser, opts = {})
.....
class SeleniumListener
attr_reader :file
@timlinquist
timlinquist / env.rb
Created February 29, 2012 01:02
Use default profile w/selenium webdriver
# Excerpt from features/env.rb for customizing selenium to be ran via capybara
.......
require 'cucumber/rails'
require 'selenium-webdriver'
# Use default profile for Firefox
# By default, selenium uses an anonymous profile so none of your settings will be enabled
# It is smart to setup a 'selenium' or 'test' profile to reduce the configurations you
# would set as a normal user of Firefox.
#
@timlinquist
timlinquist / play.coffee
Created February 15, 2012 23:08
Playing around with coffee script
class OptionHandler
constructor: (@options) ->
@options or= {}
class Inverter extends OptionHandler
invert: () ->
for key, value of @options
@options[key] = null
@options[value.toLowerCase()] = key
@timlinquist
timlinquist / flog.out
Created January 18, 2012 03:27
Flog score of refactored worker
flog app/workers/campaign_worker.rb
14.9: flog total
7.5: flog/method average
13.8: CampaignWorker::perform app/workers/campaign_worker.rb:4
@timlinquist
timlinquist / whoa.out
Created January 15, 2012 04:31
gem dependencies
.......
Installing rake (0.9.2)
Installing Saikuro (1.1.0)
Installing SystemTimer (1.2.3) with native extensions
Installing aasm (2.2.0)
Installing abstract (1.0.0)
Installing activesupport (3.0.10)
Installing builder (2.1.2)
Installing i18n (0.5.0)
Installing activemodel (3.0.10)
class CucumberExternalResqueWorker
DEFAULT_STARTUP_TIMEOUT = 1.minute
COUNTER_KEY = "cucumber:counter"
class << self
attr_accessor :pid, :startup_timeout
def start
# Call from a Cucumber support file so it is run on startup
return unless Rails.env.cucumber?
@timlinquist
timlinquist / circular_reference.rb
Created January 11, 2012 00:51
Class that detects when something may indeed have a circular reference
class CircularReferenceDetector
attr_reader :block
def initialize(&block)
@block = block
end
def circular? node, visited=[]
return true if visited.include? node
node.extend SmartNil
@timlinquist
timlinquist / github_clone_url_regex.java
Created January 9, 2012 19:46
Valid clone urls for jenkins github hook plugin
private static final Pattern[] URL_PATTERNS = {
Pattern.compile("git@(.+):([^/]+)/([^/]+).git"),
Pattern.compile("https://[^/]+@([^/]+)/([^/]+)/([^/]+).git"),
Pattern.compile("git://([^/]+)/([^/]+)/([^/]+).git"),
Pattern.compile("ssh://git@([^/]+)/([^/]+)/([^/]+).git")
};