Skip to content

Instantly share code, notes, and snippets.

View bcremer's full-sized avatar

Benjamin Cremer bcremer

View GitHub Profile
@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 <jacob.alberty@foundigital.com>
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:

php -r 'echo implode("\n", get_defined_functions()["internal"]);' | awk '{ print length($0) " " $0; }' | sort -rn | head -10
38 xml_set_processing_instruction_handler
38 intltz_create_time_zone_id_enumeration
38 intlcal_set_minimal_days_in_first_week
38 intlcal_get_minimal_days_in_first_week
37 mcrypt_module_is_block_algorithm_mode
37 mcrypt_module_get_supported_key_sizes
37 intlcal_set_repeated_wall_time_option
37 intlcal_get_repeated_wall_time_option
37 intlcal_get_keyword_values_for_locale