Skip to content

Instantly share code, notes, and snippets.

View eduardofcgo's full-sized avatar
⛷️

Eduardo Gonçalves eduardofcgo

⛷️
View GitHub Profile
@eduardofcgo
eduardofcgo / rollout.sh
Last active April 15, 2024 23:29
Rolling updates, zero downtime with just nginx and docker compose
#!/bin/bash
set -e
docker-compose build
echo Update only secondary on 3333
docker-compose up -d cooked_secondary
echo Wait until secondary is live
curl --silent --include --retry-connrefused --retry 30 --retry-delay 1 --fail http://localhost:3333/health.txt
@eduardofcgo
eduardofcgo / s3client.clj
Created April 9, 2024 03:16
aws s3 sdk v2 for s3 compatibles providers
(defn create-client []
(-> (S3Client/builder)
(.credentialsProvider
(StaticCredentialsProvider/create
(AwsBasicCredentials/create access-key secret-key)))
(.region (Region/of region))
(.endpointOverride (URI/create endpoint))
(.build)))
@eduardofcgo
eduardofcgo / espresso.md
Last active November 6, 2023 19:00
Intuition for espresso recipes

Variables that make up the espresso puck

  • Coffee bean solubility (roast level / altitude grown / type of bean)
  • Coffee dose / Head space
  • Grind size
  • Uniformity (puck preparation)
  • Tamp pressure

What makes an espresso

  • All these variables must yield a puck that in contact with water creates some "integrity" - this integrity creates the resistance to water necessary for extraction under pressure.
  • Integrity always increases with these variables.
@eduardofcgo
eduardofcgo / store.clj
Created January 9, 2023 13:02
Serialize ring session store into a jdbc compatible database, sqlite...
(ns ll.session.store
(:require
[taoensso.nippy :as nippy]
[clojure.java.jdbc :as jdbc]
[ring.middleware.session.store :refer [SessionStore]]))
(def serialize nippy/freeze)
(defn deserialize [session]
@eduardofcgo
eduardofcgo / faturas.py
Last active September 5, 2022 02:23
Mapa de impostos a partir do e-fatura
import requests
import logging
import json
import sqlite3
import math
search_params = {
"dataInicioFilter": "2022-06-01",
"dataFimFilter": "2022-08-31",
@eduardofcgo
eduardofcgo / nif.py
Last active May 26, 2022 02:39
validar nifs portugueses
import re
def _convert_to_int_list(nif_str):
return list(map(int, nif_str))
def _check_len(nif):
return len(nif) == 9
@eduardofcgo
eduardofcgo / cached_iterator.py
Created November 23, 2021 04:48
cached iterator python
from collections.abc import Iterator
class _CachedIterator(Iterator):
def __init__(self, iterator):
self.iterator = iterator
self.cache = []
self.cached = False
def __iter__(self):
@eduardofcgo
eduardofcgo / rtp-download.js
Last active May 9, 2021 11:38
download rtp play
console.log(`youtube-dl -f mp4 https://streaming-ondemand.rtp.pt${player1.fileKey.split(".mp4")[0]}/master.mpd -o "${document.title}.mp4"`)
@eduardofcgo
eduardofcgo / guia.md
Last active April 29, 2021 10:32
Tweets dataset
  1. Analisa o dataset do Twitter em /datasets/twitter.csv. Qual o comando que utilizarias para obter todos os tweets em português?
  2. E caso pretendas obter todos os tweets em japonês, qual seria o comando?
  3. Caso queiras consultar os tweets portugueses várias vezes durante um dia, consideras eficiente o comando que fizeste? Como farias para não ter de percorrer o dataset inteiro sempre que pretendes fazer fazer essa consulta?
  4. Cria um script que irá resolver o problema da pergunta anterior. O script deverá criar os índices de forma a que seja eficiente procurar todos os tweets de uma lingua específica - seja português, japonês, inglês etc. Através dos índices, não será necessário procurar o dataset inteiro sempre que se faz uma consulta. Recomendacao: Deveras criar um índice (ficheiro) para tweets de cada língua. Uma das solucoes seria primeiro criar um ficheiro com uma lista de todas as linguas. Por exemplo:
en
jp
es

Depois e possível percorrer cada linha desse ficheiro usando um while, de for

@eduardofcgo
eduardofcgo / ssh_run_script.py
Last active February 13, 2021 07:56
Run local script on remote machine with SSH in python
import pexpect
async def _run_script_ssh(user, host, password, script_path, port=22, args=None):
skip_host_key_check_args = (
"-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
)
ssh_command = f'ssh {user}@{host} -p {port} {skip_host_key_check_args} "bash -s" -- < {script_path} {args or ""}'
child = pexpect.spawn("/bin/bash", ["-c", ssh_command], encoding="utf-8")