Skip to content

Instantly share code, notes, and snippets.

@pbowyer
pbowyer / modx.server-timing.plugin.php
Last active January 21, 2024 11:15
MODX plugin to set Server-Timing header
<?php
// Run on event onWebPagePrerender
// Comma-separated list of strings like: cache;desc="Cache Read";dur=23.2
// Expectation is duration is milliseconds
$totalTime = $modx->startTime ? sprintf("%2.2f", (microtime(true) - $modx->startTime) * 1000) : 0;
$queryTime = isset($modx->queryTime) ? sprintf("%2.2f", $modx->queryTime * 1000) : 0;
$queries = isset($modx->executedQueries) ? $modx->executedQueries : 0;
$phpTime = sprintf("%2.2f", ($totalTime - $queryTime));
@pbowyer
pbowyer / app.js
Created April 28, 2023 11:30
Loading data attributes into a Vue 3 app
import {createApp} from 'vue';
import {processDataAttributes} from "../lib/process-data-attributes.js";
const app = createApp({
data() {
return {
rootData: processDataAttributes(document.getElementById("app"))
}
}
});
app.mount('#app');
@pbowyer
pbowyer / Example.php
Created July 19, 2022 06:49
How does PHP internally represent objects? Profilers such as Tideways, Datadog PHP APM etc allow you to watch methods. They are limited to exact string matches and I want to understand why the PHP internals make this the way it's done.
<?php
interface I { function i(); }
class A implements I {
function a() {}
function i() {}
}
class B extends A {
# Marker to tell the VCL compiler that this VCL has been written with the
# 4.0 or 4.1 syntax.
vcl 4.1;
import std;
# Default backend definition. Set this to point to your content server.
backend default {
.host = "127.0.0.1";
.port = "8080";
@pbowyer
pbowyer / Mailhog Bash Script (systemd)
Created January 17, 2020 10:57 — forked from v-jacob/Mailhog Bash Script (systemd)
Mailhog setup with systemd
#!/usr/bin/env bash
echo ">>> Installing Mailhog"
# Download binary from github
wget --quiet -O ~/mailhog https://github.com/mailhog/MailHog/releases/download/v1.0.0/MailHog_linux_amd64
# Make it executable
chmod +x ~/mailhog
@pbowyer
pbowyer / criteria-to-query-builder.php
Created August 23, 2018 07:48 — forked from jgornick/criteria-to-query-builder.php
Doctrine: Criteria Array to Doctrine QueryBuilder
<?php
/**
* Recursively takes the specified criteria and adds too the expression.
*
* The criteria is defined in an array notation where each item in the list
* represents a comparison <fieldName, operator, value>. The operator maps to
* comparison methods located in ExpressionBuilder. The key in the array can
* be used to identify grouping of comparisons.
*
@pbowyer
pbowyer / umap_sparse.py
Created August 22, 2018 10:59 — forked from johnhw/umap_sparse.py
1 million prime UMAP layout
### JHW 2018
import numpy as np
import umap
# This code from the excellent module at:
# https://stackoverflow.com/questions/4643647/fast-prime-factorization-module
import random
@pbowyer
pbowyer / list-templates.php
Last active February 23, 2018 10:58
Need to find which pages on a WordPress site are using a template? Upload this, create a page, select this template and 'Preview'. Delete after use.
<?php
/*
* Template Name: [ADMIN] List templates
*/
?>
<h2>Usage</h2>
<p>Append <code>?template=template-name.php</code> to this page URL</p>
<h2>Pages using <code><?php echo $_REQUEST['template'] ?></code></h2>
@pbowyer
pbowyer / README.md
Created January 25, 2018 11:06
BuzzFeed's README Template

name of the service

An explanation of what the service is doing and why. Any high level business logic should be mentioned here to give the reader an understanding of why the service exists in the first place.

List important endpoints/URLs and explain what they are responsible for.

Point of contact and Slack channel

@pbowyer
pbowyer / Connection.php
Created January 19, 2017 11:44
Doctrine DBAL extension for MySQL specific functionality
<?php
namespace TheCourseManager\AppBundle\Doctrine\DBAL;
/**
* A wrapper around a Doctrine\DBAL\Connection that adds MySQL specific features
*
*/
class Connection extends \Doctrine\DBAL\Connection
{
/**