Skip to content

Instantly share code, notes, and snippets.


Erik Vullings erikvullings

View GitHub Profile
erikvullings / xml2json.ts
Last active Mar 7, 2021
Convert XML to JSON using the browser's DOMParser without external dependencies.
View xml2json.ts
export interface IObject {
[key: string]: any;
This work is licensed under Creative Commons GNU LGPL License.
Version: 0.9
Author: Stefan Goessner/2006,
Conversion: Erik Vullings/2021 converted to TypeScript
erikvullings / capitalize.ts
Created Dec 13, 2020
Capitalize first names derived from an email address (Dutch)
View capitalize.ts
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 / pdok.html
Created Jul 30, 2020
Add a Dutch background map to your leaflet application.
View pdok.html
<!DOCTYPE html>
<title>PDOK achtergrondkaarten</title>
Zie ook de wizard hier:
PDOK biedt 4 base maps aan van NL: standaard, grijs, water, en pastel. Deze kun je gratis gebruiken
View copy-to-clipboard.js
const copyToClipboard = str => {
const el = document.createElement('textarea');
el.value = str;
el.setAttribute('readonly', ''); = 'absolute'; = '-9999px';
const selected =
document.getSelection().rangeCount > 0 ? document.getSelection().getRangeAt(0) : false;;
erikvullings / toEnglish.vba
Last active Sep 28, 2018
Change the language of your PowerPoint presentation
View toEnglish.vba
'Change the language of your PowerPoint
'In newer PowerPoint version, you need to first save your PowerPoint with macros enabled.
'Go to the VIEW tab, select MACROS (at the right), enter a name, e.g. toEnglish, and press create to enter below text.
'Now you can run the macro from the same menu.
'Alternatively, but less complete, go to the VIEW tab, select OUTLINE, select all slides (using CTRL-A).
'Now go to the REVIEW tab, select Language, and change the proofing language.
'Also make sure that you set the WINDOWS Language (taskbar, bottom right) to the preferred language, otherwise all new text
'will have the same problem (Press CTRL + WINDOWS + SPACE to switch the Keyboard input language).
Option Explicit
Sub toEnglish()
erikvullings /
Last active May 13, 2021
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.

erikvullings / message-bus-service.ts
Created Aug 15, 2018
Message bus service, or pub/sub service, loosely based on postal.js, but created in TypeScript.
View message-bus-service.ts
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 / guid.ts
Created Jul 30, 2018
Create a new GUID or UUID in TypeScript
View guid.ts
* Create a GUID
* @see
* @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 / deep-copy.ts
Last active Sep 6, 2021
Deep copy or clone in TypeScript
View deep-copy.ts
* Deep copy function for TypeScript.
* @param T Generic type of target/copied value.
* @param target Target value to be copied.
* @see Source project, ts-deepcopy
* @see Code pen
export const deepCopy = <T>(target: T): T => {
if (target === null) {
return target;