Skip to content

Instantly share code, notes, and snippets.

View pretzelhands's full-sized avatar

pretzelhands

View GitHub Profile
@pretzelhands
pretzelhands / _SUMMARY.md
Last active February 26, 2022 21:54
A benchmark of WordPress' official REST API against a raw PHP file.

Performance implications of the official WordPress REST API

On Feb 25, I had to optimize a client's website. A plugin I built for them was struggling with performance issues when liking entries posted by other users. The database query took an average of 1.2ms to perform. Nevertheless, the API response took up to 1.2s(!) in the worst case for 63 bytes of JSON data.

I started investigating and noticed that the official WordPress REST API seemed to be at fault. So I did the first thing I could think of, ripped out the voting script and placed it in a raw PHP script that loads the bare minimum of WordPress I needed to perform my action.

@pretzelhands
pretzelhands / index.php
Created June 2, 2021 13:31
Forbidden Prototype Template
<?php
// Your PHP code here
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
@pretzelhands
pretzelhands / cli.php
Last active January 21, 2021 12:47
Distributable PHAR for any app with composer dependencies
#!/usr/bin/env php
<?php
require __DIR__ . '/vendor/autoload.php';
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\SingleCommandApplication;
@pretzelhands
pretzelhands / composer.json
Created January 21, 2021 09:06
A single file CLI app for Composer-based applications
{
"name": "pretzelhands/single-file-cli",
"description": "A single file CLI application",
"type": "cli-app",
"require": {
"symfony/console": "^5.2"
},
"authors": [
{
"name": "Richard Blechinger",
@pretzelhands
pretzelhands / readingTimeEstimate.php
Last active January 17, 2021 20:54
Estimate the reading time of your markdown-based articles, as detailed by Medium: https://blog.medium.com/read-time-and-you-bc2048ab620c
<?php
const WPM = 250
const READING_TIME_PER_IMAGE = 12; // seconds
const IMAGE_THRESHOLD = 10; // After this threshold each image counts for 3 seconds
function readingTimeEstimate($markdown) {
$markdown = strip_tags($markdown);
$markdown = str_replace("\n", ' ', $markdown);
# Return next 60 days by default
start = datetime.combine(date.today(), time(0, 0))
end = start + timedelta(days=60)
logging.error('//////////////////////////////////////// IT IS WHAT IT IS: {} {}'.format(start, end))
if (start := self.request.query_params.get('start')) and (end := self.request.query_params.get('end')):
start = datetime.combine(datetime.strptime(start, '%Y-%m-%d').date(), time(0, 0))
end = datetime.combine(datetime.strptime(end, '%Y-%m-%d').date(), time(23, 59))
logging.error('||||||||||||||||||||||||||||||||||||||||||||| WHATS GOING ON HERE: {} {}'.format(start, end))
const { notarize } = require('electron-notarize');
async function notarizing(context) {
console.log("• Starting notarization of app");
return await notarize({
appBundleId: 'com.yourorg.whatever',
appPath: "ABSOLUTE_PATH_TO_APP_FILE",
appleId: "YOUR_APPLE_ID_EMAIL",
appleIdPassword: "YOUR_APP_SPECIFIC_APPLE_ID_PASSWORD", // https://support.apple.com/en-us/HT204397
require('dotenv').config();
const { notarize } = require('electron-notarize');
exports.default = async function notarizing(context) {
const { electronPlatformName, appOutDir } = context;
if (electronPlatformName !== 'darwin') {
return;
}
const appName = context.packager.appInfo.productFilename;
@pretzelhands
pretzelhands / readNotebagStore.js
Created June 25, 2020 07:41
Allows you to read a notebag.json file
const Conf = require("conf");
const util = require("util");
const store = new Conf({
name: "notebag",
cwd: "ABSOLUTE_PATH_TO_FOLDER_CONTAINING_NOTEBAG_JSON",
encryptionKey: "YOUR_LICENSE_KEY",
});
console.log(
<!-- Search engines -->
<meta name="image" content="https://howmuchdoesthismeetingco.st/assets/social.png">
<meta itemprop="name" content="How much does this meeting cost?">
<meta itemprop="description" content="Keep an overview of how much a meeting costs and whether it's really worth it.">
<meta itemprop="image" content="https://howmuchdoesthismeetingco.st/assets/social.png">
<!-- Twitter -->
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="How much does this meeting cost?">
<meta name="twitter:description" content="Keep an overview of how much a meeting costs and whether it's really worth it.">