Skip to content

Instantly share code, notes, and snippets.

View tomjn's full-sized avatar
🎯
Focusing

Tom J Nowell tomjn

🎯
Focusing
View GitHub Profile
@bradphelan
bradphelan / SmallestAngleBetweenTestSuite.cs
Last active March 9, 2016 14:17
Test suite for smallest angle between in C#
[Fact]
public void SmallestSignedAngleBetweenShouldWork ()
{
WMath.SmallestSignedAngleBetween(0.1, 0.2).Should().BeApproximately(0.1, 1e-5);
WMath.SmallestSignedAngleBetween(0.1, 0.2+Math.PI*2).Should().BeApproximately(0.1, 1e-5);
WMath.SmallestSignedAngleBetween(0.1, 0.2-Math.PI*2).Should().BeApproximately(0.1, 1e-5);
WMath.SmallestSignedAngleBetween(0.1+Math.PI*2, 0.2).Should().BeApproximately(0.1, 1e-5);
WMath.SmallestSignedAngleBetween(0.1-Math.PI*2, 0.2).Should().BeApproximately(0.1, 1e-5);
@Rarst
Rarst / doge.php
Last active December 27, 2019 10:34
Doge snippet for WordPress
<?php
add_filter('gettext',fn($t)=>
@$t[4]&&@$GLOBALS['wp_locale']
?["Such $t","Very $t",'Wow'][rand(0,2)]
:$t);
INITIALISATION
==============
load wp-config.php
set up default constants
load wp-content/advanced-cache.php if it exists
load wp-content/db.php if it exists
connect to mysql, select db
load object cache (object-cache.php if it exists, or wp-include/cache.php if not)
load wp-content/sunrise.php if it exists (multisite only)
@westonruter
westonruter / force_balance_tags2.php
Last active August 21, 2019 08:44
Use DOMDocument to do a more robust job at force_balance_tags.
<?php
/**
* Use DOMDocument to do a more robust job at force_balance_tags.
*
* "force_balance_tags() is not a really safe function. It doesn’t use an HTML parser
* but a bunch of potentially expensive regular expressions. You should use it only if
* you control the length of the excerpt too. Otherwise you could run into memory issues
* or some obscure bugs." <http://wordpress.stackexchange.com/a/89169/8521>
*
@lgladdy
lgladdy / hello-taylor.php
Last active August 29, 2016 18:15
A WordPress plugin to replace Hello Dolly lyrics with the infinitely better Taylor Swift.
<?php
/*
Plugin Name: Hello Taylor
Plugin URI: https://gist.github.com/lgladdy/9e1a7303c6a6bf43b9b1
Description: This is not just a plugin, it symbolizes the hope and enthusiasm of an entire generation summed up in <strike>two</strike> words sung most famously by <strike>Louis Armstrong: Hello, Dolly.</strike>Taylor Swift. When activated you will randomly see a lyric from <strike><cite>Hello, Dolly</cite></strike><cite>Taylor Swift</cite> in the upper right of your admin screen on every page.
Author: Liam Gladdy (based on Hello Dolly by Matt Mullenweg)
Version: 1.1
Author URI: http://www.twitter.com/lgladdy & http://ma.tt/
*/
@Rarst
Rarst / WordPress.xml
Last active August 5, 2021 04:14
WordPress Live Templates for PhpStorm
<?xml version="1.0" encoding="UTF-8"?>
<templateSet group="WordPress">
<template name="aa" value="add_action( '$hook$', '$callback$' );&#10;$END$" description="add_action" toReformat="false" toShortenFQNames="true">
<variable name="hook" expression="" defaultValue="" alwaysStopAt="true" />
<variable name="callback" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="HTML_TEXT" value="false" />
<option name="HTML" value="false" />
<option name="XSL_TEXT" value="false" />
<option name="XML" value="false" />
@omarstreak
omarstreak / background.js
Last active October 22, 2023 15:44
Chrome API Extension
//oauth2 auth
chrome.identity.getAuthToken(
{'interactive': true},
function(){
//load Google's javascript client libraries
window.gapi_onload = authorize;
loadScript('https://apis.google.com/js/client.js');
}
);
#!/usr/bin/env sh
##
# Make your Mac feel like home...
# Shoutout to @dtsn for being generally awesome and getting me started.
#
# install it:
# curl -sL https://gist.github.com/BenNunney/7219538/raw/f9b933cca93b67dd63a2d8b1eeebb69e87dc9591/feels-like-home.sh | sh
#
@philipjohn
philipjohn / ascii-for-the-people
Last active August 29, 2015 14:02
ASCII For The People
/* Copyright 2014 Code for the People Ltd
_____________
/ ____ \
_____/ \ \ \
/\ \ \___\ \
/ \ \ \
/ / / _______\
/ / / \ /
/ / / \ /
#!/bin/bash
# Takes a composer controlled repo and pushes a
# composed PACKAGE into a branch called "PACKAGE".
(
# SANITY CHECKS
# Check for uncommitted changes, and refuse to proceed if there are any
if [ -n "$(git ls-files . --exclude-standard --others)" ]; then