Skip to content

Instantly share code, notes, and snippets.

View locnt19's full-sized avatar
🦝

Loc Nguyen locnt19

🦝
View GitHub Profile
@locnt19
locnt19 / try-catch.ts
Created February 25, 2025 07:32 — forked from t3dotgg/try-catch.ts
Theo's preferred way of handling try/catch in TypeScript
// Types for the result object with discriminated union
type Success<T> = {
data: T;
error: null;
};
type Failure<E> = {
data: null;
error: E;
};
@locnt19
locnt19 / validateUEN.js
Created July 8, 2024 13:41 — forked from mervintankw/validateUEN.js
validates that UEN (Unique Entity Number) number is valid based on https://www.uen.gov.sg/ueninternet/faces/pages/admin/aboutUEN.jspx
/**
* validates UEN of businesses in Singapore
* https://www.uen.gov.sg/ueninternet/faces/pages/admin/aboutUEN.jspx
* @param {string} uen
* @returns {boolean}
*/
function validateUEN (uen) {
var debug = true;
const entityTypeIndicator = [
'LP', 'LL', 'FC', 'PF', 'RF', 'MQ', 'MM', 'NB', 'CC', 'CS', 'MB', 'FM', 'GS', 'GA',
@locnt19
locnt19 / gist:1a0a7736c2cc3214270e70019c773511
Created July 8, 2024 09:02 — forked from cjaoude/gist:fd9910626629b53c4d25
Test list of Valid and Invalid Email addresses
Use: for testing against email regex
ref: http://codefool.tumblr.com/post/15288874550/list-of-valid-and-invalid-email-addresses
List of Valid Email Addresses
email@example.com
firstname.lastname@example.com
email@subdomain.example.com
firstname+lastname@example.com
@locnt19
locnt19 / esm-package.md
Created June 30, 2024 18:49 — forked from sindresorhus/esm-package.md
Pure ESM package

Pure ESM package

The package that linked you here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.
@locnt19
locnt19 / migrate_repo.sh
Created October 15, 2021 14:37 — forked from mariozig/migrate_repo.sh
Migrate repo from GitLab to GitHub Full blog post @ http://ruby.zigzo.com/2015/03/23/moving-from-gitlab-to-github/
# Assume we are in your home directory
cd ~/
# Clone the repo from GitLab using the `--mirror` option
$ git clone --mirror git@your-gitlab-site.com:mario/my-repo.git
# Change into newly created repo directory
$ cd ~/my-repo.git
# Push to GitHub using the `--mirror` option. The `--no-verify` option skips any hooks.