Skip to content

Instantly share code, notes, and snippets.

View yoeunes's full-sized avatar
🇲🇦
Freelancer

Younes ENNAJI yoeunes

🇲🇦
Freelancer
View GitHub Profile
<?php
namespace App\Libraries;
/**
* Class able to convert a flat array with parent ID's to a nested tree
*/
class FlatToTreeConverter
{
/**
# Easier navigation: .., ..., ...., ....., ~ and -
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias .....="cd ../../../.."
alias ~="cd ~" # `cd` is probably faster to type though
alias -- -="cd -"
# Shortcuts
alias dropbox="cd ~/Documents/Dropbox"
@yoeunes
yoeunes / prepare-commit-msg.sh
Created June 1, 2020 11:19
git hook to add Jira or Gitlab issue ID to commit message
#!/bin/bash
#
# Automatically adds Jira key to commit message
#
BRANCH_NAME=$(git symbolic-ref --short HEAD)
if [[ $BRANCH_NAME =~ feat/.* ]] || [[ $BRANCH_NAME =~ fix/.* ]]; then
BRANCH_ISSUE_ID="${BRANCH_NAME##*/}"
@yoeunes
yoeunes / access_private_fields.php
Last active February 20, 2020 14:06
access private fields of a class using closures
<?php
class Article
{
private string $title = 'private title';
private function callingPrivate(string $query)
{
echo $query, PHP_EOL;
}
@yoeunes
yoeunes / decorator_design_pattern.php
Last active February 20, 2020 10:35
Simple example for the Decorator pattern in PHP
<?php
class Transaction
{
public function execute(callable $operation)
{
echo 'Begin Transaction', PHP_EOL;
$operation();
echo 'Commit Transaction', PHP_EOL;
}
@yoeunes
yoeunes / subcheckout
Last active November 24, 2024 02:13
An alternative to "git submodule foreach --recursive git checkout develop"
#!/bin/bash
# add this function to your .bashrc or .zshrc and then run "source ~/.zshrc"
# - subcheckout param1 param2
# by default subcheckout will change to develop in every submodule
# if you pass a first parameter it will checkout to that branch if exist on submodule
# if you pass a second parameter as default branch if the first branch not exists
function subcheckout() {
branch=${1:-develop}