Skip to content

Instantly share code, notes, and snippets.

View mastermatt's full-sized avatar

Matt R. Wilson mastermatt

View GitHub Profile
@mastermatt
mastermatt / gist:5436504
Created April 22, 2013 16:30
A class wrapper for the NewRelic PHP API
<?php
/**
* A wrapper for the NewRelic API
*
* Method descriptions are partials. Check the site for more.
* @link https://newrelic.com/docs/php/the-php-api
*
* Started out as a gist from devster {@link https://gist.github.com/devster/1885331}
* I removed its static functionality and added the docblock method annotations
@mastermatt
mastermatt / precisionRound.js
Last active August 29, 2015 13:56
Returns the value of a float rounded using the number of decimal points provided as precision.
/**
* Returns the value of a float rounded using the number of decimal points provided as precision.
*
* Fixes binary rounding issues eg. Math.round(1.005 * 100) / 100 === 1 that present
* problems for accounting and finance-related software.
*
* The normal technique for rounding with decimals is to multiply the number by the log10 of the
* precision, round then divide by the same log eg. for 2 decimal points `round(num * 100) / 100`.
* The binary rounding issue, however, causes this: 1.005 * 100 === 100.49999999999999.
*
@mastermatt
mastermatt / semaphore.py
Last active September 21, 2021 07:31
Consul Semaphore in Python
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import datetime
import json
import logging
import os
import socket
import time
@mastermatt
mastermatt / round_compat.py
Last active December 5, 2019 09:09
Python round compat (bankers round for python2).
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import decimal
import fractions
import math
import six

Keybase proof

I hereby claim:

  • I am mastermatt on github.
  • I am mmattrw (https://keybase.io/mmattrw) on keybase.
  • I have a public key ASDlgdvP--WRDSm8I_ijiM2sNJM9U-Vv7NrbLKhuVE-70Ao

To claim this, I am signing this object:

@mastermatt
mastermatt / git-contained.sh
Created March 31, 2019 03:44
Checks if the current branch is already contained within the provided target ref.
#!/usr/bin/env bash
#
# Checks if the current branch is already contained within the provided target ref.
#
# This solution varies from others with git diff or git log because commits themselves are ignored
# to allow for consistent results if the current branch is rebased/squashed/etc.
# Instead, the change-set as a whole is compared to the target by attempting a merge in a detached
# state and inspecting to see if any resulting merge commit was "empty".
# https://stackoverflow.com/a/55433607/823942
{
"name": "got",
"version": "9.6.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"@ava/babel-plugin-throws-helper": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/@ava/babel-plugin-throws-helper/-/babel-plugin-throws-helper-3.0.0.tgz",
"integrity": "sha512-mN9UolOs4WX09QkheU1ELkVy2WPnwonlO3XMdN8JF8fQqRVgVTR21xDbvEOUsbwz6Zwjq7ji9yzyjuXqDPalxg==",
@mastermatt
mastermatt / day3.js
Last active December 3, 2019 16:31
AoC 2019
const fs = require("fs");
const path = require("path");
const [aWireDirs, bWireDirs] = fs
.readFileSync(path.resolve(__dirname, "./day3_input.txt"))
.toString()
.split("\n");
class Point {
constructor(x, y) {
@mastermatt
mastermatt / jslib-index.d.ts
Created March 8, 2020 04:24
Reproduce Error: TS2749: 'Thing' refers to a value, but is being used as a type here.
// generated by tsc
export const Thing: typeof import("./thing");
@mastermatt
mastermatt / connection_writeable_validator.rb
Last active April 2, 2021 19:47
Sequel ConnectionWriteableValidator extension
# frozen-string-literal: true
# The connection_writeable_validator extension modifies a Database to validate
# that newly created connections are connected to writeable InnoDB servers.
#
# Based on advise given by Jeremy Evans
# https://groups.google.com/g/sequel-talk/c/JFuxfDuoAZ4/m/hTvgj71uBgAJ
#
# During an Aurora fail over, new connections may resolve to the old primary
# instance, which converts to a ready-only node.