Skip to content

Instantly share code, notes, and snippets.

@davidrjonas
davidrjonas / flatmap.php
Last active May 3, 2024 21:29
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
*/
@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 / 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
-- Bootstrap lazy.nvim
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
local lazyrepo = "https://github.com/folke/lazy.nvim.git"
local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath })
if vim.v.shell_error ~= 0 then
vim.api.nvim_echo({
{ "Failed to clone lazy.nvim:\n", "ErrorMsg" },
{ out, "WarningMsg" },
{ "\nPress any key to exit..." },