Skip to content

Instantly share code, notes, and snippets.

View malkab's full-sized avatar

Juan Pedro Pérez Alcántara malkab

  • Sunntics Ltd.
  • Seville, Andalusia (Spain)
View GitHub Profile
@malkab
malkab / postgresql-set_up_database_for_production.sql
Created January 4, 2021 12:08
PostgreSQL - Set Up Database for Production
/**
Configure a new database for production, cutting
default permissions from public to the postgres
default database.
*/
\c postgres
-- Drop default privileges
revoke all privileges on database postgres
@malkab
malkab / python.md
Last active May 30, 2021 18:04
Python

Python Virtualenv

The interesting thing about virtualenv is that it allows a flexible NPM-like, in-project package management for Docker. Once the code is ready for production images, install them globally within the production image. Virtualenv is installed by default in our malkab/python Docker image.

Steps:

  • creating the virtualenv:
virtualenv libpyexample
@malkab
malkab / postgresql-cheatsheet_reminders.md
Last active January 11, 2021 10:30
PostgreSQL - Cheatsheet & Reminders

PostgreSQL Cheatsheet & Reminders

Some hints and important stuff about PostgreSQL.

Reordering columns in existing tables with data: never do that, pointers to data seems to be lost. Redo the table if needed with create select and such.

Avoiding divisions by zero: the nullif function is an useful way to avoid them:

 round(((sum(e001518)::float) / (nullif(sum(e166418), 0))::float)::numeric, 2)
@malkab
malkab / general_software_design_notes.md
Created January 12, 2021 09:19
General Software Design Notes

Some Miscellaneous Notes about Software Design

Dependencies in Objects

In the past, we tend to overstuff objects with fixed dependencies. Object A uses object B for a lot of things. Is the relation is 1:1, it may be ok to fix the instance of B as a member in A, but if not, if A can use in a given method ANY instance of B, then provide the B object directly to the method. This way the code is free to check for loaded dependencies into A before executing methods, it's up to the API user to ensure they are providing the right object to the method. This is specially useful when dealing with dependencies that comes from a DB, since they are async procedures and the code goes too complicated. Leave this complication to the client code.

@malkab
malkab / imagemagick_recipes.sh
Created February 6, 2021 18:25
ImageMagick Recipes
# -----
#
# Some recipes for ImageMagick
#
# -----
# Cropping one pixel from the border, in place, batch version
mogrify -crop +1+1 -crop -1-1 ../src/images/*.png
@malkab
malkab / postgresql-copy_from_copy_to.md
Last active October 12, 2022 19:06
PostgreSQL - copy from / copy to

Copy To and Copy From

Copy is a command and a psql metacommand to import data into a PostgreSQL:

-- Tables
\copy test_data.test from sigwx.csv with delimiter '|' csv delimiter E'\t' header quote '"' encoding 'utf-8' null '-'

\copy test_data.test to sigwx.csv with delimiter '|' csv header quote '"' encoding 'utf-8' null '-'
@malkab
malkab / gpg_pgp_gnupg2.md
Last active February 7, 2023 08:58
GPG, PGP, and GNUPG2 (already in Logseq)

GPG, PGP, and GNUPG2

Encryption and how to read and write it with GPG.

Installation of Keys

In most cases is just a matter of copying the ~/.gnupg folder. Check available keys with commands explained below.

Owner of folder .gnupg and its contents must be the user. Folder permissions must be 700, and permissions for file gpg.conf must be 600.

@malkab
malkab / compose-basic.yaml
Last active September 15, 2022 10:44
Docker Recipes
version: '3.5'
networks:
carto_bcn:
external: false
name: carto_bcn
attachable: true
services:
postgis:
@malkab
malkab / git_working_with_branches.md
Last active February 17, 2021 17:20
Git - Working with branches

Comparing Branches

First, the term working tree refers to the current checked out branch, the working directory in it's present state.

It is recommended that comparison are made on commited, clean states, and not on uncommited changes. To compare with the current uncommited state of the working tree move the changes to staged. If not, new files won't show up at the SEARCH & COMPARE dialog, but this is tricky.

Use the VSC Git extension. To evaluate if a stalled branch is worth to be maintained, check out the develop, master, or main branch. If not very sure of the result, create a merge test branch.

Right click on the stalled branch and select Compare with Working Tree. The SEARCH & COMPARE section will read Compating XXX to Working Tree, being XXX the right clicked branch. The interpretation of the output is based on the changes to be done to XXX to reach the state of WT. Therefore:

@malkab
malkab / psql_cheatsheet.md
Last active November 24, 2021 21:04
psql Cheatsheet

psql Cheatsheet

Cheatsheet for psql, the command line client for PostgreSQL.

Launch

Do: