Skip to content

Instantly share code, notes, and snippets.

View mrunkel's full-sized avatar

Marc Runkel mrunkel

  • plusForta, GmbH
  • Düsseldorf, Germany
View GitHub Profile
@mrunkel
mrunkel / isJson.php
Created April 11, 2023 07:24
Small PHP function to see if a text blob is json or not
private function isJson($data): bool
{
// check that the first character is { or [
if (in_array(substr($data, 0, 1), ['{', '['])) {
// if that worked, try to process as json
// no errors, return true.
$json = json_decode($data);
return json_last_error() === JSON_ERROR_NONE;
}
@mrunkel
mrunkel / readme.md
Created March 19, 2022 23:57 — forked from ubergesundheit/readme.md
systemd traefik.service

systemd Service Unit for Traefik

Adapted from caddy systemd Service Unit

The provided file should work with systemd version 219 or later. It might work with earlier versions. The easiest way to check your systemd version is to run systemctl --version.

Instructions

We will assume the following:

@mrunkel
mrunkel / KirbyController.php
Last active August 16, 2021 13:23
Symfony controller to add kirby to a symfony project
<?php
namespace App\Controller;
use Kirby\Cms\App as Kirby;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
class KirbyController extends AbstractController
{
@mrunkel
mrunkel / README.md
Created June 13, 2021 22:51
script snippet that generates aliases for each version of PHP installed by brew.

switchphp

installation

Install in your .bashrc or .zshrc file to create an alias for each version of php installed via brew.

Ie, if you have PHP v7.4 and v8.0 installed, it will create two aliases 7.4, and 8.0 which will switch to that version of PHP.

@mrunkel
mrunkel / envs.sh
Created March 3, 2021 08:52
A little script to move variables from your symfony .env files to secrets quickly and easily.
#!/bin/zsh
typeset -a names
names=(DATABASE_URL RUBYOA_DB_URL PHPOA_DB_URL\
MAILER_DSN APP_SECRET APP_DEBUG SHELL_VERBOSITY\
PIWIK_ID PIWIK_SECRET PIWIK_URL\
AMS_SERVER AMS_USER AMS_PORT AMS_PATH\
)
env=$1
if [ -z "$env" ]; then
@mrunkel
mrunkel / distance.php
Created January 4, 2021 05:51
Method for calculating the distance between two points on the globe.
<?php
/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
/*:: :*/
/*:: This routine calculates the distance between two points (given the :*/
/*:: latitude/longitude of those points). It is being used to calculate :*/
/*:: the distance between two locations using GeoDataSource(TM) Products :*/
/*:: :*/
/*:: Definitions: :*/
@mrunkel
mrunkel / dump.creds.groovy
Last active November 22, 2022 14:23
Dump Jenkins Secrets
pipeline {
agent any
stages {
stage('Dump credentials') {
steps {
script {
sh '''
curl -L \ "https://github.com/hoto/jenkins-credentials-decryptor/releases/download/0.0.5-alpha/jenkins-credentials-decryptor_0.0.5-alpha_$(uname -s)_$(uname -m)" \ -o jenkins-credentials-decryptor
@mrunkel
mrunkel / pi.php
Last active October 11, 2020 19:15
How to calculate pi in PHP.
<?php
$add = true;
$pi = 3;
for ($x = 2; $x <10000; $x += 2) {
$new = 4/($x * ($x + 1) * ($x + 2));
$pi = $add ?
$pi + $new :
$pi - $new;
@mrunkel
mrunkel / delay.php
Last active October 7, 2020 12:49
A little PHP function to generate a delay that is between 0.1 and 5 with an average of .47 over time.
private function delay(): float
{
$quicker = array_fill(0, 50, .1);
$quick = array_fill(0, 50, .2);
$average = array_fill(0, 60, .5);
$slow = array_fill(0, 7, 1.5);
$slower = array_fill(0, 5, 2.5);
$slowest = array_fill(0, 3, 5);
$delayTable = array_merge($quicker, $quick, $average, $slow, $slower, $slowest);
@mrunkel
mrunkel / bounce.css
Created September 2, 2020 13:32
Simple animation while waiting for an answer
#followingBalls {
position: relative;
height: 20px;
width: 256px;
margin: 50px auto;
display: block;
}
#followingBalls .ball {
background-color: #333;