Skip to content

Instantly share code, notes, and snippets.

@davidrjonas
davidrjonas / build-dropwatch.dockerfile
Last active February 23, 2022 21:56
Build dropwatch for Debian Buster
FROM debian:buster
# backports is required for checkinstall
RUN echo 'deb http://deb.debian.org/debian buster-backports main' > /etc/apt/sources.list.d/backports.list
RUN apt-get update && apt-get install -y \
curl build-essential dh-autoreconf pkg-config \
libnl-3-dev libnl-genl-3-dev \
libpcap-dev binutils-dev libreadline-dev \
checkinstall
@davidrjonas
davidrjonas / function_mock.php
Created February 3, 2017 03:28
Using PHP namespaces to mock functions
<?php
// Define the function in the namespace that the caller is in.
namespace App {
function query() {
return call_user_func_array([$GLOBALS['__doubles']['query'], 'call'], func_get_args());
}
}
namespace Tests {
@davidrjonas
davidrjonas / flatmap.php
Last active October 8, 2021 16:04
Simple flatmap() or mapcat() for PHP 7
<?php
/**
* If you need something safer or more complete see https://github.com/lstrojny/functional-php,
* in particular, https://github.com/lstrojny/functional-php/blob/master/src/Functional/FlatMap.php
*
* @param Callable $fn Mapping function that returns an array
* @param array $array Data over which $fn will be mapped
* @return array
*/