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.
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.
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 URI.escape
method.
Traditionally there are a few ways to statically add css to a page, and via JavaScript it can also be dynamically added by either creating a link
element with rel="stylesheet"
and href
set to a css file location, or creating a style
element with css definitions as its content. Now there is a 3rd way: importing css directly from within an ESM script tag, similarly to the way of importing JavaScript resources, via a feature called 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 Thread.sleep()
, sleep
, and time.sleep()
methods to pause the execution of the current thread and wait after specified time to continue the execution, and when used together with loops, it can help address race condition issues for example. In node.js, and generally JavaScript, the way to pause and wait may not seem very obvious and frequently seen due to the nature of single-threaded, event-driven, and asyncronous architecture. However, since the use of wait
and retry
is still needed and helpful under certain circumstances, it is possible to simulate similar functions and effects in nodejs or JavaScript.
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.
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.
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.
The main things to handle during upgrading API centric application's rails version from 5.2
to 6.0
include configuration tuning and deprecation warnings fixing.