Skip to content

Instantly share code, notes, and snippets.

View srawlins's full-sized avatar

Sam Rawlins srawlins

View GitHub Profile
@srawlins
srawlins / args-changes.markdown
Last active August 29, 2015 14:06
Dart args SDK changes example

args/args

New class 'OptionType'

ArgParser

The 'addOption' method has a new parameter: { dart-core.String valueHelp: false }

@srawlins
srawlins / gist:d03d7309b8b9ef22c980
Created September 2, 2014 00:38
Broken links on dartlang.org as of 2014-09-01
$ wget --spider -o ./broken-links.txt -e robots=off -w 1 -r -p https://www.dartlang.org/
$ cat broken-links.txt |grep -B 2 '404 Not'
--2014-09-01 17:08:11-- https://www.dartlang.org/articles/writing-unit-tests-for-pub-packages/
Reusing existing connection to www.dartlang.org:443.
HTTP request sent, awaiting response... 404 Not Found
--
--2014-09-01 17:13:48-- https://www.dartlang.org/articles/benchmarking/
Reusing existing connection to www.dartlang.org:443.
HTTP request sent, awaiting response... 404 Not Found
@srawlins
srawlins / gist:5b0fe367cd3a412e6925
Created May 22, 2014 00:14
Slowdown due to proposed Coverage changes ruby bug #9508

Slowdown of Mail specs due to use of Coverage

$ git clone [email protected]:mikel/mail.git $ cd mail $ bundle $ time bundle exec rake

  • w/o Coverage: 10.5 sec.
  • w/ current Coverage library: 12 sec (14% increase).
  • w/ proposed Coverage library: 16.5 sec (57% increase over "w/o Coverage", 38% increase over "current Coverage").
@srawlins
srawlins / gist:9244013
Created February 27, 2014 03:47
Reduce allocations during mail gem's specs
Before:
Top 10 allocation sites:
String allocations at <PWD>/lib/mail/utilities.rb:180
4639 allocations during ./spec/mail/attachments_list_spec.rb:312
...
Array allocations at <PWD>/lib/mail/parsers/received_parser.rb:13
2326 allocations during ./spec/mail/message_spec.rb:1627
...
String allocations at <PWD>/lib/mail/fields/common/common_field.rb:46
2269 allocations during ./spec/mail/fields/content_type_field_spec.rb:198
@srawlins
srawlins / curries.rb
Created February 22, 2014 00:20
flexible curry for Procs and methods in Ruby
def curry(prc, *args)
Proc.new { |*remaining| prc.call(*args.map { |arg| arg || remaining.shift }) }
end
def curry_m(m, n, *args)
define_method(m, curry(method(n), *args))
end
power = ->(a,b){ "#{a}**#{b} is #{a**b}" }
square = curry power, nil, 2
@srawlins
srawlins / obscure-gz-writing.rb
Last active December 19, 2015 12:09
Example of rack #571
require 'stringio'
require 'zlib'
GZ_FILE = "rack-issue-571.gz"
class VerboseStringIO < StringIO
attr_accessor :log
def initialize(*args)
@log = []
require "mechanize"
a = Mechanize.new { |agent| agent.user_agent_alias = 'Mac Safari' }
a.get("https://www.google.com/") do |page|
puts page.at("#gbqfq").inspect
end
require "mechanize"
@srawlins
srawlins / jqAddAndRemoveClass.js
Created March 8, 2013 01:02
Even if you don't have jQuery available, you can use the add and removeClass() functions!
function jQaddClass( elem, value ) {
var newClass = value;
if ( elem.nodeType === 1 ) {
if ( !elem.className ) {
elem.className = value;
} else {
var className = " " + elem.className + " ", setClass = elem.className;
if ( className.indexOf( " " + newClass + " " ) < 0 ) {
@srawlins
srawlins / commaize.rb
Created February 28, 2013 01:09
Method chaining can still _be_ magical, and not have to _look_ like magic.
number = 1234567
# Chaining methods more than once-ish is confusing; the developer has to keep
# in mind wtf is going on:
number.to_s.reverse.split(//).each_slice(3).map(&:join).join(',').reverse
# Commenting the state of each chain helps:
number.to_s. # String, e.g. "1234567"
reverse. # reverse it, e.g. "7654321"
split(//). # split on every character, e.g. ["7", "6", "5", "4", "3", "2", "1"]
@srawlins
srawlins / adhoc-fyi.rb
Created September 13, 2012 01:15
Automated Ad Hoc Router for Kuali Coeus
require 'rubygems'
require 'capybara'
require 'capybara/dsl'
require 'highline/import'
require 'uri'
class AdHoccer
include Capybara::DSL
def initialize(url, recipient)