Skip to content

Instantly share code, notes, and snippets.

View pdscopes's full-sized avatar

Pete Scopes pdscopes

View GitHub Profile
@pdscopes
pdscopes / calcRangePrecision.js
Last active August 11, 2016 11:35
Javascript calculate the toFixed precision for a given range
/**
* Calculates the toFixed precision required for nicely displaying
* step intervals between the values given.
*
* @param int min Minimum value in set
* @param int max Maximum value in set
*
* @return int Number.toFixed precision
*/
function calcRangePrecision(min, max) {
@pdscopes
pdscopes / homebrew.mxcl.rabbitmq.plist
Created August 11, 2016 11:17
Homebrew Rabbitmq plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>homebrew.mxcl.rabbitmq</string>
<key>Program</key>
<string>/usr/local/opt/rabbitmq/sbin/rabbitmq-server</string>
<key>RunAtLoad</key>
@pdscopes
pdscopes / phpunit.xml
Last active March 1, 2017 15:05
PHPUnit
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
@pdscopes
pdscopes / string_replace_nth.js
Created September 13, 2018 10:56
String.prototype.replace_nth
String.prototype.replace_nth = function (searchValue, replaceValue, n) {
let i = 0;
return this.replace(searchValue, function (match) { return (++i === n) ? replaceValue : match; });
};
@pdscopes
pdscopes / expand_dict.py
Last active June 19, 2019 15:40
Function to expand a, partially, flattened dictionary out to a nested dictionary
def expand_dict(dct, delimiter: str = '.') -> dict:
"""
Expand a (partially) flattened dot-notation dictionary.
:param dct: Dictionary/list to be expanded
:param delimiter: String that delimits flattened keys
:return: Expanded dictionary/list
"""
if isinstance(dct, dict):
stale_keys = []