Skip to content

Instantly share code, notes, and snippets.

View turicas's full-sized avatar

Álvaro Justen turicas

View GitHub Profile
@turicas
turicas / python-tuple-creation-time.sh
Created April 10, 2025 00:14
Python tuple creation from list comprehesion is faster than from generator expression
#!/bin/bash
python -m timeit 'tuple(n for n in range(100))'
# Result: 100000 loops, best of 5: 2.09 usec per loop
python -m timeit 'tuple([n for n in range(100)])'
# Result: 200000 loops, best of 5: 1.13 usec per loop
@turicas
turicas / README.md
Created March 22, 2025 16:03
Configure SOCKS proxy in Splinter for both Firefox and Chrome (with and without selenium-wire)

Configuring a Socks Proxy in Splinter

I only found documentation regarding HTTP proxies on Splinter, but sometimes I just want to run ssh -D 1234 some-machine and get the SOCKS proxy on port 1234 to work with the Splinter browser. After many tests, I created these examples for Firefox and Chrome and all of them work.

For Web scraping tasks, sometimes having access to all the requests the browser made is a requirement, so I made examples for making this work with selenium-wire also. Since selenium-wire creates a proxy (so it can intercept requests between Selenium and the browser), the proxy configurations must be passed in a different way.

@turicas
turicas / keycloak_local_setup.py
Created March 7, 2025 06:38
Script to create keycloak realm, backend and frontend clients and user accounts
# pip install python-keycloak
import os
from keycloak import KeycloakAdmin
from keycloak.exceptions import KeycloakGetError
server_url = "http://keycloak:8080/auth/"
admin_username = "admin"
admin_password = "admin"
@turicas
turicas / README.md
Last active March 4, 2025 17:33
Transform original postgres Docker image into agensgraph
@turicas
turicas / README.md
Created January 23, 2025 17:06
Python versions in Debian and Ubuntu official Docker images

Python versions in Debian and Ubuntu official Docker images

The table below was made by installing the package python3 in each Docker image and then running python --version (see the python-versions.sh for more details). Release and end of life dates were taken from:

Distribution Version Codename Released at End of Life Python version
Debian GNU/Linux 12 bookworm 2023-06-10 2026-06-10 Python 3.11.2
@turicas
turicas / kdenlive_cuesheet_tkinter.py
Created December 13, 2024 17:44
Python script with Tkinter interface to extract clip/timeline data from Kdenlive project file and create a "cue sheet" (no external dependencies)
#!/usr/bin/env python3
import csv
import os
import tkinter as tk
import xml.etree.ElementTree as ET
from pathlib import Path
from tkinter import filedialog, messagebox
def get_properties(element):
@turicas
turicas / embeddings.py
Created November 25, 2024 19:30
Image embedding using timm and Dinov2
from pathlib import Path
import timm
import torch
from PIL import Image
class FeatureExtractor:
"""Extract embeddings from images using timm's Dinov2 models"""
model_names = (
@turicas
turicas / faces.py
Created November 18, 2024 17:06
Face recognition script using face_recognition Python library
# Requirements:
# sudo apt update && sudo apt install -y cmake
# pip install face-recognition numpy opencv-python Pillow tqdm
import cv2
import face_recognition
import numpy as np
from PIL import Image
from tqdm import tqdm
@turicas
turicas / create-tags
Created April 4, 2024 22:16
Create ctags-like file using tree-sitter and awk
#!/bin/bash
filename="$1"
if [[ -z $filename ]]; then
echo "ERROR - usage: $0 <filename>"
exit 1
fi
transformation_code='
@turicas
turicas / cidade_exterior.csv
Last active February 9, 2024 02:13
Script que cria dados de exemplo de pessoas e empresas para serem usados em demonstrações
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
cidade_exterior
ABLASSERDAN
A CORUNA
ACRA
ADDISON
AGUEDA
AICHI-KEN
ALAMEDA
ALBLASSERDAM
ALCALA DE HENARES