RSSAmplifier

Blog

sitr.us - posts by Jesse Hallett

posts by Jesse Hallett

github.comRSS feed ↗33 posts

Latest posts

Nix, NPM, and Dependabot

I have a project, git-format-staged , that I build with Nix. It includes NPM dependencies, and it is convenient to have Dependabot keep those up-to-date for me. Dependabot creates pull requests that update package-lock.json when it sees updates with security fixes and such. But my Nix configuration includes a hash of the project NPM dependencies - that hash must be updated when package-lock.json…

`void` is not a unit type in TypeScript

In type theory a unit type is any type that represents exactly one possible value. The unit types in TypeScript include null , undefined , and literal types. TypeScript also has the type void which is used as the return type for functions that don't have an explicit return value. In JavaScript a function that does not explicitly return implicitly returns undefined ; so at first glance it…

Choosing a headless CMS

This is an excerpt of a post that I wrote for my employer, Originate . One of our recent projects called for a feature to allow editors to manage and publish content. In other words, we needed a CMS. We already had a React-based web app, and a React Native mobile app in the works where we wanted to present that content. So we needed a Headless CMS. Unlike Wordpress or other traditional CMS…

When to use `never` and `unknown` in TypeScript

This is an excerpt of a post that I wrote for LogRocket . The never and unknown primitive types were introduced in TypeScript v2.0 and v3.0 respectively. These two types represent fundamental and complementary aspects of type theory. TypeScript is carefully designed according to principles of type theory, but it is also a practical language, and its features all have practical uses – including…

Automatic Code Formatting for Partially-Staged Files

This is an excerpt of a post that I wrote for Olio Apps . I wrote git-format-staged to apply an automatic code formatter or linter to staged files. It ignores unstaged changes, and leaves those changes unstaged. When run in a Git pre-commit hook git-format-staged guarantees that committed files are formatted properly, and does not clobber unstaged changes if formatting cannot be applied to working…

I finally set up XMonad to build with Stack!

The XMonad window manager is configured in Haskell. That means that when you want to apply a new configuration you actually build xmonad itself incorporating code from your configuration file. It sounds more painful than it is - when you install xmonad you get an executable called xmonad that handles the details of bootstrapping your custom build. The command xmonad --recompile builds…

Checking Types Against the Real World in TypeScript

This is an excerpt of a post that I wrote for Olio Apps . The shape of data defines a program. There are important benefits to writing out types for your data. Let’s consider a Hacker News client, which consumes stories and other items from the Hacker News API. This is a TypeScript type that describes the format for stories: In Javascript and other dynamically-typed languages, it is common to…

Type-Driven Development with TypeScript

This is an excerpt of a post that I wrote for Olio Apps . I am always interested in making my coding process faster and more robust. I want to be confident that my code will work as expected. And I want to spend as little time as possible debugging, testing, and hunting down pieces of code that I forgot to update when I make changes to a project. That is why I am a fan of correct-by-construction…

What is Poodle

This is a description of my passion project. I plan to publish more detail and motivation when I get to a minimum viable product. I want to make social collaboration software without walls. A company can have its private discussions and documents - but people in a company should be able to include clients or contractors in discussions seamlessly. It should not be necessary to require people to…

Changes I would make to Go

I have been programming primarily in Go for about six months. I find it frustrating. There are two reasons for this: First, functional programming is particularly difficult in Go. In fact the language discourages functional programming . This frustrates me because the imperative code that I write requires a lot of boilerplate, and I think it is more error-prone than it could be if I could use…

Flow Cookbook: Flow & React

This recipe is part of the Flow Cookbook series. Flow and React are both Facebook projects - so as you might imagine, they work quite well together. React components can take type parameters to specify types for props and state. Type-checking works well with both functional and class components . Flow type annotations provide an alternative to propTypes runtime checks. Flow's static checking…

Flow Cookbook

Type-checking can be a useful asset in a Javascript project. A type checker can catch problems that are introduced when adding features or refactoring, which can reduce the amount of time spent debugging and testing. Type annotations provide a form of always-up-to-date documentation that makes it easier for developers to understand an unfamiliar code base. But it is important to use type-checking…

Flow Cookbook: Unpacking JSON API data

This recipe is part of the Flow Cookbook series. Hacker News provides a public API . One of the endpoints of that API accepts an ID and responds with an item: Here is an example of a response: An "item" might be a story, a comment, a question, a job posting, a poll, or a voting option in a poll. Each item type has different properties - for example stories have a title , but comments do not. If…

Advanced features in Flow

Flow has some very interesting features that are currently not documented. It is likely that the reason for missing documentation is that these features are still experimental. Caveat emptor . I took a stroll through the source code for Flow v0.11. Here is what I found while reading type_inference_js.ml and react.js . Edit : It has been pointed out to me that Flow features prefixed with $ are not…

Type checking React with Flow v0.11

This is an old post - for an up-to-date guide see Flow Cookbook: Flow & React . Flow v0.11 was released recently. The latest set of changes really improve type checking in React apps. But there are some guidelines to follow to get the full benefits. Use ES6 classes React added support in version 0.13 for implementing components as native Javascript classes ( more information on that here ). The…

Flow is the JavaScript type checker I have been waiting for

I am very excited about Flow , a new JavaScript type checker from Facebook. I have put some thought into what a type checker for JavaScript should do - and in my opinion Facebook gets it right. The designers of Flow took great effort to make it work well with JavaScript idioms, and with off-the-shelf JavaScript code. The key features that make that possible are type inference and path-sensitive…

Javascript generators and functional reactive programming

tl;dr: ECMAScript 6 introduces a language feature called generators , which are really great for working with asynchronous code that uses promises. But they do not work well for functional reactive programming . ES6 generators allow asynchronous code to be written in a way that looks synchronous. This example uses a hypothetical library called Do (implementation below) that makes promises work…

