Skip to content

Instantly share code, notes, and snippets.

@gries
gries / gist:eae95ade571e74fd7187
Created December 19, 2014 20:51
Number systems
<?php
$elementalSystem = new NumberSystem(['earth', 'fire', 'air', 'water']);
$binarySystem = new NumberSystem(['0', '1']);
$number = new Number('fire-fire-earth-air', $elementalSystem, '-');
echo $number->asDecimalString(); // -> 214
$number->convert($binarySystem)->value() // -> 11010110
<?php
public function myPageAction(Request $request)
{
$locale = $request->getLocale();
}
@gries
gries / gries_propel_blob_access
Created October 10, 2011 12:36
Propel-ORM BLOB access
<?php
$object = ObjectQuery::create()->findOneById(1);
// load blob content
$content = stream_get_content($object->getImage());
// content now holds the image data
var_dump($content);
@gries
gries / opensuse_phpunit_install.sh
Created December 13, 2011 10:15
Install phpunit on opensuse 11.4
#!/bin/bash
pear update-channels # updates channel definitions
pear upgrade --alldeps # upgrades all existing packages and pear
pear channel-discover components.ez.no # this is needed for PHPUnit
pear channel-discover pear.symfony-project.com # also needed by PHPUnit
pear channel-discover pear.phpunit.de # This IS phpunit
pear install --alldeps phpunit/PHPUnit # installs PHPUnit and all dependencies
phpunit --version # should display something above: 3.6.x
@gries
gries / doctrine_getter_mock_right.php
Created January 11, 2012 08:06
mocking a doctrine getter the right way
<?php
class fooTest extends PHPUnit_Framework_TestCase
{
public function testBar()
{
$builder = $this->getMockBuilder('SomeDoctrineRecordClass')->disableOriginalConstructor();
$mockObject = $builder->getMock();
$mockObject->expects($this->any())
->method('__call')
@gries
gries / doctrine_getter_mock_wrong.php
Created January 11, 2012 07:59
mocking a doctrine getter the wrong way
<?php
class fooTest extends PHPUnit_Framework_TestCase
{
public function testBar()
{
$builder = $this->getMockBuilder('SomeDoctrineRecordClass')->disableOriginalConstructor();
$mockObject = $builder->getMock();
$mockObject->expects($this->any())
->method('getProperty')
// original
if ($scope.person.surname == '' || $scope.person.firstname == '') {
return true;
}
return false;
// simplifiziert
return !!($scope.person.surname == '' || $scope.person.firstname == '');
@gries
gries / migrate-to-main.sh
Created November 18, 2020 11:00
A simple bash script to move all open PRs from master to main
#!/bin/bash
# get all open PR numbers that have master as base
PRS=`gh pr list --state open --base master | cat | cut -f 1`
for PR_ID in $PRS; do
echo "PR: $PR_ID"
# Migrate pull-request to main branch
@gries
gries / script_in_yo_script.php
Last active July 4, 2023 12:57
Brainfuck Javascript Interpreter parsed by PHP
<?php
/**
* Pijib
* PHP interprets Javascript interprets Brainfuck
*
* This is an awesome script that takes brainfuck-code that
* will be interpreted by Kit's JavaScript Brainfuck Interpeter that will be interpreted by PHP
*
*/