Skip to content

Instantly share code, notes, and snippets.

View hjpbarcelos's full-sized avatar

Henrique J. P. Barcelos hjpbarcelos

View GitHub Profile
@hjpbarcelos
hjpbarcelos / artigo.md
Created November 12, 2012 22:31
2012-11-10 - Artigo Imasters - TDG & RDG

Padrões TableDataGateway e TableRowGateWay - Teoria e Prática

Introdução

Olá, pessoal!

Bom, este é o meu primeiro artigo aqui no iMasters, espero que gostem e que seja lhes seja útil.

Os puristas dos Design Patterns podem não gostar muito do conteúdo deste artigo, pois ele foge um pouco da implementação padrão conhecida, que é definida por Martin Fowler no clássico Patterns of Enterprise Application Architecture.

@hjpbarcelos
hjpbarcelos / sorting.erl
Created March 12, 2013 20:16
Erlang sorting
-module(sorting).
-export([mergesort/1, quicksort/1]).
merge([], L) -> L;
merge(L, []) -> L;
merge(L1=[H1|T1], L2=[H2|T2]) ->
if
H1 =< H2 -> [H1 | merge(T1, L2)];
true -> [H2 | merge(L1,T2)]
@hjpbarcelos
hjpbarcelos / ImageHandler.php
Last active December 15, 2015 21:49
Brincando...
<?php
namespace GdWrapper;
interface Image {
public function getPath();
public function getWidth();
public function getHeight();
public function getType();
}
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <assert.h>
int main(int argc, char *argv[]) {
assert(argc == 3);
int i;
char key = tolower(argv[2][0]);
@hjpbarcelos
hjpbarcelos / fussball.erl
Created April 8, 2013 00:02
Pebolim com erlang.
%%% File: fussball.erl
%%% Description: A simple game of Fussball.
-module(fussball).
%% Interface
-export([start/2, init/2, stop/1, kickoff/1]).
start(MyCountry, OtherCountry) ->
spawn(?MODULE, init, [MyCountry, OtherCountry]),
<?php
namespace GdWrapper\Image\Resource;
use GdWrapper\Image\Resource\Exceptions\InvalidRawResourceException;
use GdWrapper\Image\Resource\Exceptions\InvalidFilePathException;
abstract class AbstractResource {
const IMAGE_QUALITY_MAX = 100;
const IMAGE_QUALITY_HIGH = 90;
const IMAGE_QUALITY_MED = 75;
<?php
/**
* Retorna o parâmetro POST se a chave $key existe em $_POST.
* Caso não esteja, o valor $default será retornado.
* Se nenhum valor $default for informado, retorna null.
*
* @return string|null
*/
function getPost($key, $defalt = null) {
if (isset($_POST[$key]) && !empty(isset($_POST[$key]))) {
#-------------------------------------------------------------
# Greeting, motd etc. ...
#-------------------------------------------------------------
# Color definitions (taken from Color Bash Prompt HowTo).
# Some colors might look different of some terminals.
# For example, I see 'Bold Red' as 'orange' on my screen,
# hence the 'Green' 'BRed' 'Red' sequence I often use in my prompt.
/* gerenciar_canvas.cpp - Generated by Visual Multi-Thread Win32 */
#include "AppObjects.h"
#include "global.h"
#include <stdio.h>
#include <stdlib.h>
#include <tchar.h>
#include <conio.h>
#include <windows.h>
#include "graphics2.h"
@hjpbarcelos
hjpbarcelos / bootstrap.php
Last active December 28, 2015 12:59
DIC Example
<?php
$container['connection.default.dsn'] = 'mysql:dbname=nossoconsorcio;host=localhost;charset=utf8';
$container['connection.default.user'] = 'root';
$container['connection.default.password'] = '@1234&';
$container['storage.default'] = $container->share(function($c) {
return new PdoStorage(
$c['connection.default.dsn'],
$c['connection.default.user'],
$c['connection.default.password']
);