Skip to content

Instantly share code, notes, and snippets.

View purinkle's full-sized avatar

Rob Whittaker purinkle

View GitHub Profile
@purinkle
purinkle / keyword_argument_or_not.rb
Created May 28, 2023 17:40
When to use keyword arguments?
require "net/http"
class HttpWrapper
def post(url, body, headers)
Net::HTTP.post(URI.parse(url), body, headers)
end
end
url = "https://example.com/path"
body = {TEST_KEY: "TEST_VALUE"}
@purinkle
purinkle / naming-validations-after-predicate-methods.md
Created May 20, 2021 13:39
Naming Validations After Predicate Methods

Naming Validations After Predicate Methods

RSpec has many fantastic built-in matchers. One of my favourites is the [predicate matcher][1]. Not only does this matcher help make my tests more readable, but it also helps me design the name of my method.

You might decide to have a method like the following.

class SomeClass
@purinkle
purinkle / tap-your-stubs.md
Created April 19, 2021 12:58
How to use `#tap` to make your stubs more useful

Tap Your Stubs

When writing code that depends on another class, we sometimes like to stub out the dependency. This can result in test examples that are hard to read and full of details that aren't relevant to the actual test.

it "does something" do
  dependency = double(:dependency)
  allow(dependency).to receive(:foo).with(:bar).and_return(:baz)
  allow(Dependency).to receive(:new).and_return(dependency)
 
@purinkle
purinkle / README-Template.md
Created February 25, 2021 10:17 — forked from PurpleBooth/README-Template.md
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

Keybase proof

I hereby claim:

  • I am purinkle on github.
  • I am purinkle (https://keybase.io/purinkle) on keybase.
  • I have a public key ASCBX3cSW4htVNVeUi0VEq9n7Tce3B80eYBLIxlsUGibawo

To claim this, I am signing this object:

@purinkle
purinkle / index.js
Last active March 21, 2018 18:48
Fetching questionnaires
// appointments/actions.js
const doFetchedAppointmentQuestionnaires = (appointmentId, questionnaires) => ({
type: types.APPOINTMENT_QUESTIONNAIRES_FETCHED,
payload: { appointmentId, questionnaires },
});
const handleFetchQuestionnaires(appointmentId) = () => async dispatch => {
const questionnaires = await PatientApi.getQuestionnaires(appointmentId);
dispatch(doFetchedQuestionnaires(appointmentId, questionnaires));
@purinkle
purinkle / production_creation_responder.rb
Created March 24, 2017 16:26
An example of an extensible responder factory
class ProductCreationResponder
@@responders = []
def self.build(product)
responders.detect do |responder|
responder.applicable_to?(product)
end.new(product)
end
def self.register(responder)
# -*- encoding: utf-8 -*-
# Keyboard: Sample Bot
#
# Special bot controlled with the keyboard
#
# Controls:
# w drive forward
# s drive backwards
# a rotate left
# d rotate right
@purinkle
purinkle / ordered_jobs_spec.rb
Created November 18, 2011 16:30
A solution to Martin Rue's Ordered Jobs Kata
class Job
attr_reader :dependency, :name
def initialize(spec)
@name, @dependency = spec.split('=>').map(&:strip)
if @name == @dependency
raise ArgumentError
end
end