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 / troubleshooting.md
Last active December 21, 2021 17:36
Visual Studio Code

Misconfiguration of TypeScript

Once upon a time, after an update, TypeScript service stopped to run, so no Intellisense, no nothing.

The following steps where taken:

  • updated global Node.js (see below);
  • updated global TypeScript afterwards;
  • deleted the .config/Code folder but preserving the User subfolder;
  • started VSC afresh. A new, clean .config/Code folder was created;
@malkab
malkab / shebang.py
Created December 13, 2021 20:56
Python Recipes
#!/usr/bin/env python3
# coding=UTF8
# -*- coding: utf-8 -*-
print("This is the Python3 shebang")
@malkab
malkab / anaconda.md
Created December 3, 2021 08:11
Anaconda

Launch Anaconda in Linux

Default installation folder is ~/anaconda.

To launch it: ./anaconda-navigator &.

Interpolating a Range with a Predefined Color Scale

const pointColorScale = d3
  .scaleSequential(d3.interpolateTurbo)
  .domain(extent);

where interpolateTurbo is the predefined color scale and extent is the variable min / max values.

@malkab
malkab / docker_compose_for_postgresql.yaml
Last active September 15, 2022 10:44
Docker Compose for PostgreSQL
version: '3.5'
networks:
sunnsaas:
external: false
name: network_name
attachable: true
volumes:
phd-data-postgis:
@malkab
malkab / bash_recipes-arrays.sh
Last active November 11, 2021 12:24
BASH Recipes
#!/bin/bash
# Declare the array
folders=('Abacus' 'Bergamonte' 'Clemence' 'Dardanelles')
# Print all array
echo "The whole array: ${folders[@]}"
echo
# Print an element
@malkab
malkab / typescript_observable_example.ts
Last active February 27, 2022 23:38
TypeScript Observable Example
import * as rx from "rxjs";
/**
An example on how to create an Observable in TypeScript.
*/
const observable: rx.Observable<number> =
new rx.Observable<number>((o: rx.Subscriber<number>) => {
@malkab
malkab / postgis_recipes.md
Created September 29, 2021 10:26
PostGIS Recipes

PostGIS Recipes

Some miscellanea PostGIS recipes.

Resetting the GEOMETRY Type and SRID for a Table Column

This is specially useful when creating tables with CREATE TABLE AS SELECT because columns types are not correctly set at database metadata and therefore public.geometry_columns can guess the geometry type and SRID of newly created GEOMETRY columns. After creating the table, run:

@malkab
malkab / postgresql-trigger_examples.md
Created September 12, 2021 12:30
PostgreSQL: trigger examples

PostgreSQL: Trigger Examples

A simple trigger that preprocess the insert or updated rows before inserting them. Modifies input data inside the target table.

First, create a PL/PgSQL function that returns a trigger. In this function, NEW refers to the new data entering the table, while OLD refers to the old data in case there were any:

create or replace function public.fn__urban_limit_preprocessing()
returns trigger as
$$
@malkab
malkab / weighted_average_example.md
Last active January 27, 2022 17:34
PostgreSQL Custom Aggregates

PostgreSQL Custom Aggregates: Weighted Average Example

In this example we are going to create a custom aggregate function for PostgreSQL. Remember that an aggregate function is the kind of functions that works over a group or set of rows to produce a computation based on an accumulative process that iterates over the set of rows, with an alternative final process over the computated accumulative. For example, take this set of data:

val  wei grp
2 4 a
4 3 a
5 10 b
8 15 b