Negative zero (-0) This post discusses the difference between Positive zero (0) and Negative zero (-0) in programming, explaining in Javascript. In IEEE 754 Single-Precision Presentation, sign bit of negative zero is 1, that of positive zero is 0. 0 Sign | Exponent | Fraction 0 | 00000000 | 00000000000000000000000 -0 Sign | Exponent | Fraction 1 | 00000000 | 00000000000000000000000
Don't use object {} to lazily map arbitrary key in Javascript In Javascript, these keys are not undefined even in an empty object {}. * 'constructor' * '__defineGetter__' * '__defineSetter__' * 'hasOwnProperty' * '__lookupGetter__' * '__lookupSetter__' * 'isPrototypeOf' * 'propertyIsEnumerable' * 'toString' * 'valueOf' * '__proto__' * 'toLocaleString' These keys
Upload files to Cloudflare R2 using AWS CLI If you encounter this error when uploading files to Cloudflare R2. An error occurred (InternalError) when calling the UploadPart operation (reached max retries: 2): We encountered an internal error. Please try again. Add the --checksum-algorithm CRC32 flag, the error will gone. AWS_REGION=apac AWS_ACCESS_KEY_ID=<your-key-id&
Server performance debugging This post introduces several command lines and tools to debug server performance. CPU monitoring: mpstat -P ALL 1 (require apt install sysstat) In the result, notice %iowait which is the time CPU waits for IO operations. Also, high %idle with high sysload (average running process count) indicates a possibility of
Typographic scales - Comprehensive list Typographic scales are sets of predefined font sizes that create visual hierarchy while maintaining design harmony, providing designers with a systematic approach to selecting font sizes rather than making arbitrary choices. For example, with a base size of 16px and a ratio of 1.25 (Major Third), the next sizes
How does email forwarding pass DMARC validation? An email forwarder owning domain forwarder.com, receives an email sent to source@source.com and forwards to target@target.com. The original email has the following headers: - From: sender@sender.com - Return-Path: bounce@sender.com - To: source@source.com Forwarded email: - From: sender@sender.com
Change back to classic language switch UI in mac Sonoma To use classic language switch UI defaults write kCFPreferencesAnyApplication TSMLanguageIndicatorEnabled 0 To use new language switch UI defaults write kCFPreferencesAnyApplication TSMLanguageIndicatorEnabled 1
Type special symbols with Japanese input mode Do you know that you can write this equation with your keyboard in Japanese input mode? Δθ₀ = η × 1÷√(var(θ₀) + ε) × ∇(θ₀) For example, θ can be input by しーた. ε can be input by いぷしろん, etc. The exhaustive list of these symbols and the associated key combination can
Accept GCP console invitation when email is not arriving It sometimes happens that GCP does not send invitation emails when adding new users to the project. You can use the following template to obtain the invitation URL. https://console.cloud.google.com/invitation?project=<project-id>&account=<invited-email>&memberEmail=<invited-email> If you
unicode-range and font slicing There is a useful unicode-range feature in the @font-face css at-rule. The unicode-range can be used to: * Specify the character (glyph) set to which a font can be applied. * Slice the font files into different parts, especially grouping frequently used characters into a set, to reduce the total size to
Javascript prototype chain Javascript objects have an internal property called [[Prototype]] for property lookup and inheritance. When looking for an object property, javascript checks the object's own property first, if not found, it will continue with the object's [[Prototype]], if not found again, look for [[Prototype]] of its [[Prototype]
One practical use-case of Object.create(null) Sometimes, you see Object.create(null) and don't understand why not just using {}. After more than ten years of using javascript, I have found a relevant bug I had to use Object.create(null). Problem The client provides a string key and arbitrary value, you want to store
React rendering/effect/cleanup order I did some tests to get insight into how React orders its render, effect, and cleanup functions. I share the results in this post. I used react version: 18.3.1. The main component is defined below. let id = 0 function App({children}: {children: ReactNode}) { const myId = ++id console.log(
How to hide your website from search engine result To prevent your web page from appearing on search engine results (google, bing, yahoo, etc.), use noindex meta tag, and DON'T use robots.txt for this purpose.
Create a virtual audio output device In Linux, you can use the following command to create a virtual audio output device. With this virtual device, you can turn the volume in. This will not make any sound physically, and you can stream the desktop sound to other apps like streaming/recording apps. Without the virtual device,
Sakamoto algorithm to calculate day of week If year is non-negative: Sakamoto algorithm implementation in C++: 0 = sunday, 1 = monday, ..., 6 = saturday. static int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4}; int dow(int y, int m, int d) { y -= m<3; return (d + t[m-1] + y + y/4
Decimal number of programming Try this in your interpreter such as javascript or python: Input: .1 + .2 Output: 0.30000000000000004 Input: .1 + .2 === .3 Output: false Rationale: we (humans) use decimal representation for numbers (the number we write in the console, the number printed out), while internally the interpreters use binary representation which causes
Some topics in number theory This post comes from the journey when I tried to find a deterministic hash function that maps different natural numbers (for instance, an ID in a database) to different strings with the shortest length possible and an absolute zero possibility of collision. Eventually, I found a perfect answer for this,
How to install latest open-sourced Lens, bypassing login requirement Recently Lens disallows the use of its app without an account. The app even hides the close button. Here is how to install a working version 5.4 without an account. Download Lens 5.4 binary from here: https://gateway.pinata.cloud/ipfs/QmVVpMtbecfsyofgKZ2buHM7Xd6Shcr6HFJWNciRLeMPVx And add to /etc/hosts: 127.
MySQL max connections setting Sometimes, your MySQL client faces thsi error: MySQL: ERROR 1040: Too many connections To get current max connections setting show variables like "%max_connections%"; Result max_connections 151 mysqlx_max_connections 100 Default value is 151. To update value in the current session Note: the value will be
Base64 encoding This topic discusses how base64 works, and the usage of the padding and non-alphabet characters. RFC4648 link: https://datatracker.ietf.org/doc/html/rfc4648#section-4 Base64 encodes a binary buffer to ASCII using the following 65 characters for encoding. Table 1: The Base 64 Alphabet Value Encoding Value Encoding Value
Database connection timeout error (ECONNRESET) and keepalive config Sometimes, you observe that the database servers (postgres, redis, etc.) being disconnected after being idle for a while. This is due to the keepalive config, in which tcp connections are killed if they are detected not being used for a specific time range. This configuration is imposed by numerous components
Yarn 2 gitignore Yarn 2 gitignore content Default option (non-zero install + node_modules linker) .pnp.* .yarn/* !.yarn/patches !.yarn/plugins !.yarn/releases !.yarn/sdks !.yarn/versions node_modules node_modules entry can be removed unless you are using nodeLinker: node-modules option in .yarnrc.yml. Zero-install option If you have no idea what zero-install