Skip to content

Instantly share code, notes, and snippets.

View gabetax's full-sized avatar

Gabe Martin-Dempesy gabetax

  • Zendesk
  • San Francisco
  • 07:10 (UTC -07:00)
View GitHub Profile
require 'benchmark'
def measure(gc: false, times: 1000, &block)
GC.start
GC.disable if gc
gc_key = if RUBY_VERSION > 2.2
:total_allocated_objects
else
:total_allocated_object
@gabetax
gabetax / json_pluck.rb
Last active February 1, 2016 18:45
Pluck values out of JSON logs
#!/usr/bin/env ruby
require 'json'
# Usage:
# head production.log.json | ruby json_pluck.rb time,session,message
# colorize output when going to stdout or if explicitly requested (e.g. `| less -r`)
color = $stdout.tty?
color = true if ARGV.first == '-c' && ARGV.shift
#include <FastLED.h>
//#define LED_PIN 5
#define DATA_PIN 9
#define CLOCK_PIN 8
#define NUM_LEDS 300
#define BRIGHTNESS 64
#define LED_TYPE APA102
#define COLOR_ORDER BGR
CRGB leds[NUM_LEDS];
@gabetax
gabetax / hacky_each_else.rb
Created January 13, 2014 03:03
Hacky alternative to ruby not having each/else. Object#presence provided by active_support.
a = %w(a b c)
a.each do |i|
puts i
end.presence || puts("the array was empty")
@gabetax
gabetax / deploy.rb
Last active December 27, 2015 05:19 — forked from blackcoat/deploy.rb
# http://gembundler.com/deploying.html
require 'bundler/capistrano'
# http://guides.rubyonrails.org/asset_pipeline.html
load 'deploy/assets'
# http://beginrescueend.com/integration/capistrano/
# Also add rvm-capistrano to your Gemfile
require "rvm/capistrano" # Load RVM's capistrano plugin.
set :rvm_type, :system # Copy the exact line. I really mean :system here
@gabetax
gabetax / _form.html.erb
Created October 11, 2013 16:51
Javascript Page Object Example
<% @body_data = {
page_object: 'PostForm',
rails_env: Rails.env,
post_max_length: Post.column_types['title'].limit
}
%>
@gabetax
gabetax / .ackrc
Created September 27, 2013 21:22
ack configuration for ruby / rails developers
--type-add=html:ext:html.erb
--type-add=css:ext:sass,less,scss
--type-add=js:ext:js.erb,coffee
--type-add=rspec:match:/_spec.rb$/
--ignore-dir=vendor
--ignore-dir=log
--ignore-dir=tmp
--ignore-dir=coverage
--ignore-dir=public/assets
--ignore-dir=spec/fixtures/cassettes
module FeatureSpecMacros
module ExampleMethods
def successfully_visit(path)
visit path
successfully_on path
end
def successfully_on(path)
expect(page.current_path).to eq(path), "Expected: #{path} URL\nGot #{page.current_path}\n\nPage source:\n\n#{page.html}"
expect(page.status_code).to eq(200), "Expected: 200 status code\nGot #{page.status_code}\n\nPage source:\n\n#{page.html}"
@gabetax
gabetax / rspec-expect-stand-alone-matchers.md
Last active December 20, 2015 16:18
rspec expect-syntax, stand-alone operators, and you

rspec expect syntax and stand-alone operator matches

I recently started a new project using rspec's newer (and soon to be default) expect syntax, and encountered this error:

expect(5).to == 5
ArgumentError: The expect syntax does not support operator matchers, so you must pass a matcher to `#to`

"Why'd they take out operator matches? I've grown quite accustomed to them!", I thought. Digging around, the source of this change started in pull request 119 citing issue 138 as one of the root causes. Here's what's actually happening:

@gabetax
gabetax / pretzel.rb
Last active December 19, 2015 00:29
https://twitter.com/garybernhardt/status/349920138889404416
[1] pry(main)> class Object; alias_method :&, :method; end
=> Object
With standard symbol to proc, &:foo evaluates to:
{ |x| x.foo }
With the "pretzel bun", &foo&:bar evaluates to: