Skip to content

Instantly share code, notes, and snippets.

View erikvullings's full-sized avatar

Erik Vullings erikvullings

View GitHub Profile
@erikvullings
erikvullings / capitalize.ts
Created December 13, 2020 11:33
Capitalize first names derived from an email address (Dutch)
export const capitalize = (s: string) => s.charAt(0).toUpperCase() + s.slice(1);
/** Capitalize first names that are derived from an email, like anne_merel or jan_willem. */
export const capitalizeName = (s: string) =>
/^ij/i.test(s) // names like IJsbrand
? s.replace(/^ij/i, 'IJ')
: /_/.test(s) // names like jan_willem
? s.split('_').map(capitalize).join('-')
: capitalize(s); // other names
@erikvullings
erikvullings / xml2json.ts
Last active May 10, 2024 12:47
Convert XML to JSON using the browser's DOMParser without external dependencies.
export interface IObject {
[key: string]: any;
}
/*
This work is licensed under Creative Commons GNU LGPL License.
License: http://creativecommons.org/licenses/LGPL/2.1/
Version: 0.9
Author: Stefan Goessner/2006,
Conversion: Erik Vullings/2021 converted to TypeScript
@erikvullings
erikvullings / README.md
Created November 10, 2021 13:08
EADDRINUSE error

EADDRINUSE error (Endpoint Address In Use)

Error: listen EADDRINUSE: address already in use :::1234

When node.js complains that an address is in use, this may happen because the service did not end properly. In order to kill the hanging process, do the following in an Admin PowerShell window:

netstat -ano|findstr "PID :1234"
@erikvullings
erikvullings / README.md
Last active December 2, 2021 10:36
Asynchronous retry pattern with delay in Typescript
@erikvullings
erikvullings / readme.md
Created January 30, 2022 10:50
Add SSH site to Windows Terminal

Source.

You can use a commandline field in your profile configuration to initiate an SSH connection on tab creation.

Step-by-step guide:

  1. Open Settings (Ctrl+,)
  2. Find the "list" array in the "profiles" object
  3. Duplicate a Command Prompt profile ("commandline": "cmd.exe")
  4. Change the commandline value to: ssh me@my-server -p 22 -i ~/.ssh/id_rsa (use your own connection command).
@erikvullings
erikvullings / utils.ts
Last active September 22, 2022 08:51
Utility functions
/* A list of useful functions snippets */
/**
* Create a GUID
* @see https://stackoverflow.com/a/2117523/319711
*
* @returns RFC4122 version 4 compliant GUID
*/
export const uuid4 = () => {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
@erikvullings
erikvullings / local-ldb.ts
Created June 11, 2022 10:43
IndexedDB wrapper in TypeScript
/**
* Use IndexedDB for local storage.
* Based on https://github.com/DVLP/localStorageDB, but converted to TypeScript and using async instead of callbacks.
* @source: https://github.com/DVLP/localStorageDB/blob/master/localdata.js
*
* Usage example
*
*
```ts
const test = async () => {
@erikvullings
erikvullings / extract_domain_name.ts
Created October 23, 2022 08:25
Extract main domain name from a URL
const url = "https://www.lancasterguardian.co.uk/read-this/womens-world-cup-2023-groups-england-to-face-denmark-and-china-see-the-full-draw-3890113";
const url1 = "https://www.tudelft.nl";
const url2 = "https://whatsnew2day.com/world-cup-2023-draw-uswnt-face-vietnam-netherlands-playoff-winner-new-zealand-htmlns_mchannelrssns_campaign1490ito1490/";
const url3 = "https://www.news4jax.com/news/politics/2022/10/22/weapons-shortages-could-mean-hard-calls-for-ukraines-allies/";
const extractAgency = (url = '') => {
if (url.startsWith('https://t.me/')) return 'TELEGRAM';
let hostname: string;
try {
const u = new URL(url);