Skip to content

Instantly share code, notes, and snippets.

@yidas
yidas / js-nl2br-br2nl.md
Last active April 18, 2026 21:48
JavaScript nl2br & br2nl functions

JavaScript nl2br & br2nl functions

The exchange of new line & br HTML tag could refer to PHP - nl2br() function, which uses to inserts HTML line breaks before all newlines in a string.

These JavaScript functions consider whether to use insert or replace to handle the swap.

nl2br

@Ynote
Ynote / tail-call-optimization.js
Last active October 18, 2022 13:33
[Javascript] - Tail-recursive factorial function
// This is just a short reminder of this great explanation:
// http://www.2ality.com/2015/06/tail-call-optimization.html
// not TCO
function factorial(n) {
if (n <= 0) return 1;
return n * factorial(n-1); // here, the main recursive call not in a tail position because of the `n` context.
}
@tonymtz
tonymtz / gist:d75101d9bdf764c890ef
Last active July 24, 2025 16:11
Uninstall nodejs from OSX Yosemite
# first:
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.pkg.bom | while read f; do sudo rm /usr/local/${f}; done
sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*
# To recap, the best way (I've found) to completely uninstall node + npm is to do the following:
# go to /usr/local/lib and delete any node and node_modules
cd /usr/local/lib
sudo rm -rf node*