Skip to content

Instantly share code, notes, and snippets.

@TheDistantSea
TheDistantSea / _readme.md
Created July 16, 2018 09:11 — forked from jrfnl/_readme.md
PHPUnit xslt

###PHPUnit logfile XLST template

This fileset provides an easy way to view the PHPUnit XML (JUnit) logfiles in a human readable manner using a web browser.

Use this either in combination with the accompanying html file or add the following tag straight after the xml opening tag of the logfile: <?xml-stylesheet type="text/xsl" href="phpunit.xslt"?>

The thresholds used for the colour-coding and whether or not to show detail for successfull tests can be changed by adjusting the variables at the top of the xslt file.

@TheDistantSea
TheDistantSea / access_property.php
Created December 14, 2015 16:14 — forked from lastguest/access_property.php
PHP - Read/Write public/protected/private object property
<?php
// Access a property with no restrictions
function stole($object,$property){
$dict = (array)$object;
$class = get_class($object);
return isset($dict[$property])?
$dict[$property]:(isset($dict["\0*\0$property"])?
$dict["\0*\0$property"]:(isset($dict["\0$class\0$property"])?
$dict["\0$class\0$property"]:null));
@TheDistantSea
TheDistantSea / version_compare.js
Created December 18, 2013 12:19
Function to compare two version strings (e.g. "1.6.1" is smaller than "1.7"). Developed in order to answer http://stackoverflow.com/a/6832721/50079.
/**
* Compares two software version numbers (e.g. "1.7.1" or "1.2b").
*
* This function was born in http://stackoverflow.com/a/6832721.
*
* @param {string} v1 The first version to be compared.
* @param {string} v2 The second version to be compared.
* @param {object} [options] Optional flags that affect comparison behavior:
* <ul>
* <li>
@TheDistantSea
TheDistantSea / go_setup.cmd
Created August 19, 2013 23:07
Batch file that modifies the current user's environment to set up Go in Windows. The idea is to automate the setup of a portable distribution of Go which can be copied to another system or moved around. Usage: Place file at the same level as the Go root and run. Confirmation is asked before any changes are made.
@echo off
setlocal enabledelayedexpansion
if errorlevel 1 goto :nodelayedexpansion
rem *** Find Go installations
set _go_binary=go.exe
set _go_i=0
for /f "delims=" %%i in ('2^>nul dir %_go_binary% /s/b') do (
set /a _go_i=_go_i+1
@TheDistantSea
TheDistantSea / ZipIterator.php
Last active December 20, 2015 02:09
ZipIterator: iterates over multiple traversables in parallel. Requirements: PHP 5.4
class ZipIterator implements \Iterator
{
const ZIP_ALL = '{6087F687-D674-4549-AFBF-8D4DC07FE06F}';
private $_iterators;
private $_zipAll = false;
public function __construct()
{
@TheDistantSea
TheDistantSea / str_truncate.php
Created April 26, 2012 08:46
Truncate a string up to a certain length, preserving whole words
<?php
function str_truncate($str, $limit, $ellipsis = '...') {
if (strlen($str) <= $limit) {
return $str;
}
$limit -= strlen($ellipsis);
$pos = strrpos($str, ' ', $limit - strlen($str));
if ($pos === false) {
@TheDistantSea
TheDistantSea / strrcspn.php
Created April 26, 2012 08:41
Implementation of strrcspn
<?php
function strrcspn($str1, $str2, $start = -1) {
$len = strlen($str1);
$start = ($start + $len) % $len;
for ($i = $start; $i >= 0; --$i) {
if (strpos($str2, $str1[$i]) !== false) {
return $start - $i;
}
}