Get caller from Error.protoype.stack in Chrome/Firefox/Safari browsers on Windows/macOS

Typically in JavaScript and Node.js projects, use of console is disallowed and is enforced using the no-console rule in ESLint. Logging would then be done thru a centralized function, e.g. log(), which may use console.log with the ESLint rule disabled just for that line of code, instead of having multiple console.log statements throughout the codebase …

Forward SSH logs from AWS EC2 instance to AWS CloudWatch Logs for external party to access

Scenario: A third party security agency hired by your boss or client wishes to monitor the SSH logs on the bastion host of your application. The bastion host is setup on an AWS EC2 instance. Instead of giving direct access to the bastion host for pulling the SSH logs in /var/log/auth.log, we can forward the …

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 …

MySQL query to generate INSERT statements for all tables

MySQL query to generate INSERT statements with columns for all tables in the current database: — Increase limit for GROUP_CONCAT() to avoid text cutoff SET SESSION group_concat_max_len = 1048576; SELECT CONCAT( ‘\n\n’, GROUP_CONCAT(CONCAT( ‘INSERT INTO `’, table_name, ‘` (‘, columns, ‘) VALUES ()’ ) SEPARATOR ‘\n\n’), ‘\n’ ) AS result FROM ( SELECT table_name, GROUP_CONCAT(CONCAT(‘`’, …

Demo to see how compiler optimization can introduce security vulnerabilities

Took a module under Dr Roland Yap, CS4239 Software Security, at my alma mater NUS (National University of Singapore) School of Computing, back in 2017 Semester 1. It was part of its Lifelong Education programme, under SCALE (School of Continuing and Lifelong Education), where modules were opened up to the general public. One interesting lesson …

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: * …

Different alignment and order of columns on mobile/desktop using Bootstrap 5

Scenario: Build a pagination partial consisting of 3 parts – the item range (e.g. “Showing 1 – 10 of 30 results”), a dropdown to select the page and a dropdown to select the number of items per page. The 3 parts will be displayed in a different order and have different text alignment on mobile …

Split text into left and right columns using CSS

Result (drawn using ASCIIFlow Legacy): +————————————————–+ | | | 1) This text is left. This text is right. | | 2) This text is left. This text is right. | | | +————————————————–+ Sample HTML and CSS: <style> .split { display: block; } .split span { display: block; float: right; } div { left: 200px; …

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 …