This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getUniqueArr = array => Array.from(new Set(array)); | |
const mergeArrs = (...arrs) => [].concat(...arrs); | |
const getUniqueMerge = (...arrs) => getUniqueArr(mergeArrs(...arrs)); | |
/** example with nested MenuItems | |
export interface MenuItem { | |
label: string; | |
icon?: string; | |
link?: Array<any>; | |
children?: Array<MenuItem>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const RAD2DEG = 180 / Math.PI; | |
export const DEG2RAD = Math.PI / 180; | |
// compute euclidean modulo of m % n | |
// https://en.wikipedia.org/wiki/Modulo_operation | |
export function euclideanModulo(n: number, m: number) { | |
return ((n % m) + m) % m; | |
} | |
export function clamp(value: number, min: number, max: number) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# On the server use the htpasswd command to generate a hashed login: | |
# $ htpasswd -c ~/domains/{domainname}/.htpasswd {username} | |
# then input a secret password. | |
<If "req('Host') == '{domainname}.wiredev.nl'"> | |
AuthType Basic | |
AuthUserFile ~/domains/{domainname}.wiredev.nl/.htpasswd/.htpasswd | |
AuthName "Acceptance" | |
# Make an exception for the letsencrypt folder | |
Require expr %{REQUEST_URI} =~ m#^/.well-known/acme-challenge/# |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, Input } from '@angular/core'; | |
const currencyPattern = /^([\D\s]+?)(?=[+-\d])/; | |
const trailingZeroesPattern = /(,|.)00$/; | |
@Component({ | |
selector: 'price', | |
template: '{{ formattedPrice }}', | |
styles: [':host { vertical-align: middle; }'] | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// create an array with indices 0..(amount-1) | |
export function fill(amount) { | |
return Array.from(Array(amount).keys()); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% set colClass = 'col-' ~ (12 / max(2, min(blogPosts.length, 4))) %} | |
<div class="row"> | |
{% for article in blogPosts %} | |
<article class="{{ colClass }}"> | |
... | |
</article> | |
{% endfor %} | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<svg preserveAspectRatio="xMidYMid meet"> <!-- fits the parent, centered --> | |
<svg preserveAspectRatio="xMidYMid slice"> <!-- fills the parent, centered --> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |