Skip to content

Instantly share code, notes, and snippets.

@mikey179
mikey179 / example1.xml
Created October 12, 2011 14:26
XML file with XIncludes: with example1.xml the second XInclude is not resolved properly. When changing the order as in example2.xml all XIncludes are resolved properly.
<?xml version="1.0" encoding="utf-8"?>
<parts>
<part name="content">
<h1>XML xinclude example</h1>
<div>
<h2>some some blog entry</h2>
<p>blog entry comment</p>
<p>2011-10-12</p>
@mikey179
mikey179 / release-svn.php
Last active May 19, 2017 08:39
Release script
#!/usr/bin/env php
<?php
echo "Release script\n";
echo " (c) 2013 Frank Kleine\n";
echo " This software is Drinkware. If you happen to meet the author spend him a drink.\n\n";
$pwd = getcwd();
if (false === $pwd) {
error("Can't retrieve current directory - please check file permissions.");
exit(1);
}
@mikey179
mikey179 / convert.php
Created April 7, 2012 15:25
Convert trac wiki export directory to mediawiki format
<?php
# uses trac2mediawiki perl script from http://www.mediawiki.org/wiki/Extension:TracWiki2MediaWiki#Code
$dirit = new DirectoryIterator(getcwd());
foreach ($dirit as $file) {
if (!$file->isFile() || substr($file->getFilename(), 0 , 1) == '.' || $file->getExtension() == '.md') {
continue;
}
@mikey179
mikey179 / with.php
Last active December 11, 2015 00:38
with experiment
<?php
function with($var, \Closure $execute, \Closure $exit = null)
{
try {
$result = $execute($var);
$exit($var);
} catch (\Exception $e) {
if (null == $exit) {
return null;
}
@mikey179
mikey179 / gist:5520225
Last active December 17, 2015 00:19
Which one is better? Both functions do the same, but in slightly different ways. Interestingly, the second one takes around 4 times longer than the first one.
function convertToStringRepresentation1($value)
{
$string = '';
$lines = explode("\n", (string) $value);
foreach ($lines as $lineCounter => $line) {
if (empty($line)) {
continue;
}
if (0 != $lineCounter) {
@mikey179
mikey179 / private_methods.md
Created December 2, 2013 13:28
Some thoughts on private methods

In recent weeks I have come to the conclusion that private methods can be an indicator that a class needs to be refactored. The more lines a private method contains the stronger the indicator. Please be aware that I'm not arguing against private methods or that I consider them harmful, quite the contrary. A private method which encapsulates a condition to be used in another method of the class can be really helpful when it helps to keep the same level of abstraction in this other method.

However, such little methods seldom have more than 1 to 3 lines of code. When your private method starts to have five lines of code or more it becomes an indidator that it does things which shouldn't be done in this class in the first place. It should be done in one of the collaborators the class already has (i.e., one of its dependencies), either in a public method or as part of other operations in one of these collaborators. Alternatively, if it fits into none of those existing collaborators, it could give you a hint that

@mikey179
mikey179 / build_tools_and_application_builds.md
Last active December 30, 2015 03:39
Some thoughts on build tools and application builds

If your application requires a build tool, there's something wrong with your application or the runtime environment of the application. For some that might be quite a controversial statement. What do I mean with it? In order to be able to run an application, the list of steps to fulfill should include just three steps. The first step is to get a checkout of the application from your source code management system (or download it to a local folder, this should require a single command line instruction only as well), and the last step is to start the application.

Now there is a single step left only. And this step should not be running a build tool which does hundreds of things in order to get a running application. Your application should be runnable right after checkout, the only thing that is allowed to miss are any dependencies the application is build on. So the second step should be fetching the dependencies. Nothing more. You don't need a build tool for that. A simple dependency manager is just enough to

<?php
function foo(callable $bar)
{
$bar("nu?\n");
}
foo(function($arg) { echo "Hello world!\n" . $arg;});
function baz($arg)
{
<?php
class MyStreamWrapper {
private $read = false;
public function stream_open($path , $mode , $options , &$opened_path) {
return true;
}
public function stream_stat() {
return [];
@mikey179
mikey179 / selfbase.sh
Created March 28, 2017 13:11
How to retrieve the full path where a script resides
#!/bin/bash
set -o nounset
set -o errexit
selfbase() {
local selfbase=""
if [ -f $0 -a ! -h $0 ]; then
selfbase="$(dirname $0)"
elif [ $(uname) = "Darwin" ]; then
selfbase="$(dirname $(readlink $0))"