Skip to content

Instantly share code, notes, and snippets.

View bartwttewaall's full-sized avatar

Bart Wttewaall bartwttewaall

View GitHub Profile
@bartwttewaall
bartwttewaall / NoteMath.js
Created November 25, 2019 09:31
Conversion of midi note numbers to a linear scale so they can be drawn more easily. The testFrequency method show how to use it
// get frequency from piano key number t
export function keyToFrequency(n, base = 440, keys = 12) {
return base * Math.pow(2, n / keys);
}
// get inverse frequency from piano key number t
export function keyToInverseFrequency(n, base = 440, keys = 12) {
return base * -Math.pow(2, -n / keys);
}
@bartwttewaall
bartwttewaall / ObjectPool.js
Created November 25, 2019 09:47
Modified getify/deePool with additional functionality
// modified https://github.com/getify/deePool
const EMPTY_SLOT = Object.freeze(Object.create(null));
export default class ObjectPool {
constructor(objectFactory = () => {}, initialSize) {
this.objectFactory = objectFactory;
this.objPool = [];
this.nextFreeSlot = null;
if (!!initialSize) this.grow(initialSize);
@bartwttewaall
bartwttewaall / shipping-date.util.ts
Last active December 17, 2019 12:56
Angular Material mat-datepicker custom date validation and filter rules with extensible settings
const daysOffset = 1; // next day delivery
const deadlineTime = 17 * 3600; // 17:00 in seconds
const unavailableDays = [0, 1]; // sunday = 0, monday = 1
const unavailableDates = [
/* 2019 */
{ dateString: '2019-01-01', name: 'Nieuwjaarsdag' },
{ dateString: '2019-04-01', name: '1e paasdag' },
{ dateString: '2019-04-22', name: '2e paasdag' },
{ dateString: '2019-04-27', name: 'Koningsdag' },
{ dateString: '2019-05-30', name: 'Hemelvaartsdag' },
git lfs track "*.3ds" "*.3g2" "*.3gp" "*.7z" "*.a" "*.aac" "*.adp" "*.ai" "*.aif" "*.aiff" "*.alz" "*.ape" "*.apk" "*.ar" "*.arj" "*.asf" "*.au" "*.avi" "*.bak" "*.baml" "*.bh" "*.bin" "*.bk" "*.bmp" "*.BMP" "*.btif" "*.bz2" "*.bzip2" "*.cab" "*.caf" "*.cgm" "*.class" "*.cmx" "*.cpio" "*.cr2" "*.csv" "*.cur" "*.dat" "*.dcm" "*.deb" "*.dex" "*.djvu" "*.dll" "*.dmg" "*.dng" "*.doc" "*.docm" "*.docx" "*.dot" "*.dotm" "*.dra" "*.DS_Store" "*.dsk" "*.dts" "*.dtshd" "*.dvb" "*.dwg" "*.dxf" "*.ecelp4800" "*.ecelp7470" "*.ecelp9600" "*.egg" "*.eol" "*.eot" "*.epub" "*.exe" "*.f4v" "*.fbs" "*.fh" "*.fla" "*.flac" "*.fli" "*.flv" "*.fpx" "*.fst" "*.fvt" "*.g3" "*.gif" "*.GIF" "*.graffle" "*.gz" "*.gzip" "*.h261" "*.h263" "*.h264" "*.icns" "*.ico" "*.ief" "*.img" "*.ipa" "*.iso" "*.jar" "*.jpeg" "*.JPEG" "*.jpg" "*.JPG" "*.jpgv" "*.jpm" "*.jxr" "*.key" "*.ktx" "*.lha" "*.lib" "*.lvp" "*.lz" "*.lzh" "*.lzma" "*.lzo" "*.m3u" "*.m4a" "*.m4v" "*.mar" "*.mdi" "*.mht" "*.mid" "*.midi" "*.mj2" "*.mka" "*.mkv" "*.mmr" "*.mng" "
function setupDownload() {
// quick test to check if download is available on anchors (fake Modernizr implementation)
var anchor = document.createElement("A");
var Modernizr = { adownload: "download" in anchor };
delete anchor;
if (Modernizr.adownload) {
var downloads = document.querySelectorAll("a[download]");
for (var i = 0; i < downloads.length; i++) {
@bartwttewaall
bartwttewaall / sync-fork.git
Created April 30, 2020 12:35
Sync a private repository to a fork repository (used by Spicytrip)
I forked the repo to my own account and then cloned it to my PC
git clone https://github.com/bartwttewaall/spicytrip-web.git
Then I added a new upstream repository as specified in this article with the original repository url from wirelab
git remote add upstream https://github.com/wirelab/spicytrip-web.git
I then double checked the remotes with
git remote -v
and I now see both 2 origin and 2 upstream remotes.
@bartwttewaall
bartwttewaall / MyExtensions.php
Created May 1, 2020 09:40
Twig usort extension
<?php
declare(strict_types=1);
namespace App\MyBundle\Twig;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
final class MyExtensions extends AbstractExtension
@bartwttewaall
bartwttewaall / array-set-operations.js
Last active May 25, 2021 08:28
Set opterations on 2 arrays: intersection, difference, union
// Intersection
let intersection = arrA.filter(x => arrB.includes(x));
// Difference
let difference = arrA.filter(x => !arrB.includes(x));
// Symmetrical Difference 1st syntax
let symmetricalDifference = arrA
.filter(x => !arrB.includes(x))
.concat(arrB.filter(x => !arrA.includes(x)));
@bartwttewaall
bartwttewaall / html-link-to-object.ts
Created July 29, 2020 09:17
Parse html links in a string to an object
@bartwttewaall
bartwttewaall / html-link-to-object.ts
Last active July 29, 2020 09:46
Parse html links in a string to an object