How to implement a Linked List in JavaScript

implement linked list in javascript banner nickang
Photo by LinkedIn Sales Navigator on Unsplash

In this post, you’ll learn how to implement a linked list in JavaScript. This is the second part of a 2-parter post on linked lists (read part 1).

Let’s jump right in!

Continue reading “How to implement a Linked List in JavaScript”

Writing my first Sass mixins

writing my first sass mixins banner
Photo by Dmitri Popov on Unsplash

Sass is a CSS pre-processor. Even though I’ve been using Sass in many projects, I realised recently at work that I’d only been using it in a very primitive way. Sass mixins didn’t even exist in my mind.

The main ways I’d been using Sass are:

  • declaring variables in a single file as the main way of easily configuring an entire project
  • extending/inheriting selectors to reduce repetition (to keep the code DRY)
  • nesting selectors to create and maintain a clear visual hierarchy

But there’s an incredibly useful feature of Sass that I’d been missing out on. I only accidentally stumbled onto it recently – it’s called Sass mixins.

Continue reading “Writing my first Sass mixins”

How to tunnel HTTP requests into localhost

ngrok explanation illustration
Source: https://ngrok.com/product

Suppose you’re part of the engineering team of a tech company whose product is involves giving users product recommendation widgets for online stores. Since the product is already in the wild, so to speak, how do you test developmental features on live stores?

Continue reading “How to tunnel HTTP requests into localhost”

Encoding for programmers

red book with 8 bit bytes carved on the cover
Photo by Hope House Press on Unsplash

I’ve been running into Unicode and ASCII and related encoding/decoding issues recently at work. We had an email that didn’t get sent out and all I got was an error message that said that some character could not be encoded in ASCII as “ordinal out of range”. That set me back for many hours and I only think I’ve managed to fix it (by wrapping u” around every string in the affected module in Python).

Continue reading “Encoding for programmers”

How to completely replace git branch code with another branch’s code

photo of a branch of leaves
Photo by Leo Rivas-Micoud on Unsplash

At work recently, our CTO noticed that our main repository’s staging branch had over 80 less commits than master. That shouldn’t be the case, because our deployment pipeline has always been to go from feature -> staging -> master. Code that exist on master must therefore already exist in staging, right?

No, turns out nothing was really wrong. It’s just that whenever we close a pull request (PR) on GitHub, our team protocol is to hit the “Merge” button, which merges all the commits from the PR into master, but not without adding one extra commit at the top called the “merge commit”. Each PR created one extra commit on master. That was the reason for the commit count mismatch.

Continue reading “How to completely replace git branch code with another branch’s code”

How to squash git commits

In this short post, I’ll demystify the process to squash git commits from the command line. This process is simple if you’re using a remote like GitHub, which can be done with the click of a few buttons in the Pull Request UI. This post focuses on squashing commits on the command line.

Note before proceeding: I use Terminal on a Mac and the commands below are based on that.

shirtless boy hugging a ball trying to squash it
Photo by Vance Osterhout on Unsplash

Continue reading “How to squash git commits”

Silly useful things on my Repl.it

screenshot of a repl.it document

I love using repl.it, and I use it so often I can go up to a some else’s laptop and type the fully formed URL in the browser: https://repl.it/languages/python. You saw me type that, right?

Digressions aside, repl.it has really been quite helpful in my short career as a developer.

For the uninitiated, Repl (the service) is a simple web-based compiler, named after the concept of REPL (read – evaluate – print loop). It’s basically a place to write code on the left pane, which gets evaluated on command and the results (or errors) are output on the right pane. A simple but powerful tool.

Here’s an example of how I used it today to understand what happens when someone writes 2 chained assignment operators in a single line in JavaScript.

Seeing this line of code embedded deep in our code base, I found myself a bit lost.

It was the first time I’ve seen someone write two = assignment operators in the same line. Although I suspected off the cuff that this was evaluating right to left, and assigning values that way, I couldn’t be sure, so I recreated it in Repl and started fiddling with it.

Both logged ‘jquery v1’ to the web-based simulated console. In the amount of time it usually takes to get a water bottle refill, I’d figured out how a foreign-looking piece of code works.

In my opinion, this is one of those tools that need no publicity and will grow in use organically simply because it brings developers delight. Clean UI, fast loading speed, and the feature to save code for future reference (my example lives here). It’s a sweet product, and even sweeter because it’s free.

I have many more examples of Repl.it coming to save my day at work, but I don’t always save them to my account. I’ll write a separate post when I come across another insightful REPL!