Skip to content

Instantly share code, notes, and snippets.

@marcusandre
marcusandre / sequential-map.ts
Last active Oct 19, 2022
Sequential version of Map in continuation passing style
View sequential-map.ts
type MapHandler<T> = (item: T, index: number, callback: (result: T) => void) => void;
type MapDoneHandler<T> = (results: T[]) => void;
function map<T>(array: T[], handler: MapHandler<T>, done: MapDoneHandler<T>) {
let index = 0;
let results: T[] = [];
step()
function step() {
View reset.css
/* Reset */
*:where(:not(iframe, canvas, img, svg, video):not(svg *, symbol *)) {
all: unset;
display: revert;
}
*,
*::before,
*::after {
View quersumme.js
const dayjs = require('dayjs')
let start = dayjs().startOf('day')
const end = start.add(1, 'day')
const results = {}
while (start.isBefore(end)) {
const fmt = start.format('HH:mm')
const qs = fmt
.replace(':', '')
@marcusandre
marcusandre / Dockerfile
Last active Mar 18, 2019
run your Lumen development efforts with docker.
View Dockerfile
FROM php:7.3-apache
ENV APACHE_DOCUMENT_ROOT /var/www/html/public
RUN docker-php-ext-install pdo pdo_mysql
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf
RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf
RUN a2enmod rewrite
@marcusandre
marcusandre / header.js
Created Feb 14, 2019
simple sticky scrolling header
View header.js
/* global $ */
import throttle from 'raf-throttle'
export default class Header {
constructor (el) {
this.el = el
this.hiddenClass = 'hidden'
}
stick () {
@marcusandre
marcusandre / style.css
Created Jan 10, 2019
Solve word break of long titles and headlines
View style.css
h1,
h2,
h3,
h4,
h5,
h6,
.word-wrap,
.word-break {
overflow-wrap: break-word;
word-wrap: break-word;
@marcusandre
marcusandre / iban-regex.md
Last active Dec 11, 2018
IBAN regular expressions
View iban-regex.md

IBAN regular expression

The following regular expression will match:

  • AB12 1234 1234 1234 1234
  • AB12 1234 1234 1234 1234 1
  • AB12 1234 1234 1234 1234 12

but also:

@marcusandre
marcusandre / sw.js
Last active Nov 19, 2018
Simple Service Worker to respond with cached request
View sw.js
(function () {
'use strict'
self.addEventListener('fetch', event => {
let request = event.request
if (request.method !== 'GET') {
return
}
event.respondWith(
caches.match(request)
.then(response => {
@marcusandre
marcusandre / mysql.service
Last active Oct 16, 2018
get mysql config file hierarchy on the system
View mysql.service
/usr/sbin/mysqld --verbose --help | grep -A 1 "Default options"
@marcusandre
marcusandre / vagrant-suspend-all.sh
Created Feb 15, 2018
Suspend all running vagrant machines
View vagrant-suspend-all.sh
#!/usr/bin/env bash
ids=$(vagrant global-status | grep 'running' | cut -d ' ' -f 1 | xargs)
vagrant suspend $ids