Skip to content

Instantly share code, notes, and snippets.

View alganet's full-sized avatar

Alexandre Gomes Gaigalas alganet

  • São Paulo, SP, Brazil
View GitHub Profile
@alganet
alganet / template.html
Created April 14, 2011 02:45
Requirements for a next-gen HTML templating engine.
<!doctype html>
<html>
<head>
<title>Hi</title>
<script id="helloworld" type="text/html">
Hello <strong>${user}</strong>
</script>
<script id="secretTemplate" type="text/html" class="php-only">
Sensitive Info!
</script>
@alganet
alganet / chain.php
Created April 20, 2011 14:24
Simple chain sample for a friend
<?php
class Chain
{
public static function foo() {
echo "foo\n";
return new Chain; //or return new static;
}
public function bar()
{
@alganet
alganet / autoloader.php
Created May 10, 2011 14:18
Lightweight PSR-0 compliant autoloader
<?php
spl_autoload_register(function ($className) {
$fileParts = explode('\\', ltrim($className, '\\'));
if (false !== strpos(end($fileParts), '_'))
array_splice($fileParts, -1, 1, explode('_', current($fileParts)));
require implode(DIRECTORY_SEPARATOR, $fileParts) . '.php';
});
@alganet
alganet / developerquiz.php
Created August 8, 2011 20:28
Full script for the Google Developer Day Quiz (http://developerquiz.appspot.com) in 39 lines
<?php //Run as command line. Input file as first argument.
const G_FOO = 'aeiou'; //Googlon special letters
const G_INV = 'z'; //Preposition invalidator
const G_PREP = 3; //Preposition size
const G_VERB = 8; //Verb size
const G_ORDER = 'qnbczxjtklmvhrwfsdgp'; //Letter ordering
const G_NUM_MOD = 4; //Pretty number divisor
const G_NUM_MAX = 526593; //Pretty number minimum
$textB = explode(' ', file_get_contents($argv[1]));
@alganet
alganet / developerquiz.php
Created August 8, 2011 20:41
Full script for the Google Developer Day Quiz (with tests)
<?php
const FOO_LETTERS = 'aeiou'; //Letras especiais do Googlon
const PREP_INV = 'z'; //Letra que invalida preposições
const PREP_SIZE = 3; //Tamanho das preposições
const VERB_SIZE = 8; //Tamanho do verbo
const LETTER_ORDERING = 'qnbczxjtklmvhrwfsdgp'; //Ordem das letras
const GOOGLON_NUMBER_MOD = 4; //Divisor do número bonito
const GOOGLON_NUMBER_MAX = 526593; //Menor número bonito possível
@alganet
alganet / h.php
Created August 10, 2011 22:43
HTML generator prototype
<?php
print
h::html(
h::head(
h::title('Hi!')
),
h::body(
h::h1('Hello')->id('oi'),
h::ul(
@alganet
alganet / respect.php
Created August 12, 2011 20:31
Respect\Framework concepts
<?php
use Respect\Framework\RestfulRelationalApplication as Application;
$app = new Application;
$app->articles->article();
$app->articles->article()->title;
$app->articles->article()->text;
$app->articles->article()->comments;
@alganet
alganet / gist:1190360
Created September 3, 2011 01:29
Olá, contribuidor!

Olá, contribuidor!

Antes de qualquer coisa, obrigado pelo interesse no Respect! Esse é um pequeno guia de como começar a contribuir com nossos projetos.

Se você quiser contribuir, recomendo que entre em contato comigo em alexandre@gaigalas.net. Estarei disponível por email pra ajudar e responder quaisquer dúvidas. Também será legal pra saber se alguém já está trabalhando em cima de algo que você deseja contribuir.

Sempre que tiver uma idéia, abra uma Issue no projeto no qual deseja contribuir. Coloque sua idéia lá. Assim mais pessoas poderão contribuir e colaborar contigo se necessário.

O objetivo do Respect é criar um conjunto de ferramentas simples e pequenas que realizam tarefas específicas. Precisamos de vários tipos de ajuda no projeto:

@alganet
alganet / shitty_validator.php
Created October 6, 2011 03:03
Nasty code sample.
<?php
//CAUTION: THIS IS SHIT. DO NOT USE THE CODE BELOW
if ($userBirthday !== date('Y-m-d', $birthdayTime = strtotime($userBirthday))
|| strtotime('now - 18 years') < $birthdayTime) {
print "I'm invalid :(";
}
<?php
/*
* This file belongs to PHP-MG.
* 2º PHP TALKS - Dojo
*
*/
use Respect\Relational\Mapper;
use Respect\Relational\Finder;