Skip to content

Instantly share code, notes, and snippets.

View bartwttewaall's full-sized avatar

Bart Wttewaall bartwttewaall

View GitHub Profile
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" "
@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' },
@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 / 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 / Vector2.js
Created November 25, 2019 09:27
Vector2 class with many handy methods. Needs to be written as TypeScript some day
export default class Vector2 {
constructor(x, y) {
this.x = x || 0;
this.y = y || 0;
}
// ---- public instance methods ----
get name() {
const v = this.clone().normalize();
@bartwttewaall
bartwttewaall / absolute-url.ts
Created November 19, 2019 12:43
Angular tips
// Get the absolute url in various ways:
const url1 = '/' + this.route.pathFromRoot.map(r => r.snapshot.url).filter(f => !!f[0]).map(([f]) => f.path).join('/');
const url2 = this.location.prepareExternalUrl(this.location.path());
@bartwttewaall
bartwttewaall / svg-examples.html
Created November 12, 2019 14:13
Settings to layout an svg element
<svg preserveAspectRatio="xMidYMid meet"> <!-- fits the parent, centered -->
<svg preserveAspectRatio="xMidYMid slice"> <!-- fills the parent, centered -->
@bartwttewaall
bartwttewaall / column-size-twig.twig
Created November 7, 2019 11:00
Calculate best fitting column size for dynamic list of content (bootstrap 12-columns layout)
{% set colClass = 'col-' ~ (12 / max(2, min(blogPosts.length, 4))) %}
<div class="row">
{% for article in blogPosts %}
<article class="{{ colClass }}">
...
</article>
{% endfor %}
</div>
@bartwttewaall
bartwttewaall / array-fill.js
Last active December 16, 2021 10:31
Array methods, akin to those from lodash / micro-dash
// create an array with indices 0..(amount-1)
export function fill(amount) {
return Array.from(Array(amount).keys());
}
@bartwttewaall
bartwttewaall / divide-evenly.js
Created October 3, 2019 10:57
An algorithm that divides items from one or more arrays over one or more output arrays, all in a single for-loop
function divideEvenly(arrays, numOutputs) {
const arraysLength = arrays.length;
const totalLength = arrays.reduce((amount, pool) => amount + pool.length, 0);
const result = [];
let pool, item, column;
for (let i = 0; i < totalLength; i++) {
pool = arrays[i % arraysLength];
item = pool[Math.floor(i / arraysLength)];
column = Math.floor(i / (totalLength / numOutputs));