Skip to content

Instantly share code, notes, and snippets.

View bartwttewaall's full-sized avatar

Bart Wttewaall bartwttewaall

View GitHub Profile
import { Component, Input } from '@angular/core';
const currencyPattern = /^([\D\s]+?)(?=[+-\d])/;
const trailingZeroesPattern = /(,|.)00$/;
@Component({
selector: 'price',
template: '{{ formattedPrice }}',
styles: [':host { vertical-align: middle; }']
})
# 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/#
@bartwttewaall
bartwttewaall / math-utils.js
Last active June 23, 2022 09:50
Bunch of small math methods like clamp and range
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) {
@bartwttewaall
bartwttewaall / flatten_unique.js
Created September 2, 2019 15:14
Flatten an array with ES6 functionalities
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>;
@bartwttewaall
bartwttewaall / mixin-truncate.scss
Created August 5, 2019 14:27
Set wordwrap properties for ellipsis text
/* example: @include truncate(24px, 30px, 3); */
@mixin truncate($font-size, $line-height, $lines-to-show) {
display: block; // Fallback for non-webkit
display: -webkit-box;
max-width: 400px;
font-size: $font-size;
line-height: $line-height;
-webkit-line-clamp: $lines-to-show;
-webkit-box-orient: vertical;
@bartwttewaall
bartwttewaall / express_get-robots.js
Created August 1, 2019 12:33
Generate robots.txt on the fly which makes it possible to only allow web crawlers when in production mode
app.get("/robots.txt", function(req, res) {
res.type("text/plain");
var rules = {
"User-agent": "*",
"Disallow": process.env.NODE_ENV === "production" ? "" : "/"
};
var flattenedString = Object.keys(rules)
.map((key) => key + ": " + rules[key])
.join("\n");
res.send(flattenedString);
@bartwttewaall
bartwttewaall / dl-horizontal.scss
Created July 24, 2019 15:37
Horizontal definition list for Bootstrap4 in the same style as there used to be included in Bootstrap3
.dl-horizontal {
$definitionWidth: 100px;
display: flex;
flex-wrap: wrap;
> dt {
width: $definitionWidth;
text-align: left;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
@bartwttewaall
bartwttewaall / Unity3D_FullscreenButton.cs
Created July 22, 2019 09:58
Custom script extending Button: adds a onDown ButtonClickedEvent in order to trigger Screen.fullscreen when clicked and not on the next interaction event.
/* Usage
fullscreenButton.onDown.AddListener (() => {
Screen.fullScreen = !Screen.fullScreen;
});
*/
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
@bartwttewaall
bartwttewaall / Unity3D_CleanupSceneBuildProcessor.cs
Created July 22, 2019 09:53
Build script to strip out Colliders from a scene, used in a project where all static colliders we exported as a json file and were not needed within the scene at runtime which made it more performant.
#if UNITY_EDITOR
/**
This script should be located in an Editor folder
No need to try assigning it to a GameObject
It will run automatically when playing from the editor or during a build
see: https://docs.unity3d.com/ScriptReference/Build.IProcessSceneWithReport.OnProcessScene.html
*/
using System;
@bartwttewaall
bartwttewaall / Unity3D_ChatMessageItemRenderer.cs
Last active July 22, 2019 09:59
A single chat richtext (multi)line prefab with fade in/out method and optional timeout event. Extends ItemRenderer
using System;
using System.Collections;
using DG.Tweening;
using TMPro;
using UnityEngine;
using Wirelab.Pages;
public class ChatMessageItemRenderer : ItemRenderer<ChatMessageData> {
public BaseEvent onTimeout;