Skip to content

Instantly share code, notes, and snippets.

@funivan
Last active September 11, 2023 07:11
Show Gist options
  • Select an option

  • Save funivan/a8ee2edcf84c978489b273e7cc207e0f to your computer and use it in GitHub Desktop.

Select an option

Save funivan/a8ee2edcf84c978489b273e7cc207e0f to your computer and use it in GitHub Desktop.

SH

Current script directory

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"

Full path to the directory

realpath ../tests

Build/run/stop docker container

ID="$(basename $SCRIPT_DIR)-prod"
trap "docker kill $ID" INT # trap ctrl-c and call ctrl_c()
docker build -t "$ID" "$SCRIPT_DIR" &&
  docker run --name="$ID" --rm -di $ID &&
  docker logs --follow "$ID"

Php

Run tests with coverage in the container

#!/usr/bin/env bash
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
docker run --rm -v "$SCRIPT_DIR":/app \
       -w "/app" \
       -it "mileschou/xdebug:7.4" \
       "./vendor/bin/phpunit"

Git

# update local branch based on 
git clean -f -x && git pull upstream master --rebase && git push --force

# publish your changes
git push --force


# update local branch
git pull --rebase upstream master
git rebase --continue && git push --force

SH color printing

ok () { echo -e "\033[0;32m$@\033[0m"; }
error () { echo -e "\033[0;31m$@\033[0m"; }
warning () { echo -e "\033[0;33m$@\033[0m"; }
info () { echo -e "\033[0m$@\033[0m"; }

# How to use it
ok "[OK] message" :: Green
error "Error message" :: Red
warning "~~" "Warning message" "~~" :: Yelow
info INFO message :: White color

API

Merge multiple swagger files

npx swagger-cli bundle -t yaml  -o notifications.v3.bundle.yaml notifications.v3.yaml && \
npx swagger-cli validate notifications.v3.bundle.yaml

MacOS

Use fingerprint to run sudo sudo vi /etc/pam.d/sudo

# Add pam_tim as first line
auth       sufficient     pam_tid.so
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment