Skip to content

Instantly share code, notes, and snippets.

@OllieJones
OllieJones / DataTableResultSet.cs
Last active Mar 30, 2022
C# code for handling Ajax calls for the DataTables.net client table-rendering plugin.
View DataTableResultSet.cs
/// <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>>();
@OllieJones
OllieJones / wordpress-hooks.php
Last active Mar 16, 2022
Register WordPress Hooks Declaratively
View wordpress-hooks.php
<?php
namespace OllieJones;
use ReflectionClass;
use ReflectionMethod;
/**
* Automatically register WordPress hooks in classes derived from this one.
*
@OllieJones
OllieJones / h264tools.js
Created Feb 4, 2021
h.264: Create an 'avcC' atom from a sequence of NALUs emitted by MediaRecorder
View h264tools.js
'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 Sep 17, 2021
Queue class, super simple, based on Kate Morley's queue code.
View queue.js
'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:
@OllieJones
OllieJones / fullquery
Last active Jul 28, 2021
Fast nearest-location finder for SQL (MySQL, PostgreSQL, SQL Server)
View fullquery
SELECT zip, primary_city,
latitude, longitude, distance
FROM (
SELECT z.zip,
z.primary_city,
z.latitude, z.longitude,
p.radius,
p.distance_unit
* DEGREES(ACOS(LEAST(1.0, COS(RADIANS(p.latpoint))
* COS(RADIANS(z.latitude))
View embl-browser.js
'use strict';
/*globals ebml */
if ( !window.ebml ) window.ebml = {};
ebml.EbmlDecoder = function EbmlDecoder( options ) {
var schema = {
"80": {
@OllieJones
OllieJones / stored_procs
Last active Apr 16, 2020
SQL Reporting By Time Intervals
View stored_procs
DELIMITER $$
DROP FUNCTION IF EXISTS TRUNC_HOUR$$
CREATE
FUNCTION TRUNC_HOUR(datestamp DATETIME)
RETURNS DATETIME DETERMINISTIC NO SQL
COMMENT 'returns current hour'
RETURN DATE_FORMAT(datestamp, '%Y-%m-%d %H:00')$$
DROP FUNCTION IF EXISTS TRUNC_DAY$$
@OllieJones
OllieJones / streamPeek.js
Last active Sep 5, 2018
Read useful information from a MP4 data stream
View streamPeek.js
/*
* 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 Oct 5, 2017
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.
View validateGithubWebhook.js
'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 Oct 3, 2017
Snippets of Javascript.
View nonce.js
'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 );