cmd for macOS is the
ctrl for windows.
I came across a system issue recently that some of our batch jobs written as ruby rake tasks ended up having duplicated invocations, which causes either duplicated records in database or duplicated alerts in slack. It is definitely an infra issue but until it is fixed from infra side, I need figure out a way to address it from the coding perspective. Trying to rewrite everything as idempotent as possible is not an option and neither is enhancing application level validations or database uniqueness constraints, because not all jobs can be idempotent and not all jobs write to databases, besides the issues are caused by race conditions not from two threads but from two processes. After some research and experiment, I decided to use
Redis as a simple distribution lock solution, which is already available in our application and needs zero extra setup, and it is a single instance therefore no replication sync concern.
Redis is single-threaded architecture so no matter how many concurrent clients try to write to it, it is guaranteed to be in sequential and atomic. I figure out I could make use of this nature to fix the issue faced.
tmux is a terminal multiplexer. It is very useful when we need run long-running tasks on remote servers on the background and check the results later without the need to keep a constant live ssh connection and worrying about network failure causing the task to exit unexpectedly. Here is a list of minimum commands to meet most of the use cases.
Since JDK 11, Java supports executing source file directly without the need to first compile to class file, which makes it possible to write scripting in Java, as is usually done with dynamic programming languages like python, ruby, or nodejs. This post serves as an example as well as a quick reference on how to achieve it.
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.
Ruby 3.0 came with a few breaking changes which would cause much hassle for a typical rails app that uses a lot of gems, especially the keyword argument behavior breaking change and the removal of the
link element with
href set to a css file location, or creating a
CSS Module scripts.
When dealing with large text files such as parsing log files, it is always preferred to load/iterate the content line by line instead of reading everything into memory for efficiency and performance reasons. In Nodejs, it has always been a hassle because the way of reading line by line looks hacky and too low-level from a daily user’s perspective. However, that’s not the case any more thanks to a PR merged into the latest version of
v18.11.0, there is now
FileHandle.prototype.readLines builtin which makes it very convenient to use.
In other programming languages such as Java, Ruby and Python, there are
It becomes annoying sometimes if ssh connection gets terminated very soon if no messages sent between the ssh server and client for sometime but there are ways to keep it alive for long or forever from either client or server side.