Skip to content

Instantly share code, notes, and snippets.

View cwcowellshah's full-sized avatar

Chris Cowell cwcowellshah

  • Portland, Oregon, USA
View GitHub Profile
@cwcowellshah
cwcowellshah / good_vs_bad.rb
Last active May 6, 2019 01:45
Good Ruby vs. Bad Ruby
# Here are two Ruby programs that do exactly the same thing. One is written to be readable and maintainable, and the other is not.
#
# BAD RUBY
#
d = Hash.new([])
File.foreach('scale_test_timing_log.csv') { |line| d[line.split(',')[2]] = d[line.split(',')[2]] << line.chomp.split(',')[3].to_f }
d.keys.sort.each { |act| File.open('a.csv', 'a') { |a| a.puts("#{act},#{((d[act].sort[((d[act].length - 1) / 2.0).floor] + d[act].sort[((d[act].length - 1) / 2.0).ceil]) / 2.0).round(1)},#{d[act].last},#{d[act].select { |elapsed_secs| elapsed_secs >= 4 }.length}") } }
@cwcowellshah
cwcowellshah / gist:216be03063bd71472f1e
Created April 30, 2015 21:04
crazy_stack_trace_when_running_cloverage
~/Documents/GitHub/classifier$ lein cloverage
Retrieving me/raynes/conch/0.5.0/conch-0.5.0.pom from central
Retrieving useful/useful/0.8.5-alpha2/useful-0.8.5-alpha2.pom from clojars
Retrieving spyscope/spyscope/0.1.3/spyscope-0.1.3.pom from clojars
Retrieving me/raynes/conch/0.5.0/conch-0.5.0.jar from central
Retrieving puppetlabs/certificate-authority/0.5.0/certificate-authority-0.5.0.jar from clojars
Retrieving spyscope/spyscope/0.1.3/spyscope-0.1.3.jar from clojars
Retrieving useful/useful/0.8.5-alpha2/useful-0.8.5-alpha2.jar from clojars
Retrieving puppetlabs/pe-rbac-service/0.1.13/pe-rbac-service-0.1.13-test.jar from releases
Retrieving puppetlabs/pe-rbac-service/0.1.13/pe-rbac-service-0.1.13.jar from releases
@cwcowellshah
cwcowellshah / assert logic inverter
Last active August 29, 2015 14:10
logic inverter for tests that are expected to fail
# @note Instead of commenting out a test or using skip_test(), use this!
#
# Tells an assert that it's supposed to fail due to a product bug, an
# undelivered feature, or some similar situation.
#
# This converts failing asserts into passing asserts (so we can continue to
# run the test even though there are underlying product bugs), and converts
# passing asserts into failing asserts (so we know when the underlying product
# bug has been fixed).
#