Skip to content

Instantly share code, notes, and snippets.

View asgrim's full-sized avatar
😈
Doing evil things, probably. Sorry...

James Titcumb asgrim

😈
Doing evil things, probably. Sorry...
View GitHub Profile
@asgrim
asgrim / stream-ips.sh
Created March 2, 2018 18:22
Used to use this on browscap-site to watch for IP abuse and block them
#!/bin/bash
set -uox pipefail
RUN=true
TIMEOUT=60
trap 'kill -INT -$PID; RUN=false' INT
file="/tmp/ips"
# varnishncsa > $file

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

<?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"));
<?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"));
@asgrim
asgrim / app.php
Last active May 1, 2017 15:13
Example for using `ciaranmcnulty/behat-psr7extension` with a Zend Expressive app
<?php
declare(strict_types=1);
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
/** @var \Interop\Container\ContainerInterface $container */
$container = require __DIR__ . '/../config/container.php';
/** @var \Zend\Expressive\Application $app */
@asgrim
asgrim / pre-commit
Created December 31, 2015 11:46
Never commit a broken test again...
#!/bin/bash
echo -n "Running phpunit... "
vendor/bin/phpunit --stop-on-failure --stop-on-error > /dev/null
if [ $? -ne 0 ]
then
echo "[FAILED]"
exit 1
fi
<?php
$months = array_map(
function ($i) {
return (new \DateTimeImmutable())->setDate(2017, $i, 1)->format('F');
},
range(1, 12)
);
var_dump($months);
@asgrim
asgrim / uaseragents.csv
Created August 6, 2013 10:34
user agents list
We can make this file beautiful and searchable if this error is corrected: It looks like row 2 should actually have 2 columns, instead of 3. in line 1.
2347,Mozilla/5.0 (compatible; monitis - premium monitoring service; http://www.monitis.com)
910,Mozilla/5.0 (PlayBook; U; RIM Tablet OS 2.1.0; en-US) AppleWebKit/536.2+ (KHTML, like Gecko) Version/7.2.1.0 Safari/536.2+
678,checks.panopta.com
206,Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US); 0110120602120527
89,ClickTale bot
41,AddThis.com robot tech.support@clearspring.com
35,Mozilla/5.0 (BB10; Kbd) AppleWebKit/537.10+ (KHTML, like Gecko) Version/10.1.0.2342 Mobile Safari/537.10+
33,Mozilla/5.0 (BB10; Touch) AppleWebKit/537.10+ (KHTML, like Gecko) Version/10.1.0.2354 Mobile Safari/537.10+
31,Mozilla/5.0 (BB10; Touch) AppleWebKit/537.10+ (KHTML, like Gecko) Version/10.0.10.690 Mobile Safari/537.10+
25,Mozilla/5.0 (BB10; Touch) AppleWebKit/537.10+ (KHTML, like Gecko) Version/10.1.0.1720 Mobile Safari/537.10+