Skip to content

Instantly share code, notes, and snippets.

View hgraca's full-sized avatar

Herberto Graça hgraca

View GitHub Profile
@hgraca
hgraca / HOWTO_merge_repositories.md
Last active April 12, 2023 16:49
HOWTO merge repositories

HOWTO merge repositories

In the exporting repo (ex. legacy API into new monolith, the exporting repo is 'legacy API')

git checkout master
git pull
git checkout -b export
git mv public_html lib/legacy/api
git mv .gitignore lib/legacy/api
@hgraca
hgraca / migrate.sh
Last active September 10, 2023 08:30
migrate MySQL db
#!/usr/bin/env bash
#
# This script migrates a DB from one server to another
# It should be run from the source server, the
# destination server or an intermediate server,
# and it assumes ssh connections are configured so that there
# is no need to insert credentials.
#
# You need to call the script as
@hgraca
hgraca / Makefile
Created January 22, 2021 16:07
Makefile example
# 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
Last active March 11, 2021 15:28
bash-examples
#!/usr/bin/env bash
SCRIPT_PATH="$(
cd "$(dirname "$0")" || exit >/dev/null 2>&1
pwd -P
)"#!/usr/bin/env bash
#################################
# Named arguments for base scripts
#################################
@hgraca
hgraca / run.php
Created July 21, 2020 12:50
A very simple template rendering mechanism.
<?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.");
}
<?php
final class CreatePostalCodeCommand
{
private string $postalCode;
private string $locality;
private float $latitude;
@hgraca
hgraca / Point.php
Last active July 6, 2020 13:55
A Point Value Object
<?php
final class Point
{
private int $x;
private int $y;
public function __construct(int $x, int $y)
{
@hgraca
hgraca / BlogAddAction.php
Created August 22, 2018 15:27
ADR - Action-Domain-Responder
<?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 August 22, 2018 13:29
RMR - Resource-Method-Representation pattern
<?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 September 5, 2017 15:19
Extract repo folder into a new repo
#!/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: