Skip to content

Instantly share code, notes, and snippets.

Avatar
😈
Doing evil things, probably. Sorry...

James Titcumb asgrim

😈
Doing evil things, probably. Sorry...
View GitHub Profile
@asgrim
asgrim / index.php
Created Jul 30, 2012
Crazy Morse-encoded PHP executor. Dirty and quick, no apologies for this code.
View index.php
<?php
require 'morselib.php';
$morse = new morselib();
eval($morse->decode(file_get_contents("site.morse")));
@asgrim
asgrim / DisallowBlacklistedClassUsage.php
Last active May 1, 2020
Simplified plugin for Psalm that does (part of) what I wanted in this Tweet: https://twitter.com/asgrim/status/1256181096938647555
View DisallowBlacklistedClassUsage.php
<?php
declare(strict_types=1);
namespace StaticAnalysisPlugin;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\StaticCall;
use Psalm\Codebase;
View parps.php
<?php
final class BookHandler
{
public function __construct(AggregateRepository $bookLibrary) {}
public function handleCheckInBook(CheckInBook $command) {}
public function handleCheckOutBook(CheckOutBook $command) {}
}
@asgrim
asgrim / test.php
Created Apr 2, 2019
Get all the classes and functions in a file
View test.php
<?php
declare(strict_types=1);
use Roave\BetterReflection\BetterReflection;
use Roave\BetterReflection\Reflector\ClassReflector;
use Roave\BetterReflection\Reflector\FunctionReflector;
use Roave\BetterReflection\SourceLocator\Type\SingleFileSourceLocator;
$fileName = 'my-file-with-stuff.php';
@asgrim
asgrim / stream-ips.sh
Created Mar 2, 2018
Used to use this on browscap-site to watch for IP abuse and block them
View stream-ips.sh
#!/bin/bash
set -uox pipefail
RUN=true
TIMEOUT=60
trap 'kill -INT -$PID; RUN=false' INT
file="/tmp/ips"
# varnishncsa > $file
View workshop.md

Best practices for crafting high quality PHP apps

This prototype works, but it’s not pretty, and now it’s in production. That legacy application really needs some TLC. Where do we start? When creating long lived applications, it’s imperative to focus on good practices. The solution is to improve the whole development life cycle; from planning, better coding and testing, to automation, peer review and more. In this tutorial, we’ll take a deep dive into each of these areas, looking at how we can make positive, actionable change in our workflow.

This workshop intends to improve your skills in planning, documenting, some aspects of development, testing and delivery of software for both legacy and greenfield projects. The workshop is made up of multiple exercises, allowing dynamic exploration into the various aspects of the software development life cycle. In each practical exercise, we'll brainstorm and investigate solutions, ensuring they are future-proofed, well tested and lead to the ultimate goal of conf

View async.php
<?php
class x {
async public function highlightFileContents($path) : string {
$source = await Amp\File\get($path);
return highlight_string($source, true);
}
}
$highlighted = Amp\wait((new x())->highlightFileContents("helpers.php"));
View async.php
<?php
class x {
async static function highlightFileContents($path) {
$source = await Amp\File\get($path);
return highlight_string($source, true);
}
}
$highlighted = Amp\wait(x::highlightFileContents("helpers.php"));