Kinesis Advantage with DSA keycaps

I now have a Kinesis Advantage keyboard for use at work. I have been feeling some wrist strain recently; and some of my coworkers were encouraging me to try one. So I borrowed a Kinesis for a week, and found that I really liked it. The contoured shape makes reaching for keys comfortable; I find the column layout to be nicer than the usual staggered key arrangement; and between the thumb-key…

Category Theory proofs in Idris

Idris is a programming language with dependent types. It is similar to Agda , but hews more closely to Haskell . The goal of Idris is to bring dependent types to general-purpose programming. It supports multiple compilation targets, including C and Javascript. Dependent types provide an unprecedented level of type safety. A quick example is a type-safe printf implementation (video) . They are also…

Functional data structures in JavaScript with Mori

I have a long-standing desire for a JavaScript library that provides good implementations of functional data structures. Recently I found Mori , and I think that it may be just the library that I have been looking for. Mori packages data structures from the Clojure standard library for use in JavaScript code. Table of Contents Functional data structures A functional data structure (also called a…

Functional Reactive Programming in JavaScript

I had a great time at NodePDX last week. There were many talks packed into a short span of time and I saw many exciting ideas presented. One topic that seemed particularly useful to me was Chris Meiklejohn's talk on Functional Reactive Programming (FRP) . I have talked and written about how useful promises are. See Promise Pipelines in JavaScript . Promises are useful when you want to…

Monkey patching document.write()

This is one of the crazier workarounds that I have implemented. I was working on a web page that embeds third-party widgets. The widgets are drawn in the page document - they do not get their own frames. And sometimes the widgets are redrawn after page load. We had a problem with one widget invoking document.write() . In case you are not familiar with it, if that method is called while the page is…

Promise Pipelines in JavaScript

This page has been translated into Spanish language by Maria Ramos from Webhostinghub.com . Promises, also know as deferreds or futures, are a wonderful abstraction for manipulating asynchronous actions. Dojo has had Deferreds for some time. jQuery introduced its own Deferreds in version 1.5 based on the CommonJS Promises/A specification. I'm going to show you some recipes for working with…

Installing a custom ROM on the Transformer Prime: A start-to-finish guide

This guide provides step-by-step instructions for installing the Virtuous Prime community ROM on your Asus Transformer Prime TF201 tablet. This guide will be useful to you if you do not have root access to your tablet. Be aware that following the instructions here will void your warranty and will wipe all of the data on your tablet. There is also a danger that you might brick your tablet. Proceed…

Cookies are bad for you: Improving web application security

Most web applications today use browser cookies to keep a user logged in while she is using the application. Cookies are a decades-old device and they do not stand up well to security threats that have emerged on the modern web. In particular, cookies are vulnerable to cross-site request forgery . Web applications can by made more secure by using OAuth for session authentication. This post is…

How Mobile Safari emulates mouse events

When you are adapting web apps to touchscreen devices particular challenges come up around events like mouseover and mouseout . Touchscreen devices like the iPad do not have a cursor, so the user cannot exactly move the mouse over an HTML element. However, Mobile Safari, the web browser that comes with the iPhone and iPad, has a fallback for websites that require hovering or cursor movement.…

CouchDB Notes

Recently I gave a talk at Portland Ruby Brigade meeting on CouchDB , a document-oriented database. I thought I would share my notes from that talk. In some respects this was a followup to an earlier talk that Igal Koshevoy gave comparing various post-relational databases . Igal also wrote some additional notes on my talk . In summary, some of the distinguishing features of CouchDB are: Schema-less…

How to install Haskell "Batteries Included" Platform on Ubuntu Jaunty

Just for kicks I thought I would take another shot at some Haskell programming. To get all of the common libraries and the automated package installer, cabal, I set up the Haskell Platform . Here is how I did it. Ubuntu Jaunty includes a package for the Haskell compiler, ghc, at version 6.8. The Haskell Platform installer will roll its eyes at you if you try to proceed with this version of ghc. So…

Database Queries the CouchDB Way

CouchDB is a document-oriented database. It has no rows or tables. Instead CouchDB is a collection of JSON documents. It uses a map-reduce pattern to index data. Queries in CouchDB pull data from what are essentially stored procedures called views. A view is made up of a map function and optionally a reduce function. Ninety percent of the time all you need is the map function, so I will focus on…

How to use RSpec to describe a Sinatra application

This information was written a long time ago and has become pretty outdated. Sinatra is a fun little web application microframework. Recently I started working on an application using Sinatra - and since I am working on good programming habits, before I dove into any coding I sat down to work out how to write specs for a Sinatra application. Sinatra comes bundled with support for test/spec : a…

International Phonetic Alphabet

In last week's post I provided phonetic transcriptions of some example words using the International Phonetic Alphabet, or IPA for short. I thought it would be helpful to follow that up with some information about what the IPA is, and how to read it. And as a bonus, after learning about IPA transcription you will be able to better read pronunciation guides on Wikipedia. You have probably seen…

Anatomy of a Syllable

The syllable is a constant feature in every spoken language in the world. Each language has its own rules about what kinds of syllables are allowed, and what kinds aren't - but the general structure is the same everywhere. A syllable has as many as three parts: onset , nucleus , and coda . The onset and the coda are consonants, or consonant clusters, that appear at the beginning and the end…

Deixis

When someone says to you, "here" or "now", you probably know what he means. "Here" might the room that you are both sitting in. "Now" would be the span of time you spent sitting together. But if either word were uttered under different circumstances, it could mean something very different. For example, if I called you from the Andes and I used the word, "here", it would mean a mountainside…