Skip to content

Instantly share code, notes, and snippets.

View ThomasWeinert's full-sized avatar
💻
programming

Thomas Weinert ThomasWeinert

💻
programming
View GitHub Profile
@ThomasWeinert
ThomasWeinert / php-version.bat
Created March 13, 2021 17:14
Allow for switch between multiple PHP versions. Expects the PHP version to be in subdirectories `PHP_%VERSION%` (PHP_8.0.4).
@echo off & setlocal enabledelayedexpansion
IF "%~1"=="" GOTO Help
IF "%~1"=="list" GOTO ListVersion
IF "%~1"=="bat" GOTO CreateBatchFiles
:LINK_VERSION
set PHP_VERSION=%1
set PHP_BASE_PATH=%~dp0
set "PHP_BINARY=%~dp0PHP_%PHP_VERSION%\php"
@ThomasWeinert
ThomasWeinert / xml-namespace-read.php
Created November 1, 2019 16:25
How to read XML with namespaces
<?php
// define the namespace URI as a constant
// this is often an URL but it does not have to be one
// in existing XMLs look for the "xmlns/xmlns:*" attributes
const XMLNS_EXAMPLE = 'urn:example-namespace';
// load a really basic XML with the example namespace
$document = new DOMDocument();
$document->loadXML('<f:foo xmlns:f="urn:example-namespace">content</f:foo>');

libary.xml

<project name="buildlibrary" default="hello">
  <target name="hello" hidden="yes">
    <echo message="Hello World!"/>
  </target>
</project>
<?xml version="1.0"?>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="150" height="100">
<defs>
<filter id="b">
<feGaussianBlur stdDeviation="12"/>
</filter>
<linearGradient id='spinner'>
<stop stop-color='rgba(255, 255, 255, 0)'/>
<stop offset='0.2' stop-color='rgba(255, 255, 255, 0)'/>
<stop offset='0.5' stop-color='#fff'/>

Keybase proof

I hereby claim:

  • I am thomasweinert on github.
  • I am thomasweinert (https://keybase.io/thomasweinert) on keybase.
  • I have a public key ASBwbCBQ_ZVJ6zqKiD0Bb3WkLLf4Rz6VObXll9dMYggZXwo

To claim this, I am signing this object:

<?php
// fetch the Firmata board depending on the configuration
$board = include(__DIR__.'/bootstrap.php');
// Carica Chip is used
use Carica\Chip as Chip;
// and http from Carica Io
use Carica\Io\Network\Http as Http;
$board
<?php
$data = array(
array('volume' => 67, 'edition' => 2),
array('volume' => 86, 'edition' => 1),
array('volume' => 85, 'edition' => 6),
array('volume' => 98, 'edition' => 2),
array('volume' => 86, 'edition' => 6),
array('volume' => 67, 'edition' => 7)
);
@ThomasWeinert
ThomasWeinert / async-mysql.php
Created May 30, 2013 13:27
Asynchronous MySQL queries
<?php
include('../../src/Carica/Io/Loader.php');
Carica\Io\Loader::register();
use Carica\Io;
$mysqlOne = new Io\Deferred\MySQL(new mysqli('127.0.0.1'));
$mysqlTwo = new Io\Deferred\MySQL(new mysqli('localhost'));
$time = microtime(TRUE);
@ThomasWeinert
ThomasWeinert / gist:4500763
Last active December 10, 2015 22:18 — forked from tliff/gist:4500652
<?php
$data = '<div>blabla<h1><a href="http://www.example.com/blabla.php?id=12345" class=l>blub</a></h1><h2><a href="http://www.example.com/asfadfafadf.php?id=12345" class=l>blub</a></h2>sdfafgdghaghagh<h1><a href="http://www.example.com/fdgadfhfh.php?id=123dsfasdf45" class=l>blub</a>asdfasdfasdf</h1>';
$doc = new DOMDocument();
$doc->loadHTML($data);
$xpath = new DOMXpath($doc);
$linkTargets = array();
foreach ($xpath->evaluate('//*[@href]/@href', NULL, FALSE) as $attribute) {
$linkTargets[] = $attribute->value;
@ThomasWeinert
ThomasWeinert / groupedmax.sql
Created November 29, 2012 11:37
SQL Maximum Of Group (latest ten, but only one of each group)
SELECT *
FROM mytable
WHERE idfield IN (
SELECT MAX(main.idfield)
FROM mytable AS main
JOIN (
SELECT groupfield, MAX(maxfield) maximum
FROM mytable
GROUP BY groupfield
ORDER BY maximum DESC