Skip to content

Instantly share code, notes, and snippets.

@jligerofleitas
jligerofleitas / Import_SQL_file_to_PostgreSQL_in_container.sh
Last active January 4, 2026 20:00
Import SQL file to PostgreSQL in container
# Single quotes are relevant to delay expansion to be executed in container shell session
# 1. using docker exec:
cat /path/to/file.sql | docker exec -i <running postgres container name> \
bash -c 'PGPASSWORD=${POSTGRES_PASSWORD} psql -U ${POSTGRES_USER} -d ${POSTGRES_DB}'
# 2. using docker compose exec
cat /path/to/file.sql | docker compose exec -i <service name in docker-compose.yml> \
bash -c 'PGPASSWORD=${POSTGRES_PASSWORD} psql -U ${POSTGRES_USER} -d ${POSTGRES_DB}'
# You can also use `docker compose exec`:
# docker compose exec -i <service name in docker-compose.yml> bash -c '...' < /path/to/file.sql
@jligerofleitas
jligerofleitas / SecureSession.php
Last active September 29, 2015 00:08
Inspired by Enrizo Zimmel' secure sessions, I just added extra code to allow filesystem and DB session storage (via PDO), configured in the constructor. get(), set() and flash() methods added for daily usage.
<?php
/**
* ------------------------------------------------
* Encrypt PHP session data using files
* ------------------------------------------------
* The encryption is built using mcrypt extension
* and the randomness is managed by openssl
* The default encryption algorithm is AES (Rijndael-128)
* and we use CBC+HMAC (Encrypt-then-mac) with SHA-256