Skip to content

Instantly share code, notes, and snippets.

View Rarst's full-sized avatar
Otherwise occupied.

Andrey Savchenko Rarst

Otherwise occupied.
View GitHub Profile
View memoize.php
function memoize($target) {
static $memo = new WeakMap;
return new class ($target, $memo) {
function __construct(
protected $target,
protected &$memo,
) {}
Ocramius / psalm-compendium.php
Last active November 9, 2023 07:27
A small compendium of what is possible with `vimeo/psalm` 3.9.x to add some decent type system features to PHP
View psalm-compendium.php
// -- types are a compile-time propagated concept
class TheType
/** @var string */
public $foo = 'bar';
barryosull / index.php
Created February 28, 2020 10:32
PHPUnit Code Coverage Report of Web App
View index.php
How to run a code coverage report on a web page:
Simply put this code after the vendor require and before the rest of the calling logic.
(Assumes you have PHPUnit installed)
require_once __DIR__ . "/../vendor/autoload.php";
gmazzap / VersionNumber.php
Created March 24, 2019 19:37
Version number parser and comparator compatible with both Semver and WordPress version numbers.
View VersionNumber.php
* Copyright 2019 Inpsyde GmbH
* @license MIT
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
westonruter / list-document-images.js
Last active August 7, 2018 09:55
Prior to Performance Timeline API getting list of all images in document would require looking at document.images and inspectomg stylesheets to find any referenced background-images; but now with the Performance Timeline API it's easy to get a list of all images (assuming they have image filename extensions)
View list-document-images.js
function getDocumentImages() {
return performance.getEntriesByType('resource')
.map( ( entry ) => )
.filter( ( url ) => {
const parsedUrl = new URL( url );
return /\.(png|jpe?g|gif|webp|svg)$/i.test( parsedUrl.pathname );
} );
DragonBe / Vagrantfile-php7.2
Created March 20, 2018 09:29
A quick Vagrant file to get started with PHP 7.2
View Vagrantfile-php7.2
# -*- mode: ruby -*-
# vi: set ft=ruby :
@script = <<SCRIPT
# Fix for
if ! grep -q "ubuntu-xenial" /etc/hosts; then
echo " ubuntu-xenial" >> /etc/hosts
egmontkob /
Last active March 2, 2024 11:13
Hyperlinks in Terminal Emulators
gmazzap / AutoPaginatedQuery.php
Last active April 8, 2016 21:49
`WP_Query` subclass that takes a non-paginated query and split into different paginated queries offering a transparent interface to "standard loop" usage.
View AutoPaginatedQuery.php
namespace GM;
* `WP_Query` subclass that takes a non-paginated query and split into different
* paginated queries offering a transparent interface to "standard loop" usage.
* The class is not 100% transparent:
* - the var `$posts` and the method `get_posts()`, that are not used directly
* in standard loop usage, here don't return array of all posts, but only posts
MikeNGarrett / wp-config.php
Last active February 6, 2024 15:12
All those damned wp-config constants you can never remember.
View wp-config.php
// PHP memory limit for this site
define( 'WP_MEMORY_LIMIT', '128M' );
define( 'WP_MAX_MEMORY_LIMIT', '256M' ); // Increase admin-side memory limit.
// Database
define( 'WP_ALLOW_REPAIR', true ); // Allow WordPress to automatically repair your database.
define( 'DO_NOT_UPGRADE_GLOBAL_TABLES', true ); // Don't make database upgrades on global tables (like users)
// Explicitely setting url
gmazzap / Angie.php
Last active April 6, 2016 17:35
Very simple, quite powerful, extensible, plain-PHP one-class template engine.
View Angie.php
<?php namespace GM;
* Angie. Very simple, and quite powerful, plain PHP template engine.
* @author Giuseppe Mazzapica <>
* @license MIT
class Angie