Skip to content

Instantly share code, notes, and snippets.

View clemherreman's full-sized avatar

Clement Herreman clemherreman

  • Exotec
  • Lille, France
View GitHub Profile
@clemherreman
clemherreman / Collection.php
Last active August 29, 2015 14:00
WTF collection
<?php
class Collection
{
/**
* Gets an item from the collection
*
* @param $item
* @return string|null
*/
public function get($item)
@clemherreman
clemherreman / shortcut.js
Created October 9, 2014 14:58
Joseph's productivity x1000 multiplier
// Step 1: include jQuery
var jq = document.createElement('script');
jq.src = "//code.jquery.com/jquery-latest.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
// ... give time for script to load, then type.
jQuery.noConflict();
// Step 2: create a textarea
jQuery('#console').after('<textarea id="filenames"></textarea>');
class MyService {
private $finderFactory;
public function __construct(callable $finderFactory)
{
$this->finderFactory = $finderFactory;
}
public function findStuff()
{
<?php
class FailTest extends \PHPUnit_Framework_TestCase
{
public function testfail()
{
fail();
$this->assertTrue(true);
}
}
@clemherreman
clemherreman / main.go
Created January 28, 2015 12:30
Go casting byte to string
package main
import "fmt"
type IPAddr [4]byte
func (i IPAddr) String() string {
return string(i[0]) // Returns an empty string
return fmt.Sprintf("%v.%v.%v.%v", i[0], i[1], i[2], i[3]) // Only way to cast byte to string is through Sprintf
}
@clemherreman
clemherreman / php -v
Created May 20, 2015 13:29
Blackfire Probe troubleshoot
[vagrant@luceo-ocb vagrant]$ php -v
PHP 5.4.41 (cli) (built: May 14 2015 23:37:34)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies
@clemherreman
clemherreman / Company.php
Created August 26, 2010 09:16
Symfony getter overloading
<?php
/**
* Company
*
* This class has been auto-generated by the Doctrine ORM Framework
*
* @package winston
* @subpackage model
* @author Clement Herreman <clement@activcompany.fr>
@clemherreman
clemherreman / dateproblem.php
Created April 4, 2011 08:02
Date WTF in PHP
<?php
$badDate = '2010-13-03';
$date = DateTime::createFromFormat('Y-m-d', $badDate);
var_dump($date);
/*
object(DateTime)#284 (3) {
["date"]=>
string(19) "2011-01-03 10:01:20"
@clemherreman
clemherreman / 1_Person.class.php
Created April 22, 2011 09:50
PHP WTF of the day
<?php
class Person
{
private $phone;
private $name;
public function __construct($name, $phone)
{
var_dump($name);
var_dump($phone);
@clemherreman
clemherreman / DocumentIdentificationForm.php
Created May 5, 2011 12:04
How to add business logic on form save
<?php
class DocumentIdentificationForm extends DocumentForm
{
protected function doUpdateObject($values)
{
parent::doUpdateObject($values);
if ($values['author_id'])
$this->getObject()->setStatusId(Doctrine_Core::getTable('Status')->getIdentifiedStatus());
else