Skip to content

Instantly share code, notes, and snippets.

View h4cc's full-sized avatar

Julius Beckmann h4cc

  • ZENNER IoT Solutions
  • Hamburg, Germany
View GitHub Profile
@h4cc
h4cc / guzzle_streamer.php
Created March 1, 2013 11:25
A Guzzle Plugin for streaming files. Maybe someday a real Guzzle Plugin with Composer package...
<?php
/**
* Direct streamer for guzzle.
* Makes a HEAD request to fetch content length first.
* Uses GET request to stream read data directly to the browser.
*
* @author Julius Beckmann
*/
include('guzzle.phar');
@h4cc
h4cc / RedirectResponseListener.php
Created May 29, 2013 12:11
Symfony2 Listener, that will check if a redirect to our page has a route defined.
<?php
/**
* Symfony2 Listener, that will check if a redirect to our page has a route defined.
*
* @author Julius Beckmann
* @date 27.05.13
*/
namespace h4cc\PennerZoneBundle;
@h4cc
h4cc / UrlGenerator.php
Created July 30, 2013 13:15
How to add a _url default to routes, so a external url can be generated by name.
<?php
namespace Acme\DemoBundle\Routing\Generator;
use Symfony\Component\Routing\Generator\UrlGenerator as BaseUrlGenerator;
class UrlGenerator extends BaseUrlGenerator
{
protected function doGenerate($variables, $defaults, $requirements, $tokens, $parameters, $name, $referenceType, $hostTokens)
{
@h4cc
h4cc / services.yml
Last active December 21, 2015 08:39
When using a service alias, a parameter in case of the alias name can NOT be used. Exceptions: 'InvalidArgumentException: Unable to replace alias "%my_alias%" with "bar".' 'InvalidArgumentException: The service definition "%my_alias%" does not exist.'
parameters:
my_alias: foo
services:
foo:
class: Example\Foo
bar:
alias: %my_alias%
#--------------------------------------------
@h4cc
h4cc / architecture.php
Created August 23, 2013 11:56
Check if PHP is running on a 32bit or 64bit architecture.
<?php
// Switch architecture if needed
if(2147483647 == PHP_INT_MAX) {
$architecture = 'i386';
}else{
$architecture = 'amd64';
}
@h4cc
h4cc / gist:6387788
Created August 30, 2013 08:54
Add missing 'eunit.hrl' on Ubuntu/Debian with erlang-dev.
If you get this error:
> 'can't find include lib "eunit/include/eunit.hrl"'
even if you already installed "erlang-eunit.
Try installing 'erlang-dev':
> apt-get install erlang-dev
@h4cc
h4cc / doctrine_query_mock.php
Last active May 5, 2017 23:05
If you get this message from PHPUnit: 'Class "Doctrine\ORM\Query" is declared "final"' Check out the following code:
<?php
// Use the Abstract query, which has nearly all needed Methods as the Query.
$this->queryMock = $this->getMockBuilder('\Doctrine\ORM\AbstractQuery')
->setMethods(array('setParameter', 'getResult'))
->disableOriginalConstructor()
->getMockForAbstractClass();
@h4cc
h4cc / phpunit_mock_iterator_items.php
Created September 18, 2013 10:56
A helper function for creating Iterator Mocks with PHPUnit. Simply add the expected items to the prepared mock.
<?php
/**
* @author Julius Beckmann <github@h4cc.de>
* @license MIT (http://opensource.org/licenses/MIT)
*/
/**
* Adds expected items to a mocked Iterator.
*/
function mockIteratorItems(\Iterator $iterator, array $items, $includeCallsToKey = false)
@h4cc
h4cc / current_function_name.erl
Created October 8, 2013 09:01
Erlang macro for getting the current function name.
-define(current_function_name(), element(2, element(2, process_info(self(), current_function)))).
@h4cc
h4cc / ubuntu_13_10.sh
Last active December 26, 2015 02:49
Ubuntu 13.10 Saucy Salamander - Basic packages i usually install
#--- Ubuntu 13.10 Saucy Salamander
#-
#- Basic packages i usually install
#
# Update and Upgrade
sudo apt-get update
sudo apt-get upgrade
# Graphics