Skip to content

Instantly share code, notes, and snippets.

View bkeepers's full-sized avatar

Brandon Keepers bkeepers

View GitHub Profile
@bkeepers
bkeepers / api_spec.rb
Created September 20, 2013 15:41
Use HyperClient to test your Hypermedia API
# spec/features/api_spec.rb
require 'spec_helper'
describe 'API' do
class TestClient < Hyperclient::EntryPoint
def default_faraday_block
lambda do |faraday|
faraday.request :json
faraday.response :json, content_type: /\bjson$/
faraday.adapter :rack, Capybara.app
// Turn any function calls on a promise into function calls on the result.
//
// For example:
//
// serialPromise(promise).foo();
//
// Is the same as calling:
//
// promise.then(result => result.foo());
//

This post has sat as a draft on my computer for well over a year now. I always intended to finish it, but am beyond caring. So I’m just going to publish it in its current form in hopes that it sparks some interesting conversation and avoids beating a dead horse.

Cucumber is a divisive tool. Some people absolutely love it and have an irrational dedication to using it for every single project. Others hate it, either because they haven’t tried it, or tried it on one project and ended up with a steaming pile of sh…step definitions.

I’ve been using cucumber since one of the first few releases. While I have been burned by it on projects, I also have a great appreciation for it.

What’s wrong with cucumber? Technically, nothing. It’s a brilliant tool for creating DSLs to test our applications. The problem with cucumber is YOU: you don’t understand why to use it, when to use it or how to use it. Don’t worry, though, it’s not entirely your fault. Many people are responsible f

@bkeepers
bkeepers / gist:8337479
Created January 9, 2014 16:45
Follow link without sending referrer.
//= require lib/jquery
//= require csrf
function openWithoutReferrer(url) {
var site = window.open("", "hide_referrer");
site.document.open();
site.document.writeln('<script type="text/javascript">window.location = "' + url + '";</script>');
site.document.close();
}
@bkeepers
bkeepers / gist:6502229
Last active December 22, 2015 16:49
My micro-talk to the Grand Rapids Ruby Group on separating code and configuration.
/$$$$$$ /$$$$$$ /$$ /$$ /$$$$$$$$ /$$$$$$ /$$$$$$
/$$__ $$ /$$__ $$| $$$ | $$| $$_____/|_ $$_/ /$$__ $$
| $$ \__/| $$ \ $$| $$$$| $$| $$ | $$ | $$ \__/
| $$ | $$ | $$| $$ $$ $$| $$$$$ | $$ | $$ /$$$$
| $$ | $$ | $$| $$ $$$$| $$__/ | $$ | $$|_ $$
| $$ $$| $$ | $$| $$\ $$$| $$ | $$ | $$ \ $$
@bkeepers
bkeepers / gist:6002211
Last active December 19, 2015 18:58
I'm looking for a better pattern for defining a method that takes a single object or an array of objects as an argument, does something with them, and then returns either a single object or an Array depending on what was passed to it.
def dress(dog_or_dogs)
dressed_dogs = Array(dog_or_dogs).map {|dog| DogSweater.new(dog) }
dog_or_dogs.respond_to?(:each) ? dressed_dogs : dressed_dogs.first
end
one_dog = dress(Dog.new)
all_my_dogs = dress([Dog.new, Dog.new, Dog.new])
@bkeepers
bkeepers / twithubbers.sh
Created June 4, 2013 14:29
Create a list of GitHubbers and follow all of them.
#!/bin/sh
#
# Requires the `t` gem: https://github.com/sferik/t
#
# gem install t
#
if [ -z $(t lists | grep -i githubbers) ]
then
t list create GitHubbers
@bkeepers
bkeepers / iframe.html
Created April 4, 2012 02:24
demo of window.sendMessage
<html>
</html>
# puts (1..100).to_a.shuffle.inspect
class Array
def shuffle
size.downto(1) { |n| swap(n - 1, rand(n)) }
self
end
def swap(x, y)
self[x], self[y] = self[y], self[x]
end
@bkeepers
bkeepers / gist:1901470
Created February 24, 2012 15:01
Spine Collections
class Message extends Spine.Model
@configure 'Message', 'text'
class Mentions extends Spine.Collection
@configure Message
@extend Spine.Model.Ajax
@url: '/messages/mentions'