Skip to content

Instantly share code, notes, and snippets.

Erik Vullings erikvullings

Block or report user

Report or block erikvullings

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@erikvullings
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
erikvullings / Excel_time_to_UTC_time.md
Last active Aug 24, 2018
Convert Excel time to UTC time
View Excel_time_to_UTC_time.md

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
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
erikvullings / guid.ts
Created Jul 30, 2018
Create a new GUID or UUID in TypeScript
View guid.ts
/**
* 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 / deep-copy.ts
Last active Dec 9, 2019
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 https://github.com/ykdr2017/ts-deepcopy
* @see Code pen https://codepen.io/erikvullings/pen/ejyBYg
*/
export const deepCopy = <T>(target: T): T => {
if (target === null) {
return target;
@erikvullings
erikvullings / deep-copy.ts
Created Jul 30, 2018
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 https://github.com/ykdr2017/ts-deepcopy
*/
export const deepCopy = <T>(target: T): T => {
if (target === null) {
return target;
}
@erikvullings
erikvullings / utils.ts
Last active Jan 19, 2019
TypeScript utilities: GUID and deepCopy (clone)
View utils.ts
/**
* 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 / cachify.ts
Created May 31, 2018
Created a cached version of any function with a single argument.
View cachify.ts
/**
* Create a cached version of a function.
*
* @example cachedCalcArea = cachify(calcArea);
* @param fn Function whose results you want to cache
* @see TypeScript version of https://dev.to/kepta/javascript-underdogs-part-1---the-weakmap-4jih
*/
export const cachify = <T extends object, R>(fn: (arg: T) => R) => {
const cache = new WeakMap(); // Use Map() when dealing with non-object arguments
return (arg: T) => {
@erikvullings
erikvullings / geo.ts
Last active May 29, 2018
Convert RD (rijksdriehoek) to WGS84 and back.
View geo.ts
/**
* Convert RD (Rijksdriehoek) coordinates to WGS84 and vice versa.
* @see https://thomasv.nl/2014/03/rd-naar-gps/
*/
const projectionBetweenRdWgs84 = () => {
const x0 = 155000;
const y0 = 463000;
const f0 = 52.15517440; // f => phi
const l0 = 5.38720621; // l => lambda
@erikvullings
erikvullings / walk.ts
Created May 15, 2018
Recursively walk a directory in TypeScript
View walk.ts
/**
* Recursively walk a directory asynchronously and obtain all file names (with full path).
*
* @param dir Folder name you want to recursively process
* @param done Callback function, returns all files with full path.
* @param filter Optional filter to specify which files to include,
* e.g. for json files: (f: string) => /.json$/.test(f)
* @see https://stackoverflow.com/questions/5827612/node-js-fs-readdir-recursive-directory-search/50345475#50345475
*/
const walk = (
You can’t perform that action at this time.