Skip to content

Instantly share code, notes, and snippets.

View bcremer's full-sized avatar

Benjamin Cremer bcremer

View GitHub Profile
@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 / 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 / anonymous_class_interface_implementation.php
Last active February 6, 2018 12:26
Only ever return implementations of an interface as an anonymous class coming from a factory.
<?php
/**
* https://twitter.com/Ocramius/status/959405445260726272
* only ever return implementations of an interface as an
* anonymous class coming from a factory.
*/
namespace Example;
@bcremer
bcremer / sodium_secretbox_demo.php
Last active October 5, 2017 12:03
Sodium Secretbox with user provided password
<?php
$password = 'My Plaintext Password';
$plaintext = 'This is my message';
$secretBox = new Secretbox();
$ciphertext = $secretBox->encrypt($plaintext, $password);
$decryptedPlaintext = $secretBox->decrypt($ciphertext, $password);
assertThat($decryptedPlaintext === $plaintext, 'Can decrypt');
@bcremer
bcremer / php-class-name-constant-case sensitivity-and-psr-11.md
Last active July 13, 2017 12:40
PHP class name constant (::class) is case insensitive and that might break your PSR-11 container access

PHP´s magic ::class-constant will not canonical the casing of your imports.

This can lead to hard to debug errors when you a using a case sensitive service PSR-11-locator like Zend\ServiceManager.

namespace FirstNamespace;

class TestClass {}
<?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 / fizzbuzz.php
Last active October 17, 2018 22:02
FizzBuzz without Conditionals in PHP
<?php
$fizzers = [1, 0, 0, 0];
$buzzers = [2, 0, 0, 0, 0];
$words = ['', 'Fizz', 'Buzz', 'FizzBuzz'];
foreach (range(1, 100) as $i) {
$words[0] = $i;
echo $words[$fizzers[$i % 3] + $buzzers[$i % 5]].PHP_EOL;
}
@bcremer
bcremer / Dockerfile
Last active January 6, 2017 11:56
Unifi Controller in Docker started by Systemd
FROM debian:jessie
MAINTAINER Jacob Alberty <[email protected]>
ENV DEBIAN_FRONTEND noninteractive
RUN echo "deb http://www.ubnt.com/downloads/unifi/debian unifi5 ubiquiti" > \
/etc/apt/sources.list.d/20ubiquiti.list && \
echo "deb http://downloads-distro.mongodb.org/repo/debian-sysvinit dist 10gen" > \
/etc/apt/sources.list.d/21mongodb.list && \
echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" > \
@bcremer
bcremer / htaccess_to_vhost.sh
Created January 5, 2017 07:35
htaccess_to_vhost
#!/usr/bin/env bash
#
# Converts .htaccess files to vhost directory directives
#
# http://httpd.apache.org/docs/2.4/howto/htaccess.html#when
# You should avoid using .htaccess files completely if you have
# access to httpd main server config file. Using .htaccess files
# slows down your Apache http server. Any directive that you can
# include in a .htaccess file is better set in a Directory block,
# as it will have the same effect with better performance.

Keybase proof

I hereby claim:

  • I am bcremer on github.
  • I am bcremer (https://keybase.io/bcremer) on keybase.
  • I have a public key whose fingerprint is C93E 6F38 AC81 F7BA 2EC1 822D 393E 661F BD0D 3A1B

To claim this, I am signing this object: