Skip to content

Instantly share code, notes, and snippets.

View augustohp's full-sized avatar

Augusto Pascutti augustohp

View GitHub Profile
@augustohp
augustohp / SplClassLoader.php
Created October 16, 2010 07:22 — forked from jwage/SplClassLoader.php
Little mod for not breaking class_exists() usage with non-existing classes, preventing a Fatal Error
<?php
/**
* SplClassLoader implementation that implements the technical interoperability
* standards for PHP 5.3 namespaces and class names.
*
* http://groups.google.com/group/php-standards/web/final-proposal
*
* // Example which loads classes for the Doctrine Common package in the
* // Doctrine\Common namespace.
@augustohp
augustohp / gist:1402858
Created November 29, 2011 01:03 — forked from wesleyvicthor/gist:1392133
twig array
{% if cases_list.ProcessInstance is defined %}
{% for case in cases_list.ProcessInstance %}
{% for activity in case.activities.children() %}
<tr>
{% for variable in case.clientVariables.children() %}
{{ set value = variable.xpath('string[2]') }}
<td>{{ array_pop(value) }}</td>
{% endfor %}
<td><a href="{{ cloud_link_address }}{{ activity.uuid.value }}" target="_blank">{{ activity.name }}</a></td>
<td>#</td>
@augustohp
augustohp / Loader.php
Created January 4, 2012 17:57 — forked from caferrari/Loader.php
VorticePHP2 Loader
<?php
/**
* Simple loader class
*
* Usage: new Vortice\Common\Loader('Zend', './Zend');
* @author Carlos André Ferrari <carlos@ferrari.eti.br>
*/
namespace Vortice\Common;
@augustohp
augustohp / HtmlHandler.php
Created February 12, 2012 17:21 — forked from thiagophx/HtmlHandler.php
ViewHandler
<?php
namespace MyApp;
class HtmlHandler implements ViewHandler
{
public function __invoke(Response $response)
{
foreach ($response->getHeaders() as $header)
header($header);
@augustohp
augustohp / test.md
Created March 21, 2012 16:48 — forked from alganet/test.md
Sample for Respect\Doc

Example 1:

$math = new Math;
$balance = 12.30;
$deposit = 1.70;
$total = $math->sum($balance, $deposit);
if ($total === 14)
    echo 'Ok';
else

echo 'Fail';

@augustohp
augustohp / mocks.php
Created March 27, 2012 17:50 — forked from alganet/mocks.php
Next-gen mocks and stubs for PHP 5.4
<?php
use FooBar\Test\Mock;
// In the sample below, $mock expects the method "sayHelloTo" to be called one time
// with the parameter $name equals "Alexandre" and return "Hello Alexandre"
$mock = (new Mock('NamespaceVendor\\ClassName'))([
'sayHelloTo' => function($name="Alexandre") {
return "Hello Alexandre";
@augustohp
augustohp / bf2c.py
Created March 30, 2012 05:11 — forked from jdp/bf2c.py
Naive brainfuck-to-C transpiler
#!/usr/bin/env python3
import argparse
import sys
def tokenize(source):
return list(source)
def parse(tokens):
ast = []
stack = [ast]
@augustohp
augustohp / yourmom.js
Created March 30, 2012 21:10 — forked from evert/yourmom.js
Greasemonkey script to change every utm_source link attribute value to 'Your mom'
// ==UserScript==
// @name Referral: your mom
// @namespace yourmom
// @description This script changes every utm_source variable in links to 'Your mom'.
// @include *
// ==/UserScript==
var links = document.getElementsByTagName('a');
for(var i=0; i<links.length; i++) {
links[i].href = links[i].href.replace(/([&|?])utm_source=(.*)([&|?|^])/,"$1utm_source=Your+mom$3");
@augustohp
augustohp / index.php
Created March 30, 2012 22:18 — forked from alganet/index.php
Seamless Respect Framework
<?php
/**
* Example of usage of the "Respect Framework", that is actually
* just using one or more Respect components together.
*
* Using components in version 0.4.*
*/
use Respect\Validation\Validator as v;
use Respect\Rest\Router;
@augustohp
augustohp / php_singleton_test.php
Created March 31, 2012 05:37
A new way to make singleton in PHP?
<?php
/**
* @author: Garith
*/
class Singleton{
protected static $instance = null;
public static function load(){
if(self::$instance === null){