Skip to content

Instantly share code, notes, and snippets.

View vanderlee's full-sized avatar

Martijn van der Lee vanderlee

View GitHub Profile
@vanderlee
vanderlee / retry.php
Created April 4, 2019 11:23
Try a callable a number of times
<?php
/**
* Try a callable a number of times.
* If all attempts fail, handle a catch and/or finally.
* If no catch is provided, just throw the exception from the last failed attempt.
* If an attempt succeeds, return the number of attempts (at least one).
* If the provided number of attempts is zero or less, the code won't attempt to run at all.
*
* This is a quick hack, which can easily be improved and most likely still has issues.
@vanderlee
vanderlee / backtrace.php
Created October 9, 2018 12:56
backtrace(); Safely return current backtrace as array of formatted strings
<?php
/**
* Returns an array of formatted backtrace lines.
* Optional format string may include the following keywords:
* index Zero-based order number of backtrace step.
* file Path and name of file
* line Line number
* class Fully qualified name of class
* type `::` if class method or `->` if object method
@vanderlee
vanderlee / knockout-jquery-ui-widget.js
Last active August 29, 2015 14:13 — forked from medmunds/knockout-jquery-ui-widget.js
Renamed 'jqueryui' to 'jquery', as it also works for pretty much every jquery plug-in, not just jquery-ui ones.
// knockout-jquery-widget.js
// Copyright (c) 2011, Planapple, Inc.
// License: MIT (http://www.opensource.org/licenses/mit-license.php)
//
// Knockout binding for jQuery widgets
//
// Examples:
// <input type="submit" value="OK" data-bind='jquery: "button"' />
//
// Attaches a jQuery UI button widget to this button, with default options.
@vanderlee
vanderlee / jquery.autowidth.js
Last active August 29, 2015 14:13
jQuery.autowidth plugin to automatically resize width of HTML select inputs based on the currently selected option
// Based on http://stackoverflow.com/questions/20091481/auto-resizing-the-select-element-according-to-selected-options-width
// Licensed as CC0 or public domain, whatever you prefer.
;(function($, undefined) {
var pluginName = 'autowidth',
defaults = {
maxWidth: null,
minWidth: null,
padding: 30
};