Blog
Read. Debug. Repeat.
Using Direnv to Automatically Manage Git Hooks
The recent release of npm@7 broke husky, my git hook management tool of choice. When I was looking into why my git hooks had stopped working I came across the docs for the next version of husky and saw that git hooks will now be stored in a committed directory rather than inside package.json. This got me thinking; do I really need husky? Surely there must be a simple method to manage a directory of git hooks inside your repository. I want something that's (mostly) automatic, safe, easy, and preferably uses tooling I'm already familiar with (installing a global dependency just to manage git hooks on a per-project basis is somewhat less than ideal).
Introducing instant.bible - An as-you-type Bible search engine written in Rust, Swift, Kotlin, and TypeScript!
Introduction
Creating and Scaling a Docker Swarm Cluster with Terraform
Terraform is a tool made by Hashicorp which allows you to provision and manage infrastructure on popular cloud providers. You define your infrastructure as code in simple configuration files enabling repeatable deployments which are simple to tear down and easy to make changes to. This article serves as an introduction to Terraform by showing you how to create and scale a Docker Swarm cluster on DigitalOcean. If you don't already have a DigitalOcean account and would like to follow along you can use this link to get $10 in free credit.
Testing Single-File Vue Components in Node
Vue is a progressive framework for building user interfaces in JavaScript, HTML, and CSS. One of its most unique features is that it allows you to combine the JavaScript (logic), HTML (template), and CSS (style) for a single component into a single .vue file.
Quick Tip: Multiple User Configs with Git
On my personal laptop I often write code for multiple organizations as well as my own personal projects. Being the git neat freak I am sometimes I prefer to use different user configurations in git depending on what project I'm working on (e.g., personal projects might use my email address here at knpw.rs whereas non-personal projects might use a different email address). The solution for a small number of projects is simple: just use git config to set local user configuration for a given repo. However, that breaks down very easily. For instance, sometimes I would clone down a repo just to make a quick change and I would forget to set local user configuration. A quick Google search revealed that I'm not alone. What follows is my solution to make using multiple users in git easy and convenient.
Trying Out Node Modules
How do you try out node modules? Have you really thought about it at all? It's something I've given some thought recently. Today's post presents three options for trying out node modules with pros, cons, and recommended use cases for each.
Using Lodash as a Collection of Micro-Libraries
So a thing happened recently. I'm sure you've heard of it by now. 11 lines of code were unpublished from npm and all hell broke loose. This post isn't going to be about my opinion, everyone else on the Internet seems to be handling that just fine. This also isn't going to be a summary of what happened. The npm blog post does that just fine and gets in to all the details I don't feel like writing about (legal stuff... ugh...). This is going to be a discussion on the context of why this happened and a few ways it can be avoided in the future (but I'm not going to talk about preventing unpublishing, others around the Internet including the npm blog post already cover that avenue).
Why You Should Learn JavaScript in 2016
Recently I saw this question come up in my Facebook news feed:
Advanced Features in Sinon
In my previous post on testing I covered the basics of testing with Mocha, Chai, and Sinon -- including asynchronous testing and stubbing methods with asynchronous callbacks (such as methods which make a server request). That's all well and good, but sometimes it's more convenient or natural to synchronously manipulate the JavaScript timer or create fake servers to instantly and synchronously respond to requests. Sinon provides the facilities to work such magic -- read on to learn more.
The Power and Limitations of Partials
Partially applied functions, or partials for short, are functions with pre-set arguments. The use of partials is very common in functional programming and has been implemented in several JavaScript libraries and more recently in ECMAScript 5 through Function.prototype.bind. Consider the following examples:
Testing in Browsers and Node with Mocha, Chai, Sinon, and Testem
So you're writing some JavaScript code that has to run in multiple web browsers as well as Node. How can you effectively test this code? Effective testing means that you should be able to run all tests in all environments on demand, i.e., with the press of a single button the tests should run in Node, Chrome, Firefox, Internet Explorer, and whatever other environments you have set up for testing, and we should avoid code duplication whenever possible. Continue reading and I'll walk you through setting up a basic testing environment using Mocha as a testing framework, Chai for assertions, Sinon for mocking, and Testem as a universal test runner. Basic knowledge of testing, asserting, and mocking in languages other than JavaScript is assumed. Those of you who are familiar with testing, asserting, and mocking in JavaScript will want to skip to the Testem section below -- that's where the meat and potatoes of pulling everything together into a working example is.