Skip to content

Instantly share code, notes, and snippets.

Avatar

Herberto Graça hgraca

View GitHub Profile
@hgraca
hgraca / Makefile
Created Jan 22, 2021
Makefile example
View Makefile
# Makefile
#
# Execute targets as often as wanted
.PHONY: config
# Mute all `make` specific output. Comment this out to get some debug information.
.SILENT:
# make commands be run with `bash` instead of the default `sh`
@hgraca
hgraca / index.sh
Created Jan 22, 2021
bash-examples
View index.sh
#!/usr/bin/env bash
SCRIPT_PATH="$(
cd "$(dirname "$0")" || exit >/dev/null 2>&1
pwd -P
)"
. lib.sh
addToStartOfTrapCommand "exit 1"
@hgraca
hgraca / run.php
Created Jul 21, 2020
A very simple template rendering mechanism.
View run.php
<?php
declare(strict_types=1);
function render(string $templateFilePath, array $args = []): string
{
if (!file_exists($templateFilePath)) {
throw new Exception("Template file '$templateFilePath' does not exist.");
}
View CreatePostalCodeCommand.php
<?php
final class CreatePostalCodeCommand
{
private string $postalCode;
private string $locality;
private float $latitude;
@hgraca
hgraca / Point.php
Last active Jul 6, 2020
A Point Value Object
View Point.php
<?php
final class Point
{
private int $x;
private int $y;
public function __construct(int $x, int $y)
{
@hgraca
hgraca / BlogAddAction.php
Created Aug 22, 2018
ADR - Action-Domain-Responder
View BlogAddAction.php
<?php
// Source: https://github.com/pmjones/adr-example/blob/master/src/Web/Blog/Add/BlogAddAction.php
namespace Pmjones\Adr\Web\Blog\Add;
use Pmjones\Adr\Domain\Blog\BlogService;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
class BlogAddAction
{
protected $domain;
@hgraca
hgraca / Resource.php
Last active Aug 22, 2018
RMR - Resource-Method-Representation pattern
View Resource.php
<?php
// taken from http://www.peej.co.uk/articles/rmr-architecture.html
class Resource {
private resourceData = [];
method constructor(request, dataSource) {
// load data from data source
}
method get(request) {
return new Response(200, getRepresentation(request.url, resourceData));
@hgraca
hgraca / git-move-folder-with-history.sh
Created Sep 5, 2017
Extract repo folder into a new repo
View git-move-folder-with-history.sh
#!/usr/bin/env bash
SOURCE_REPO=${1}
DIR_TO_KEEP=${2}
DEST_REPO=${3}
SOURCE_REPO_DIR='source_repo'
DEST_REPO_DIR='dest_repo'
# Based on:
@hgraca
hgraca / M-V-C-VM_-_Controller_example.php
Last active Aug 17, 2017
A simple example of my prefered MVC implementation, with featuring the Model, a View, a Controller, and a ViewModel.
View M-V-C-VM_-_Controller_example.php
<?php
// src/UI/Admin/Some/Controller/Namespace/Detail/SomeEntityDetailController.php
namespace UI\Admin\Some\Controller\Namespace\Detail;
// use ...
final class SomeEntityDetailController
{
/**
@hgraca
hgraca / MVP_snippet.php
Last active Apr 2, 2017
MVP snippet used in my blog post about MVC and variants
View MVP_snippet.php
<?php
class MyPresenter
// ...
public function showUsers()
{
// ...
$data = $this->accountManager->getUserDetails($from = 10, $to = 20);
$this->view->bind('list', $data);
// ...