Skip to content

Instantly share code, notes, and snippets.

View pschultz's full-sized avatar

Peter Schultz pschultz

  • classmarkets GmbH
  • Berlin, Germany
View GitHub Profile
@pschultz
pschultz / 00 lib.php
Created June 20, 2012 13:09
o2p REST API draft
<?php
function query($action, $params = array()) {
$context = stream_context_create(array(
'http' => array(
'method' => 'GET',
'header' => "Content-type: application/json\r\n",
'ignore_errors' => true,
)
));
@pschultz
pschultz / bootstrap.phpunit.php
Created November 27, 2012 08:02 — forked from meddulla/config_test.yml
symfony 2 test configuration
<?php
// in /app/bootstrap.phpunit.php:
require_once __DIR__.'/bootstrap.php.cache';
require_once __DIR__.'/AppKernel.php';
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\ConsoleOutput;
@pschultz
pschultz / 00-test.php
Created December 7, 2012 10:58
DomDocument::$preserveWhitespace and ::saveHtml()
$doc = new DomDocument;
$doc->preserveWhitespace = true;
$doc->formatOutput = false;
$doc->loadHtml(
'<ul id="ProjectSubmenu">
<li><a href="/projects/markdown/" title="Markdown Project Page">Main</a></li>
<li>
<a href="/projects/markdown/basics" title="Markdown Basics">Basics</a>
</li>
@pschultz
pschultz / NgramTokenizer.php
Created February 26, 2013 17:46
Ngram tokenizer in php
<?php
class NgramTokenizer
{
public static function tokenize($word, $n)
{
if ($n === 1) {
return str_split($word);
}
@pschultz
pschultz / 00-before.sql
Created April 15, 2013 10:23
Postgresql function after ALTER SCHEMA public RENAME to public_copy;
CREATE OR REPLACE FUNCTION public.get_locations()
RETURNS SETOF public.locations AS
$BODY$
DECLARE
l_record public.locations;
BEGIN
FOR l_record IN
SELECT * FROM public.locations
ORDER BY location_desc
@pschultz
pschultz / sysinfo.ps1
Last active December 19, 2015 12:29
Windows System Info
get-wmiobject Win32_ComputerSystem | format-list *
get-wmiobject Win32_Processor | format-list *
get-wmiobject Win32_PhysicalMemory | format-list *
@pschultz
pschultz / gist:6232714
Created August 14, 2013 16:20
Resource Requirements for Magmatic Engines (Minecraft FTB)
1 Piston
1 Iron Ingot
1 Iron Dust
1 Redstone
3 Wood
4 Stone
1 Coil
1 Silver Ingot
1 Silver Dust
<?php
$options = array();
for ($d = new \DateTime('1970-01-01 09:00:00'); $d < new \DateTime('1970-01-01 19:00:00'); $d->modify('+ 15 minutes')) {
$time = $d->format('H:i');
$options[$time] = $time;
}
@pschultz
pschultz / color_test.sh
Last active December 22, 2015 00:19 — forked from esundahl/color_test.sh
function color_test {
# Daniel Crisman's ANSI color chart script from
# The Bash Prompt HOWTO: 6.1. Colours
# http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html
#
# This function echoes a bunch of color codes to the
# terminal to demonstrate what's available. Each
# line is the color code of one forground color,
# out of 17 (default + 16 escapes), followed by a
# test use of that color on all nine background
@pschultz
pschultz / ForceCharsetPlugin.php
Last active December 9, 2021 16:26
Guzzle plugin to force the response charset. Useful ~if~ when webservers lie to you again.
<?php
use Guzzle\Common\Event;
use Guzzle\Http\Message\Header;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class ForceCharsetPlugin implements EventSubscriberInterface
{
private $forcedCharset = 'utf8';