Skip to content

Instantly share code, notes, and snippets.

@OllieJones
OllieJones / wp_options_length_histogram.sql
Created June 23, 2022 15:59
Display a histogram of WordPress option lengths with histogram buckets approximating the log of lengths
-- Display a histogram of WordPress option lengths,
-- with histogram buckets approximating the log of lengths,
WITH lengths AS (
SELECT LENGTH(option_value) l,
autoload,
option_name
FROM wp_options
),
buckets AS (
SELECT autoload, l, option_name,
@OllieJones
OllieJones / wordpress-hooks.php
Last active March 16, 2022 11:56
Register WordPress Hooks Declaratively
<?php
namespace OllieJones;
use ReflectionClass;
use ReflectionMethod;
/**
* Automatically register WordPress hooks in classes derived from this one.
*
@OllieJones
OllieJones / h264tools.js
Created February 4, 2021 16:11
h.264: Create an 'avcC' atom from a sequence of NALUs emitted by MediaRecorder
'use static'
// noinspection JSUnusedLocalSymbols,JSUnusedGlobalSymbols
/**
* Tools for handling H.264 bitstream issues.
*/
/**
* Handle the parsing and creation of "avcC" atoms.
*/
@OllieJones
OllieJones / queue.js
Last active September 17, 2021 15:50
Queue class, super simple, based on Kate Morley's queue code.
'use strict';
/*
Queue.js
A class to represent a queue
Created by Kate Morley - https://code.iamkate.com/ - and released under the terms
of the CC0 1.0 Universal legal code:
'use strict';
/*globals ebml */
if ( !window.ebml ) window.ebml = {};
ebml.EbmlDecoder = function EbmlDecoder( options ) {
var schema = {
"80": {
@OllieJones
OllieJones / streamPeek.js
Last active September 5, 2018 13:38
Read useful information from a MP4 data stream
/*
* this code examines a MP4 data stream.
* it looks at the appropriate atoms to determine width, height, and frame rate.
*
* It is a sleazy approach, the equivalent of grepping for necessary
* boxes rather than using box lengths to parse the file.
*/
function read32( buff, fourcc, offset ) {
let start = 0;
@OllieJones
OllieJones / validateGithubWebhook.js
Created October 5, 2017 12:49
Github webhooks use a shared secret for validation. The webhook itself contains a header X-Hub-Signature containing a hash of the webhook body. This function checks that hash against the body.
'use strict';
const crypto = require( 'crypto' );
function validateGithub( secret, signature, rawBody ) {
if( (!signature) || signature.length === 0 ) return false;
if( (!rawBody) || rawBody.length === 0 ) return false;
try {
const splits = signature.split( '=' );
@OllieJones
OllieJones / nonce.js
Created October 3, 2017 12:28
Snippets of Javascript.
'use strict';
/* node.js nonce: crypto-quality random session key (filename safe base64, rfc4648) */
const btoa = require( 'btoa' );
const crypto = require( 'crypto' );
function nonce( length ) {
const rndLen = 1+(( (length)+(length<<1) +3)>>2);
const randomArray = crypto.randomBytes( rndLen );
@OllieJones
OllieJones / explanation.md
Last active July 20, 2016 16:18
Detecting a disconnected RDP session in a unix / linux / bsd server.

Here is a way to obtain a list of disconnected xrdp sessions. It relies on the fact that the xrdp server is, in normal X session manager usage, the only client that establishes a TCP connection to the Xvnc X Window System display server. (The other client programs -- the ones doing things for the user -- use UNIX-domain sockets for their display connections).

When an xrdp session is active, the associated Xvnc display server has two TCP connections, one in the ESTABLISHED state, and the other in the LISTEN state. That looks something like this using the lsof(1) program.

$ sudo lsof  -b -w -n -c /^Xvnc$/b -a -iTCP:5900-5999 
COMMAND  PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
Xvnc    1625 guest    1u  IPv4 252910      0t0  TCP 127.0.0.1:5910 (LISTEN)
Xvnc    1625 guest    9u  IPv4 261226      0t0  TCP 127.0.0.1:5910->127.0.0.1:35242 (ESTABLISHED)

If the user of the remote session abandons it by closing the RDP connection (or, in the case of an Apache Guacamole RDP session

@OllieJones
OllieJones / DataTableResultSet.cs
Last active March 3, 2023 22:16
C# code for handling Ajax calls for the DataTables.net client table-rendering plugin.
/// <summary>
/// Resultset to be JSON stringified and set back to client.
/// </summary>
[Serializable]
[SuppressMessage("ReSharper", "InconsistentNaming")]
public class DataTableResultSet
{
/// <summary>Array of records. Each element of the array is itself an array of columns</summary>
public List<List<string>> data = new List<List<string>>();