Skip to content

Instantly share code, notes, and snippets.

require 'nokogiri'
require 'net/http'
class ShakespeareAnalyzer
def initialize(url)
@url = url
end
def analyze
speech_elements.inject({}) do |result, element|
@jferris
jferris / rewrite_redirects.hs
Last active December 19, 2015 17:09
Find URLs that redirect in stdin and replace them with their target URL in stdout
import Control.Applicative
import Data.List.Utils
import Data.Maybe
import Network.HTTP
import Network.HTTP.Headers
import System.IO
import Text.Regex.PCRE
main = do
line <- getLine
@jferris
jferris / guard
Created July 10, 2013 19:27
Example Bundler binstub
#!/usr/bin/env ruby
#
# This file was generated by Bundler.
#
# The application 'guard' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require 'pathname'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
@jferris
jferris / .vimrc
Created May 23, 2013 15:50
Per-project path settings to make :find more useful
" Lives inside a project directory
setl path+=lib/events
setl path+=lib/advertiser
setl path+=lib/model_view
@jferris
jferris / array_matching.rb
Created May 13, 2013 19:06
Example: custom rspec-mocks argument matcher
module ArrayMatching
class ArrayMatching
def initialize(array)
@array = array
end
def ==(other_array)
Set.new(@array) == Set.new(other_array)
end
class InspectorGadget < BasicObject
def initialize(target, notifier)
@target = target
@notifier = notifier
end
def method_missing(name, *args, &block)
result = @target.public_send(name, *args, &block)
@notifier.invocation(name, args, block, result)
result
@jferris
jferris / filters.rb
Created March 11, 2013 16:36
Duplication for method calls vs before_filters
# Filters
# Action name is duplicated in filter blacklist or whitelist
class PoniesController < ApplicationController
before_filter :find_pony, except: [:index]
before_filter :authorize_rider, only: [:edit, :update, :destroy]
def show
end
def index
require 'spec_helper'
describe 'products/_prime_purchase.html.erb' do
it "tries to sell the user on Prime" do
view.stubs(currently_viewing_subscription_product?: false)
view.stubs(current_user_has_active_subscription?: false)
view.stubs(subscription_product: stub('subscription_product', name: 'foo'))
render template: 'products/_prime_purchase'
@jferris
jferris / date.js
Created October 22, 2012 17:08
Causes warnings with ctags 5.8
/**
* Version: 1.0 Alpha-1
* Build Date: 13-Nov-2007
* Copyright (c) 2006-2007, Coolite Inc. (http://www.coolite.com/). All rights reserved.
* License: Licensed under The MIT License. See license.txt and http://www.datejs.com/license/.
* Website: http://www.datejs.com/ or http://www.coolite.com/datejs/
*/
Date.CultureInfo={name:"en-US",englishName:"English (United States)",nativeName:"English (United States)",dayNames:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],abbreviatedDayNames:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],shortestDayNames:["Su","Mo","Tu","We","Th","Fr","Sa"],firstLetterDayNames:["S","M","T","W","T","F","S"],monthNames:["January","February","March","April","May","June","July","August","September","October","November","December"],abbreviatedMonthNames:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],amDesignator:"AM",pmDesignator:"PM",firstDayOfWeek:0,twoDigitYearMax:2029,dateElementOrder:"mdy",formatPatterns:{shortDate:"M/d/yyyy",
@jferris
jferris / copr.rb
Created October 19, 2012 13:34
Check out pull requests from the command line
#!/usr/bin/env ruby
require 'rubygems'
require 'json'
require 'net/https'
require 'fileutils'
def usage
puts "usage: copr project_name id"
puts "example: copr capybara-webkit 316"