Skip to content

Instantly share code, notes, and snippets.

View bcremer's full-sized avatar

Benjamin Cremer bcremer

View GitHub Profile
@bcremer
bcremer / gist:12167985b442d0d195de
Created August 5, 2014 12:01
NGINX as caching REST-API Proxy
upstream backend {
server localhost:8080;
#server backup1.example.com:8080 backup;
#server backup2.example.com:8080 backup;
}
# Set cache dir
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=one:10m;
# Set cache key to include identifying components
@bcremer
bcremer / gist:7524492
Last active August 5, 2023 23:09
My i3 config.
# .config/i3/config
set $mod Mod4
set $alt Mod1
font pango:Segoe UI 8
# Use Mouse+$mod to drag floating windows to their wanted position
floating_modifier $mod
## Solarized colorshema
@bcremer
bcremer / build.xml
Created July 30, 2013 09:23
Apache ANT If/Else-Condition without ANT-Contrib
<?xml version="1.0" encoding="utf-8"?>
<project name="Ant Condition Example">
<target name="myConditionalTask" depends="myConditionalTask-check, myConditionalTask-fail" if="myConditionalTask-check-property">
<echo message="EXECUTE myConditionalTask" />
</target>
<target name="myConditionalTask-fail" unless="myConditionalTask-check-property">
<echo message="SKIPPED myConditionalTask" />
</target>
@bcremer
bcremer / build-minimal-php.sh
Last active May 11, 2023 14:39
Compile Minimal Version of PHP used for Lint-Check legacy code
mkdir source
cd source
wget http://museum.php.net/php5/php-5.2.17.tar.gz
tar xvf php-5.2.17.tar.gz
cd php-5.2.17
./configure --disable-all --enable-static --enable-cli
make
cp sapi/cli/php ~/bin/php5.2.17-x64-static
@bcremer
bcremer / Dockerfile
Created December 12, 2018 20:42
Multi-Stage Dockerfile to prepopulated MySQL Image
## See: https://serverfault.com/a/915845/17736
FROM percona/percona-server:5.7 as builder
USER root
RUN mkdir -p /initialized-db && chown -R mysql:mysql /initialized-db
# That file does the DB initialization but also runs mysql daemon, by removing the last line it will only init
RUN ["sed", "-i", "s/exec \"$@\"/echo \"not running $@\"/", "/docker-entrypoint.sh"]
@bcremer
bcremer / BaseTestCase.php
Created April 7, 2020 13:21
Reset PHPUnit testcase properties to save memory after each test.
<?php
abstract class BaseTestCase extends PHPUnit\Framework\TestCase
{
/**
* Reset the properties to save memory after each test.
* @see https://kriswallsmith.net/post/18029585104/faster-phpunit
*/
protected function tearDown(): void
{
<?php
// see https://confluence.jetbrains.com/display/PhpStorm/PhpStorm+Advanced+Metadata
namespace PHPSTORM_META {
override(\Doctrine\ORM\EntityManager::find(0), map([
'' => '@',
]));
override(\Interop\Container\ContainerInterface::get(0), map([
'' => '@',
@bcremer
bcremer / convert_audible_aax_to_m4b.sh
Last active September 14, 2020 08:32
Script to convert audible aax files to DRM-free m4b files via ffmpeg
#!/usr/bin/bash
## extract once using https://github.com/inAudible-NG/audible-activator
activationBytes=""
for m in *.aax; do
basename=${m%.aax}
# extract audio stream
ffmpeg -activation_bytes $activationBytes -i ${basename}.aax -vn -c:a copy ${basename}.m4a
# extract thumbnail
ffmpeg -activation_bytes $activationBytes -i ${basename}.aax -an -vcodec copy ${basename}.jpg
@bcremer
bcremer / ZendOpcache + APCu
Last active September 9, 2020 21:03
Alternative Bytecodecache + Datacache based on ZendOpcache and APCu
# http://pecl.php.net/package/APCu
# http://pecl.php.net/package/ZendOpcache
# Install ZendOpcache
sudo pecl install ZendOpcache-beta
sudo -i
cat > /etc/php5/mods-available/opcache.ini << EOF
zend_extension=/usr/lib/php5/20100525/opcache.so
opcache.memory_consumption=128
opcache.interned_strings_buffer=8