Skip to content

Instantly share code, notes, and snippets.

View mrsarm's full-sized avatar
🏠
Working from home

Mariano Ruiz mrsarm

🏠
Working from home
View GitHub Profile
@mrsarm
mrsarm / restore-backup-pg.sh
Created May 6, 2021 14:52
restore-backup.sh: Restore Postgres backups from Docker volume
#!/usr/bin/env sh
DB="pg-latest_data"
DB_BCK="pg-latest_data-backup-$(date --iso-8601)"
#DB_BCK="pg-latest_data-backup-SNAPSHOT"
echo "Restoring backup of '$DB' database with backup '$DB_BCK' ..."
echo
docker-compose down
docker volume rm $DB
@mrsarm
mrsarm / docker-sh
Last active July 16, 2022 20:52
docker-sh: start a shell session with the container passed
#!/usr/bin/env bash
if [ "$#" -ne 1 -o "$1" == "-h" -o "$1" == "--help" ]; then
echo 'docker-sh: start a shell session with the container passed'
echo
echo "Use: docker-sh CONTAINER_NAME"
echo
echo "NOTE: partial names can be used, but the session"
echo " is started only if one container match"
exit 2
@mrsarm
mrsarm / docker-volume-sh
Last active March 18, 2021 12:32
docker-volume-sh: start a shell session with the volume mounted at /data
#!/usr/bin/env bash
if [ "$#" -ne 1 -o "$1" == "-h" -o "$1" == "--help" ]; then
echo "docker-volume-sh: start a shell session with the volume mounted at /data"
echo
echo "Use: docker-volume-sh VOLUME"
echo
echo "NOTE: if VOLUME does not exist, docker creates it first"
echo
exit 2
@mrsarm
mrsarm / docker-volume-cp
Last active March 18, 2021 12:33
docker-volume-cp script: copy one Docker volume content to a new one
#!/usr/bin/env sh
if [ "$#" -ne 2 ]; then
echo "docker-volume-cp: copy one Docker volume content to another"
echo
echo "Use: docker-volume-cp VOL_SOURCE VOL_DEST"
echo
echo "NOTE: if VOL_DEST does not exist, docker-volume-cp creates it first"
exit 2
fi
@mrsarm
mrsarm / docker-compose-couchdb.yml
Last active March 18, 2021 12:37
docker-compose.yml CouchDB latest: launch a CouchDB server with a volume attached to persist data across sessions
couchdb-latest:
image: couchdb
environment:
- COUCHDB_USER=admin
- COUCHDB_PASSWORD=couch
ports:
- "5984:5984"
volumes:
- couchdb-data-latest:/opt/couchdb/data
- couchdb-conf-latest:/opt/couchdb/etc/local.d
@mrsarm
mrsarm / bash_prompt_custom.sh
Created June 15, 2020 22:09
bash_prompt_custom.sh Bash prompt config (add to your ~/.bashrc)
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
c_reset='\e[0m'
c_git_clean='\e[0;32m'
c_git_dirty='\e[0;31m'
else
c_reset=
c_git_clean=
c_git_dirty=
fi
@mrsarm
mrsarm / docker-compose-pg.yml
Last active January 18, 2022 17:02
docker-compose.yml pg-latest: launch a PostgreSQL server with a volume attached to persist data across sessions
version: "3.9"
services:
pg-latest:
container_name: pg-latest
image: postgres
environment:
- POSTGRES_PASSWORD=postgres
ports:
- "5432:5432"
volumes:
@mrsarm
mrsarm / docker-compose.yml
Last active September 1, 2020 18:49
docker-compose.yml mongo-latest: launch a MongoDB server with a volume attached to persist data across sessions
mongo-latest:
image: mongo
ports:
- "27017:27017"
volumes:
- mongo-data-latest:/data/db
# - `docker-compose up' to start MongoDB attached to the console, or `.. start' detached
# - Connect with `docker-compose run mongo-latest mongo HOSTIP/DBNAME'
# - `docker-compose stop' to stop the service if it was detached,
@mrsarm
mrsarm / find-text
Last active June 19, 2023 16:46
find-text: Bash script to find text or regex in a given path with context display, and omitting temp folders
#!/usr/bin/env bash
#
# find-text: Find text or regex in a given path with context display,
# and omitting temp folders.
#
if [ "$1" == "-h" -o "$1" == "--help" ]
then
cat >&2 <<-'EOF'
find-text: find text or regex in a given path with context display,
@mrsarm
mrsarm / find-css
Last active January 31, 2022 19:11
find-css: Bash script to find one or two words (CSS markups) across CSS, SCSS or LESS files
#!/usr/bin/env bash
#
# find-css: Find one or two words (CSS markups) across CSS, SCSS or LESS files
#
if [ "$#" == 0 -o "$1" == "-h" -o "$1" == "--help" ]
then
cat >&2 <<-'EOF'
find-css: Find one or two words (CSS markups) across CSS, SCSS or LESS files
in the folder passed as first parameter.