Payton.Codes

Musings on life, games, and code

Payton’s Blog

  • Avoiding Tightly-Coupled REST APIs

    Avoiding Tightly-Coupled REST APIs

    As you might have read, WordPress is getting a powerful REST API. For a few years now I’ve been writing endpoints for the WordPress.com version of this API, as well as few REST APIs in other languages (Ruby, JavaScript). As I’m also a big fan of unit testing, I’d like to share a pattern that…

  • get_deep_value in PHP

    get_deep_value in PHP

    Ever have an array in PHP that looks like this? It can be annoying to pull deep values from such an array because if you access an array key that doesn’t exist, PHP will throw an exception. You could check each level of the data using array_key_exists() like this: But that would take forever. PHP’s…

  • The “why” of writing tests

    The “why” of writing tests

    Unit testing is part of my normal development flow now. For the most part, I try to write my code in a “TDD” or “BDD” manner, meaning: I write my tests first, explaining how I want my public methods to behave, then follow it up with the actual code to make the tests pass. Years…

  • Using React stateless components for quick prototyping

    Using React stateless components for quick prototyping

    When you’re building a new app using React it’s nice to start laying out all the components you’ll want to use inside the components that you’re building. Unfortunately this can be a little slow because for each new component you have to: Create a new file Import that file Include React in the file Export…

  • Re-ordering Objects in a List

    Re-ordering Objects in a List

    In an old version of an app I wrote, I had a list of objects which were in a specific order. I wrote the app to operate using a REST API, so when you changed one of the objects, the client sent a PUT request to the server with the new data for that object…

  • ES2015 module re-exports

    Today’s episode of TIL (“Today I Learned”) is: Did you know you can re-export modules in ES2015 (aka: ES6, aka: new JavaScript)? That is, you can import a module and export it again all in one line of code. Why would you want to do this? Well, first you need to know about the way…

  • New Year’s D&D 

    Because what else would you do to celebrate? Roll for initiative, 2016.

  • The Stonecutter Samurai

    The Stonecutter Samurai

    Once a year Automattic gathers all its employees together for a week of projects, learning, and adventure at an event called the Grand Meetup. This year I wrote a D&D adventure to share with my friends and co-workers, most of whom had never played a tabletop RPG before. It’s now been run seven times (four by me)…