Range of integers/floats/dates in programming languages when using BIGINT in PostgreSQL

Was trying to migrate a database from MySQL to PostgreSQL recently when I “discovered” that UNSIGNED is not supported in PostgreSQL, as it is not part of the ANSI SQL standard which it follows closely. Other findings were that non-aggregate columns are not allowed in queries with GROUP BY clauses (which MySQL/SQLite “allows” by selecting …

JavaScript code that can be used client-side in the browser and server-side in Node.js

Sample code as follows, read comments for more details ๐Ÿ™‚ /** * Example of JavaScript code that can be used client-side in the browser and server-side in Node.js * * Usage in browser: * <script src=”shared.js”></script> * <script> * console.log(shared.STATUS_SUCCESS, shared.test()); // note that shared.getTimestamp() won’t work * </script> * * Usage in Node.js: * …

Render array of objects together with index in Mustache.js and as Bootstrap rows or dropdown options with selected value

Came across a GitHub issue Collection processing like @index for Mustache.js. It referenced the each() function in another library, GRMustache. Came up with the following and posted my solution back in the Mustache.js GitHub issue ๐Ÿ™‚ Sample output: <h4>Test 1: Loop over array with count & access to existing template vars/fns</h4> <div data-date=”2021-12-03″>item 1/4: ant …

Using Konva.js to annotate image with bounding boxes

References: Konva Tutorials Konva API Docs Drawing Labels on Image with canvas HTML5 Canvas Export to High Quality Image Tutorial Resolving “Tainted canvases may not be exported” with Konva First up, a working demo below. Click on “Set image” button first. Click “Add box” button to create a new bounding box. Each time the box …

Uploading a folder via HTML form or cURL

References: Upload directory doesn’t send folder name with file Upload files with CURL Multipart formposts How to upload folder using HTML and PHP VGG Image Annotator: Issue 270 – Using Webkitdirectory to import multiple directories and maintain directory hierarchy Contents of folder to be uploaded (drawn using tree –charset unicode –dirsfirst -a -n in bash): …

Logical operators in Javascript do not always return boolean result

Given a variable myObj in Javascript, evaluating myObj.child.name || ‘Kid’ will cause an error if myObj.child does not exist. In comparison, in PHP, $myObj->child->name ?? ‘Kid’ would just yield “Kid” with no errors. One way would be to write the expression let result = (myObj && myObj.child && myObj.child.name) ? myObj.child.name : ‘Kid’;. Another way …

When an object is assigned to a variable, will modifying the variable modify the original object?

This is similar to the previous blog post except this is more direct. The answer is “Yes” for all tested languages except C and C++. This may seem trivial until you meet a situation where the same original object is shared across requests/sessions, like a public static variable in Java or an incorrectly scoped Javascript …

Does modifying objects passed in to functions modify original object?

As per title, ran this across various languages. Results are mixed, but IMHO, it seems unsafe to design your functions/methods this way. It would be better to pass in the object, compute the changes without modifying the object, return the computed changes and assign it back to the original variable. Below are sample code snippets …