Skip to content

Instantly share code, notes, and snippets.

View philsturgeon's full-sized avatar
🌳
Planting Trees

Phil Sturgeon philsturgeon

🌳
Planting Trees
View GitHub Profile
@philsturgeon
philsturgeon / 0-intro.md
Last active June 7, 2018 09:34
PSR-2 v CodeSniffer PSR-2

This is a list of issues or discrepencies between the wording or intention of PSR-2 itself and the CodeSniffer PSR-2 ruleset.

Add suggestions in the comments or tweet me (@philsturgeon) if you have more inconsistencies to report.

@philsturgeon
philsturgeon / Gemfile
Created December 14, 2017 17:48
Faraday Adapters Benchmark
source 'https://rubygems.org'
gem 'faraday'
gem 'net-http-persistent'
gem 'typhoeus'
gem 'patron'
gem 'httpclient'
gem 'net-http2'
@philsturgeon
philsturgeon / wtf.md
Last active December 7, 2017 18:44
Postman disagrees with itself

Hey, I’m super lost.

Currently im trying to make API Flow work:

luckymarmot/API-Flow#149

There is an output.json which is a test case, and accoring to Postmans JSON Schema it is invalid.

I'm fixing a few (headers cannot have a null value) but the auth section is triggering errors. It looks like this:

@philsturgeon
philsturgeon / gist:bfabe7461ec6faf9457b6a75f25c0d9c
Created August 7, 2017 20:29
The most basic-ass presenter ever
class Api::V3::CompanyPresenter
attr_accessor :company, :includes
def initialize(company, includes: [])
@company = company
@includes = Array(includes)
end
def as_json
{
@philsturgeon
philsturgeon / gist:64f7b611a035084b39673853c7e43f0d
Last active June 8, 2017 16:54
Janky Quick Example of RPC API being cool

POST /check-v1

Request

{
  "user_uuid" : "12345",
  "policy_action" : "do-a-thing"
}

Taken verbatim from https://www.congress.gov/bill/114th-congress/house-bill/2029/text

   TITLE <<NOTE: Visa Waiver Program Improvement and Terrorist Travel 
  Prevention Act of 2015.>>  II--TERRORIST TRAVEL PREVENTION AND VISA 
WAIVER PROGRAM REFORM
SEC. 201. <<NOTE: 8 USC 1101 note.>> SHORT TITLE.

    This title may be cited as the ``Visa Waiver Program Improvement and 
Terrorist Travel Prevention Act of 2015''.
@philsturgeon
philsturgeon / fucking-tests.sh
Created November 2, 2016 19:51
Get those tests outta here!
bundle exec rspec | grep -ohi 'rspec \./[^\:]*' | sed -e 's/^rspec //' | while read f; do [[ -a "$f" ]] && git rm "$f"; done
@philsturgeon
philsturgeon / options.md
Created October 20, 2016 14:28
RESTful Liking

Option 1

Modifying a global resource can feel a bit weird, but essentially as an authorized user, you are looking at your customized representation of the resource, and not just a direct 1:1 of whats in the database.

  • Like: PATCH /bars/123 with field liked: true
  • Unlike: PATCH /bars/123 with field liked: false

This can feel a bit weird if you consider it as corrupting the global value, but headers often change the response and that's probably fine. It can be weird to show different attributes depending on the user (I avoid this) but you can probably jam it in meta as the JSON-API allows this already? It's relevant data, just not necessairily part of the resource.

Option 2

@philsturgeon
philsturgeon / talk.md
Created March 31, 2016 21:53
What Rails Can Teach PHP About Building APIs

As somebody who's built APIs with PHP since 2009, and built APIs with Rails for the last two years, the contrast in some of the tooling available is mind-blowing. When it comes to factories for generating test data, spec-driven testing with tools like RSpec, mutation testing, simplistic state machines, serialization and deserialization in JSON-API, REPL debugging with breakpoints, file upload handlers, etc., Ruby (and Rails) very often has a strong lead in maturity of the tooling.

Objectively speaking, PHP either does not have some of these tools, or they're immature in comparison. This is by no means a fault of PHP as a language or a community. Ruby has had Gems for far longer than PHP has had Composer, and while PHP is starting to learn how to get this done in a post-framework-everything world, it has a way to go.

This talk looks at some of the cool stuff Ruby can do, and some of the lesser known tools that provide similar functionality in PHP.

@philsturgeon
philsturgeon / example.php
Created March 16, 2016 18:27 — forked from anonymous/example.php
Instance variable type checking needed?
<?php
class Example
{
public $number;
public $text;
public function __construct(int $number, string $text)
{
$this->number = $number;