Blog

  1. Word Boundaries and Lookahead Assertions

    As I was trying to improve the lexer for postcss-calc, I learnt about two regular expression features: the word boundary anchor character and lookahead.

  2. Word Boundaries and Lookahead Assertions

    As I was trying to improve the lexer for postcss-calc, I learnt about two regular expression features: the word boundary anchor character and lookahead.

  3. How large is a Buffer?

    The gzip() and gzipSync() functions in the zlib return a result of type Buffer. How do you calculate the size of the result? I came across two properties of the Buffer type: length and byteLength. Is there a difference? The API documentation for Buffer does not tell you, because it lacks the length and byteLength properties. Where do these properties come from? Likely from the prototype.

  4. Scripting in Java?

    Since Java 11, you can run a Java program without compiling it first. Can you script in Java like in Python?

  5. Migrate a Node.js project to ESM

    To use an ESM Node.js module in your own, you need to use import. But node can only use import inside ESM modules, so you need to convert your own CommonJS modules to ESM. Writing import and converting it to require() with Babel does not count! Otherwise you will get an error like this: SyntaxError: Cannot use import statement outside a module So, how do you migrate your code to use import instead of require()?

  6. Invasion of the Killer Retries

    How can you bring your web application down? For example, by trying to make it more reliable.

  7. Docker cheatsheet

    Here’s how to perform some common tasks with Docker.

  8. Dive into esbuild

    To prepare your frontend code for production, you can use esbuild. Compared to webpack or rollup, esbuild offers limited code splitting options, but if your JavaScript code is mostly used on one page, esbuild can be a good solution.

  9. Secrets of CSS modules

    With a frontend framework like Next.js or just a bundler like webpack, you can import the CSS class names from a CSS module as if importing variables from a JavaScript module. For example, if your CSS file contains this code: // styles.css someClass { background-color: blue; } you can apply the someClass class to an HTML element from a JavaScript file by importing the class name: // main.js import { someClass } from '.

  10. Technical Writing Tips

    Writing my React book has been humbling: I wasn’t as good a writer as a I imagined. Here’s some what I’ve learnt working with my editor.

  11. Backing up MySQL with Percona XtraBackup

    The logical backup created by mysqldump was just 430MB. but for testing I wanted to repeatedly tear down and restore the same database. The restore was too slow even after disabling foreign key checks and unique checks.

    I decided to try Percona XtraBackup. Here’s how I completed a full backup and restore. For incremental backups, you must do things a little differently, but I won’t handle incremental backups in this post.

  12. The Sociology of Input Validation

    Maybe writing programs that accept whatever data comes in, and dealing with the consequences later, isn’t as sloppy as it sounds.

  13. Havoc with Hibernate Filters and Inheritance

    After migrating from Hibernate 3.6 to Hibernate 5.2, our web framework would sometimes fail mysteriously to bind controller method arguments to the corresponding persistent entity. The cause turned out to be an obscure interaction between JPA’s single table inheritance and a misconfigured Hibernate filter.

  14. Smart Mistakes Are the Worst

    When writing bad code, playing smarter sometimes gives the worst results.

  15. How to wrap a web REST API

    When calling into a third-party REST API, it’s OK to define high- and low-level operations, and leave out the middle.

  16. Lone Heroes on Software Projects

    On a software project, communicate to colleagues, managers and clients when you’re in trouble:

  17. Bit Twiddling

    Bit operations preserve De Morgan’s laws. Bit values are sequences of symbols. What makes them behave like booleans? Where does the essence of a boolean lie?

  18. Validate like a Native with React

    Validating a form doesn’t always require a lot of code. With HTML5 constraint validation, you can describe form validation rules with HTML attributes on the form fields.

    For example, to enforce that an <input> element should not be empty, add the required attribute to the element:

    <input id="name" name="name" required/>
    

    You can use HTML5 constraint validation even with React. Let’s look at an example.

  19. How to turn an HTML form into JSON

    To send data from an HTML form to a JSON API, you can extract all the form data in one go with form-serialize.

  20. React and refs, an eternal love story

    As in our previous exercise, we want to get the DOM node for a form component to validate the form with the HTML constraint validation API.

    Since React 16.3, we can store references to DOM nodes with React.createRef(). Let’s repeat the exercise with the new API.