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 / 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.
@mrsarm
mrsarm / pg_stat_activity.sql
Created January 29, 2020 20:26
pg_stat_activity.sql: check PostgreSQL active connections (and idle)
-- Find all active connections (and idle)
SELECT
pid
,state
,datname
,usename
,application_name
,client_hostname
,client_port
,backend_start
@mrsarm
mrsarm / find-samples.sh
Created August 21, 2019 17:08
find-samples.sh: examples of how to use the `find` command, and combine it with others commands
# Find in the current folder (recursively) all the files with .xml extension.
find . -name '*.xml'
# Find all the __pycache__ files (or folders) and execute
# for each result the command `rm -r` with the filename as a first argument
find . -name "__pycache__" -print0 | xargs -0 rm -r
# Find into the /tmp folder files that the path matchs a regex expression
find /tmp -regextype posix-egrep -regex ".*\.(le|c)ss$"
@mrsarm
mrsarm / time.py
Last active October 5, 2022 15:13
Python date and time handling examples
# Get valid patterns from http://strftimer.com/
>>> from datetime import datetime, date
>>> datetime.strptime("January 23, 2019", "%B %d, %Y")
datetime.datetime(2019, 1, 23, 0, 0)
>>> datetime.strptime("January 23, 2018", "%B %d, %Y").strftime("%Y-%m-%d")
'2018-01-23'
>>> datetime.strptime("2021-01-01T18:33:00Z", '%Y-%m-%dT%H:%M:%SZ') # The ISO format supported by Python does not parse dates ended with 'Z'
@mrsarm
mrsarm / video2gif.sh
Created March 22, 2019 17:13
video2gif.sh: convert any input video file (avi, mp4...) to a gif file with a reasonable file size
#!/usr/bin/env sh
#
# video2gif.sh
#
# See https://askubuntu.com/questions/648603/how-to-create-an-animated-gif-from-mp4-video-via-command-line
#
# Useful Params:
#
# -r Num of frames x sec
# -vf scale=512:-1 Scale up to 512, remove to preserve original resolution
@mrsarm
mrsarm / rmduplicates.py
Last active February 25, 2019 14:10
rmduplicates.py: filter repeated JSON objects from a given JSON line file
#!/usr/bin/python3
"""
Filter repeated JSON objects from a given JSON line file.
""" # noqa
import argparse
import json
import sys
parser = argparse.ArgumentParser(
@mrsarm
mrsarm / msdos2utf8.py
Last active August 22, 2019 19:54
Use: ./msdos2utf8.py OLD_DOS_FILE NEW_ENCODED_FILE
#!/usr/bin/python3
#
# Usage: ./msdos2utf8.py OLD_DOS_FILE NEW_ENCODED_FILE
#
# Creates a new file UTF-8 encoded, taking the input file as a file with old ASCII encoded used in MS-DOS systems.
#
# Try to replace 'cp437' with 'iso8859' if the new file isn't encoded properly
import sys