Skip to content

Instantly share code, notes, and snippets.

View frankdejonge's full-sized avatar

Frank de Jonge frankdejonge

View GitHub Profile
@frankdejonge
frankdejonge / until-breakpoint-tailwind-plugin.js
Created July 16, 2022 18:15
Tailwind plugin to add screen variants up until a breakpoint
const plugin = require('tailwindcss/plugin');
let untilBreakpoint = plugin(({ addVariant, config }) => {
let screens = config('theme.screens');
for (let screen in screens) {
let def = screens[screen];
if (typeof def === 'string') {
addVariant(`-${screen}`, `@media (max-width: calc(${def} - 1px))`);
@frankdejonge
frankdejonge / README.md
Last active June 12, 2022 22:07
PHP Wither template

You can copy the XML below and paste them into your live templates in PHPStorm to start using it :)

@frankdejonge
frankdejonge / paginated-generator.php
Created May 25, 2021 18:12
Generate use-case: paginated API call example
<?php
/**
* Imagine this is an API call
*/
function listPage(int $i): array
{
$next = $i >= 9 ? null : $i + 1;
return ['cursor' => $next, 'items' => array_fill(0, 5, $i)];
}
<?php
declare(strict_types=1);
namespace AcmeCompany\Flysystem;
use Aws\CommandInterface;
use Aws\S3\Exception\S3Exception;
use Aws\S3\S3ClientInterface;
use Exception;
<?php
final class EventDispatcher {
private $listeners = [];
public function listen(callable $listener)
{
$this->listeners[] = $listener;
}
<?php
interface EventDispatcher
{
public function listen(string $event, callable $listener);
public function emit(object $event): object;
}
class ExampleEventDispatcher implements EventDispatcher
{
@frankdejonge
frankdejonge / AssetLocator.php
Last active October 22, 2018 14:13
Asset locating in Symfony with cashed manifest contents.
<?php
namespace App\Twig;
interface AssetLocator
{
public function lookup(string $asset): string;
}
<?php
namespace App\Translator;
use MessageFormatter;
use Symfony\Component\Translation\MessageSelector;
class IcuMessageSelector extends MessageSelector
{
/**
@frankdejonge
frankdejonge / compile.php
Created March 8, 2017 14:46
Symfony Routing optimisation.
<?php
use Symfony\Component\Routing\Matcher\Dumper\PhpMatcherDumper;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
include __DIR__.'/vendor/autoload.php';
if (count($argv) < 2) {
die('Not enough arguments');
@frankdejonge
frankdejonge / example.php
Last active May 21, 2017 17:41
Mirco-time precise DateTime(Immutable) instances.
<?php
function mirco_time_precise_date_time_immutable()
{
return DateTimeImmutable::createFromFormat('U.u', sprintf('%.6F', microtime(true)));
}