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 / Envoy.blade.php
Created August 23, 2014 15:59
Envoy server at a non-standard port
@servers(['web' => 'user@example.com -p 1234'])
@task('deploy', ['on' => 'web'])
ls -la
@endtask
@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)];
}
@frankdejonge
frankdejonge / example.php
Created October 31, 2014 15:01
Flysystem Download from FTP
<?php
$ftp = new League\Flysystem\Filesystem(new League\Flysystem\Adapter\Ftp($settings));
$local = new League\Flysystem\Filesystem(new League\Flysystem\Adapter\Local($path));
$local->write($destination, $ftp->read($source));
@frankdejonge
frankdejonge / getter.tpl
Created July 1, 2016 21:46
PHPStorm getter/setter templates.
#set($returnType = ": $TYPE_HINT")
## First we check against a blacklist of primitive and other common types used in documentation.
#set($nonTypeHintableTypes = ["", "mixed", "number", "void", "object", "real", "double", "resource", "null"])
#foreach($nonTypeHintableType in $nonTypeHintableTypes)
#if ($nonTypeHintableType == $TYPE_HINT)
#set($returnType = "")
#end
#end
## Make sure the type hint actually looks like a legal php class name(permitting namespaces too) for future proofing reasons.
## This is important because PSR-5 is coming soon, and will allow documentation of types with syntax like SplStack<int>
<?php
declare(strict_types=1);
namespace AcmeCompany\Flysystem;
use Aws\CommandInterface;
use Aws\S3\Exception\S3Exception;
use Aws\S3\S3ClientInterface;
use Exception;
@frankdejonge
frankdejonge / example.php
Created July 20, 2015 12:05
Concurrent upload to S3 buckets with Flysystem and pthreads
<?php
use Aws\S3\S3Client;
use League\Flysystem\AwsS3v3\AwsS3Adapter;
use League\Flysystem\Filesystem;
function get_filesystem() {
$client = new S3Client([
'credentials' => [
'key' => getenv('AWS_KET'),
<?php
interface EventDispatcher
{
public function listen(string $event, callable $listener);
public function emit(object $event): object;
}
class ExampleEventDispatcher implements EventDispatcher
{
<?php
final class EventDispatcher {
private $listeners = [];
public function listen(callable $listener)
{
$this->listeners[] = $listener;
}