React fundamentals and pitfalls

React fundamentals and pitfalls. Mostly from the official doc.

Difference between service worker and web worker

Web workers and service workers are both types of JavaScript workers that run in the background, separate from the main browser thread. However, they serve different purposes and have distinct characteristics.

async parallel behavior with callback

The async library has a convenient method called parallel, which takes a collection of async functions to run and an optional callback to run once all the functions have completed successfully.

Convert epoch millisecond timestamp to readable datetime

In many cases such as when dealing with API response in JSON format, working on JavaScript assets embedded on websites, and so on, we keep seeing 13-digit long numbers very frequently and we probably know it is epoch timestamp originating from code like new Date().getTime(), however, as a human we just can not quickly tell what date and time it represents. There is a convenient website named Epoch Converter that can help convert it to human-readable format easily but most of the time for developers, there are even quicker ways than opening the website, which is by using the interactive shell that comes with many programming languages.

How to convert stream to buffer in Nodejs

In Nodejs when dealing with non-text files (e.g. images) IO operations such as transferring via network or reading from disk, there is a big chance to receive the content as stream.Readable, and before we can process the complete data in memory such as calculating the bytes size or image dimensions, we need save the stream to buffer and here are a few ways.

Intellj IDEA eslint and alias resolving issues

I'm using a perpetual fallback license version of Intellj IDEA Ultimate for daily development but recently I noticed two issues in JavaScript development environment related to ESLint and module alias resolution. Luckily for either issue I managed to find a solution.

How to handle BigInt in JSON stringify

As we know the BigInt type is availble in JavaScript as a data type able to represent any arbitrary large integer number, which is a good supplement when a value exceeds what number could represent. However, when working with applications where you need exchange data with JSON format, the BigInt values become a problem because JSON does not know how to serialize BigInt values by default, in such cases, one solution is to convert the BigInt into string as this post shows.

Upgrade socket.io from v3 to v4

Following Upgrade socket.io from v2 to v3, this post is about upgrading socket.io and its associated packages to the latest versions as of when this post is written and the only setting changes seem to be from the redis-adapater and the way to import client io this time (for our specific use case).

Upgrade socket.io from v2 to v3

socket.io and its related libraries such as socket.io-redis-adapter and socket.io-redis-emitter had a few breaking changes in either functions or behaviors since v3 which might cause issues during the v2-to-v3 migration. This post lists what was encountered and how to solve it for specific use cases based on hands-on experience.

JS resources

Since I find myself writing code more and more in JavaScript nowadays regardless of backend or frontend development, I figure out I should at least give it a look seriously, the first time in more than 10 years, and here are the resources I find useful while diving into this long overlooked programming language.

JavaScript typeof returns and falsy values

JavaScript typeof returns and falsy values.

How to dynamically insert js

How to dynamically insert js.

How to generate 26 english letters in js

How to generate 26 english letters in js.

Nodenv quick commands cheatsheet

nodenv is a great tool to manage multiple NodeJS versions and here are some of its commonly used commands summarized for quick reference.

React-csv issue in async data and rendering

In frontend development sometimes you need to export the data (usually in JSON format) as downloadable csv format, and for those working on ReactJS related web applications, there is a package named react-csv that can save you from breaking the DRY... However, you may also encounter issues when applying this package in some specific scenarios, such as the one I'm writing down soon which involves in data being loaded asyncronously but needed for initial UI rendering.

Floating horizontal scrollbar

How to use a jquery plugin to implement floating horizontal scrollbar, which is especially useful for single page application where partial content of the page (i.g. table of data) are large and dynamically updated and you don't want to make use of the browser scrollbar for scrolling the partial content.

Javascript calendar

A javascript calendar.