Skip to content

Instantly share code, notes, and snippets.

View augustohp's full-sized avatar

Augusto Pascutti augustohp

View GitHub Profile
@augustohp
augustohp / Doctrine.ini
Created February 1, 2012 18:15
Doctrine.ini configuration to use with Respect\Config
; Configurations
db_host = 'localhost'
db_user = 'zend'
db_passwd = ''
db_name = 'test'
db_driver = 'mysql'
;db_port = 3306
;db_charset = 'utf8'
dsn = '[db_driver]:host=[db_host];dbname=[db_name]'
dsn = 'sqlite::memory:'
@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 / Twig.ini
Created February 14, 2012 01:08
Respect\Config example: Twig configuration and instantiation
view_path = '/app/views'
[options]
debug = false
charset = 'UTF-8'
base_template_class = 'Twig_Template'
strict_variables = false
autoescape = true
cache = false
auto_reload = null
@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 / respect-doc.md
Created March 23, 2012 05:57
Respect Doc (blog) post

Making documentation useful again

Or trying. We, as developers, love code. We read, we study, we do stare at a nice code and get amused by it. In the end of the day what we really care about is code and its functionality. Making our work useful is always the main objective and to do that, we have to - let me take a deep breath here - document it.

We have solutions today that circle around documentation blocks for classes, methods, properties and so on. We even made that documentation do something with @Annotations. So we code and (hopefully) document it using an specific markup: PHPDoc.

Don't get me wrong here. I really think PHPDoc is great, but the documentation generated by it is really usefull? Yeah, I know: IDEs do use them and so on. But how many times have an API doc been useful? Can you just give an API doc to someone and expect a lot of understanding from it?

README to the rescue

@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){