Passing Elements as Props in React

I like this nuanced post by David Barral in which he goes over all the options on how to configure a Confirm component: what exactly do you pass in as props. In this story we are going to see a simple technique that allows you to write friendly customizable components with simple APIs, just by …

The Power of the JSON.stringify() replacer parameter

As previously detailed (2013 😱), you can use JSON.stringify()‘s second replacer parameter to pluck specific fields from it, by passing in an array: var person = {"name":"Jim Cowart","location":{"city":{"name":"Chattanooga","population":167674},"state":{"name":"Tennessee","abbreviation":"TN","population":6403000}},"company":"appendTo"}; JSON.stringify(person, ["name", "company"], 4); // ~> "{ // "name": "Jim Cowart", // "company": "appendTo" // }" As Pawel explains the parameter can also be a function, to …

Manage React State with zustand

Small, fast and scaleable bearbones state-management solution. Has a comfy api based on hooks, that isn’t boilerplatey or opinionated, but still just enough to be explicit and flux-like. import create from 'zustand' const [useStore] = create(set => ({ count: 1, inc: () => set(state => ({ count: state.count + 1 })), dec: () => set(state …

Building a Website Screenshot API with Puppeteer and Google Cloud Functions

Here’s the source of a Google Cloud function that, using Puppeteer, takes a screenshot of a given website and store the resulting screenshot in a bucket on Google Cloud Storage: const puppeteer = require('puppeteer'); const { Storage } = require('@google-cloud/storage'); const GOOGLE_CLOUD_PROJECT_ID = "screenshotapi"; const BUCKET_NAME = "screenshot-api-net"; exports.run = async (req, res) => { …

Automatically upgrade your PHP code from 5.3 to PHP 7.4 with Rector

Rector is a reconstructor tool – it does instant upgrades and instant refactoring of your code. Why refactor manually if Rector can handle 80% for you? Installation per Composer: composer require rector/rector –dev For example, to upgrade the contents of the ./src folder: vendor/bin/rector process src –set php74 The cool thing is that Rector uses …

Emulate Dark Mode using Chrome DevTools

Coming to the next version of Chrome is a way to emulate “Dark Mode” using the DevTools. With the DevTools open and focused, hit SHIFT+CMD+P and choose “Emulate CSS prefers-color-scheme: dark” from the menu You can also access the option via the Rendering panel. (Via @ChromeDevTools)

Inversion of Control

Photo by Jasper Garrat on Unsplash In his post “Inversion of Control” Kent C. Dodds starts off with a simple filter function and how it can quickly become a mess as features creep in. Using IoC it’s possible to keep the implementation, diverting some responsibilities away from it: We changed the responsibility of deciding which …

Use C, Rust, Go, etc. code inside PHP with “Foreign Function Interface“ (PHP FFI)

A new extension that comes with PHP 7.4 (which was released today 🎉) is Foreign Function Interface. On the JoliCode Paris website there’s a nice article introducing it: PHP Foreign Function Interface, or FFI for fans, is a PHP extension that allows you to include with ease some externals libraries into your PHP code. That …