Skip to content

Instantly share code, notes, and snippets.

View markjlorenz's full-sized avatar

Mark Lorenz markjlorenz

View GitHub Profile
@markjlorenz
markjlorenz / 1_spec_output.markdown
Last active August 29, 2015 14:02
Not helpfull error message in rails.

A spec failure when TDDing a has_many_through:

1) Platform should have many interested_parties through platforms_interested_parties
   Failure/Error: it { should have_many(:interested_parties).through(:platforms_interested_parties) }
   NoMethodError:
     undefined method `class_name' for nil:NilClass

Not helpful. The problem here is that I've not yet wired up PlatformsInterestedParty.

@markjlorenz
markjlorenz / amazing_method_extraction.markdown
Last active August 29, 2015 14:02
An amazing method extraction

Pre-Extaction:

describe "email side effects" do
  it "sent an email to the PIC" do
    emails_to_pic = to_addresses.select { |to| to == pic.email }
    expect(emails_to_pic.size).to eq(1)
  end

  context "PIC is on vacation" do
    it "sent an email to the backup" do
@markjlorenz
markjlorenz / field_hand.markdown
Last active August 29, 2015 14:02
Explaining the FieldHand technique.

Introducing FieldHand!

disclaimer: Always try making the object graph less complex first.

[ed. I've renamed this to the FieldHand pattern, to avoid naming colisions]

The Problem: How do you build even moderatly complicated object graphs for request specs? Three things you don't want to do:

  1. Duplicate the setup, and linking of multple objects across different files.
  2. Have very long test files to avoid duplicate setup ( a.k.a fixing (1) the lazy way )
  3. Extracting let creation into a module. This may seem like a good idea at first, but it quickly becomes very hard to override the right let, and even harder to figure out what your test is doing.
@markjlorenz
markjlorenz / double_response.markdown
Last active August 29, 2015 14:02
Sending two HTTP responses to one request

Sending Two HTTP Responses to One Request

The Several Million Dollar Bug by Jacques Mattheij claims that while HTTP is designed to be synchronous, it is actually possible to send the response before the request has been made. I wanted to try that out. Here's a proof of concept in ruby:

#! /usr/bin/env ruby

require "socket"

server = TCPServer.new 3999
@markjlorenz
markjlorenz / no_gui.markdown
Created June 10, 2014 02:48
Running an xserver with no display attached

Can You Run an X11 Server with a Fake Display?

yes.

On The Server

sudo yum install xorg-x11-server-Xvfb
export DISPLAY=:1
Xvfb :1 -screen 0 1024x768x16 &
@markjlorenz
markjlorenz / the_wrench.markdown
Last active August 29, 2015 13:59
replace guard with a simple while-loop, fifo combination

The Wrench

mkfifo run_anything
while true; do sh -c "`cat run_anything`"; done

Example, running specs

@markjlorenz
markjlorenz / gpg_multiple_keys.markdown
Last active August 29, 2015 13:58
How gpg encryption works when multiple keys can decrypt the data.

http://tools.ietf.org/html/rfc4880#section-5.1

5.1. Public-Key Encrypted Session Key Packets (Tag 1)

A Public-Key Encrypted Session Key packet holds the session key used to encrypt a message. Zero or more Public-Key Encrypted Session Key packets and/or Symmetric-Key Encrypted Session Key packets may precede a Symmetrically Encrypted Data Packet, which holds an encrypted message. The message is encrypted with the session key, and the session key is itself encrypted and stored in the Encrypted

Keybase proof

I hereby claim:

  • I am dapplebeforedawn on github.
  • I am markjlorenz (https://keybase.io/markjlorenz) on keybase.
  • I have a public key whose fingerprint is C18E 5606 1E22 F30C 55AC 7621 9A97 9E13 C30D 6824

To claim this, I am signing this object:

@markjlorenz
markjlorenz / align.vim
Created February 28, 2014 21:02
align
" Alignment macros
nmap <Leader>a= :Tabularize /=\(>\)\@!<CR>
vmap <Leader>a= :Tabularize /=\(>\)\@!<CR>
nmap <Leader>a> :Tabularize /=><CR>
vmap <Leader>a> :Tabularize /=><CR>
nmap <Leader>a: :Tabularize /:\zs<CR>
vmap <Leader>a: :Tabularize /:\zs<CR>
nmap <Leader>a{ :Tabularize / \zs{<CR>
vmap <Leader>a{ :Tabularize / \zs{<CR>
class FaxThing
DEFAULT_API_KEY = "default-key".freeze
attr_accessor :to
attr_accessor :pdf
attr_accessor :subject
attr_accessor :api_key
def initialize opts={}
opts = opts.symbolize_keys