Skip to content

Instantly share code, notes, and snippets.

View erikvullings's full-sized avatar

Erik Vullings erikvullings

View GitHub Profile
@erikvullings
erikvullings / guid.ts
Created July 30, 2018 10:45
Create a new GUID or UUID in TypeScript
/**
* 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) => {
// tslint:disable-next-line:no-bitwise
const r = (Math.random() * 16) | 0;
@erikvullings
erikvullings / message-bus-service.ts
Created August 15, 2018 07:31
Message bus service, or pub/sub service, loosely based on postal.js, but created in TypeScript.
export type ICallback<T> = (data: T, envelope: IEnvelope<T>) => void;
/** Message enveloppe */
export interface IEnvelope<T> {
/* Uses DEFAULT_CHANNEL if no channel is provided */
channel?: string;
/** Topic name */
topic: string;
/** Payload */
data?: T;
@erikvullings
erikvullings / utils.ts
Last active January 19, 2019 11:46
TypeScript utilities: GUID and deepCopy (clone)
/**
* 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) => {
// tslint:disable-next-line:no-bitwise
const r = (Math.random() * 16) | 0;
@erikvullings
erikvullings / ColorExt.js
Created October 13, 2015 22:01
Displaying an ESRI ASCII grid file in leaflet using an HTML5 canvas element.
var ColorExt;
(function (ColorExt) {
var Utils = (function () {
function Utils() {
}
Utils.hsv2rgb = function (h, s, v) {
var rgb, i, data = [];
if (s === 0) {
rgb = [v, v, v];
}
const copyToClipboard = str => {
const el = document.createElement('textarea');
el.value = str;
el.setAttribute('readonly', '');
el.style.position = 'absolute';
el.style.left = '-9999px';
document.body.appendChild(el);
const selected =
document.getSelection().rangeCount > 0 ? document.getSelection().getRangeAt(0) : false;
el.select();
@erikvullings
erikvullings / pdok.html
Created July 30, 2020 10:50
Add a Dutch background map to your leaflet application.
<!DOCTYPE html>
<html>
<head>
<title>PDOK achtergrondkaarten</title>
<!-- https://www.pdok.nl/introductie/-/article/basisregistratie-topografie-achtergrondkaarten-brt-a-
Zie ook de wizard hier:
https://nlmaps.nl/
PDOK biedt 4 base maps aan van NL: standaard, grijs, water, en pastel. Deze kun je gratis gebruiken
@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 / 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 / Excel_time_to_UTC_time.md
Last active November 29, 2021 21:03
Convert Excel time to UTC time

The problem

I had a CSV file that needed to be processed on a web page. So I had to convert the Excel time to UTC time.

The solution

According to this answer on StackOverflow:

The Excel number for a modern date is most easily calculated as the number of days since 12/30/1899 on the Gregorian calendar.

Excel treats the mythical date 01/00/1900 (i.e., 12/31/1899) as corresponding to 0, and incorrectly treats year 1900 as a leap year. So for dates before 03/01/1900, the Excel number is effectively the number of days after 12/31/1899.