Skip to content

Instantly share code, notes, and snippets.

View rordi's full-sized avatar
🎓

Dietrich Rordorf rordi

🎓
View GitHub Profile
@rordi
rordi / ahvn13-validation.js
Last active July 31, 2020 12:35
Javascript-based validation of Swiss AHV numbers AHVN13 / EAN13 [Validierung von Schweizer AHV Nummern mit Javascript]
/**
* Javascript-based validation of Swiss AHV numbers AHVN13 / EAN13
* [Validierung von Schweizer AHV Nummern mit Javascript]
*/
var inp = document.getElementById('ahvn13');
inp.addEventListener('change', _validateAhvn13);
var _validateAhvn13 = function(input) {
var pattern = /^756\.(\d{4})\.(\d{4})\.(\d{2})$/; // format is 756.0000.0000.00
@rordi
rordi / docker-debug.md
Last active December 5, 2023 09:35
Docker debugging an existing image

Debugging a Docker image

Start up the Docker container from image:

docker run --entrypoint "/bin/bash" --rm imagename:latest -c "sleep 24h"

Obtain the container hash id:

docker ps
@rordi
rordi / crontab.md
Last active October 24, 2017 14:26
Give crontab access to env variables of www-data user within a Docker container

Give crontab access to env variables of www-data user within a Docker container

docker entrypoint

CRON_ENV=/var/www/env.sh
printenv | sed 's/^\(.*\)$/export \1/g' > ${CRON_ENV}
0xAd9b1FEFC98Ee16934DB03297B351FeF2ddb3866
@rordi
rordi / cors.md
Last active March 21, 2022 14:04
Simplest, configurable CORS implementation for Symfony through listeners

Simplest, configurable CORS implementation for Symfony through listeners

CorsListener.php event listener for pre-flight OPTIONS requests

<?php
/**
 * CorsListener.php
 *
 * @author Dietrich Rordorf
@rordi
rordi / phpdoc.md
Last active March 10, 2023 15:22
Generate PhpDoc Documentation with Docker

Easily create a PhpDoc documentation with this Docker container

Use following command from withint the root directory of your PHP project to create the PhpDocs in the ./docs subfolder of the project root. You may want to include only a ./src (Symfony) or ./app (Silex) subfolders in the analysis (do not run the documentator on the ./vendors folder):

docker run --rm -v $(pwd):/app instrumentisto/phpdoc -d /app -t ./docs

Remove a large file from previous git commit / GitHub

E.g. when accidentally committing a large file to a git repo and GitHub refises the commit.

git filter-branch --tree-filter 'rm -f path/to/large/file' HEAD

Afterwards, simply try to push to GitHub again...

@rordi
rordi / wordpress-proxy.md
Last active September 16, 2021 11:52
Run Wordpress behind a proxy server (avoid assets being blocked)

Run Wordpress behind a proxy server (avoid assets being blocked)

Wordpress has issues to detect the SSL connection betwenn the client and the proxy and thus may load static assets through http instead https, which will be blocked in moderns browsers (mixed content).

To circumvent the problem, simly extend your wp-config.php by following functions (insert towards the top of the config script):

/** Proxy SSL detection */

@rordi
rordi / hugo-prev-next-navigation-custom-section.order.md
Last active April 18, 2021 18:33
Previous / Next Navigation in Hugo with custom section order

Previous/Next navigation in Hugo with custom order based on param / attribute

This gist let's you return previous/next pages based on a frontmatter parameter in Hugo. In this exmaple, the frontmatter parameter is called position, where lower positions come first.

This prev / next navigation is looping: if there is no "next >" entry anymore, the first entry of the collection will be linked. Same for "< prev": if there is no previous element, the last element of the collection will be linked.

<div class="nav-prev-next">
    {{ $currentSection := (($.Site.GetPage "section" .Section).Pages.ByParam "position") }}
@rordi
rordi / selenium-chrome-options.js
Last active August 20, 2019 15:28
Javascript Selenium Web Driver with Chrome Options
const {Builder, By, Capabilities} = require('selenium-webdriver');
let chromeCapabilities = Capabilities.chrome();
let chromeOptions = {
'args': ['--test-type', '--headles', '--incognito', '--window-size=340,750'] // approx. size of an iPhone 5/SE
};
// "chromeOptions" was changed to "goog:chromeOptions" at some point...
chromeCapabilities.set('goog:chromeOptions', chromeOptions);