Skip to content

Instantly share code, notes, and snippets.

@ygalvao
ygalvao / Poetry_entrypoint_for_apps.md
Created March 12, 2024 15:59
Proper entrypoint for Python apps using Poetry

Instead of renaming app.py (or whatever.py) to main.py, use proper packaging and entrypoints to execute code.

Here is a simple example in Poetry of how to generate a proper executable using entrypoints in pyproject.toml:

[tool.poetry.scripts]
dummy-project = "dummy_project.app:app"
@ygalvao
ygalvao / get_cities_using_geonames.py
Last active February 28, 2024 21:54
Fetching all cities within a specific Canadian province or within a radius from a specific city using GeoNames API
#!/usr/bin/env python3
import requests
def fetch_province_cities(province:str)->list:
"""
Fetches all cities within a specific Canadian province.
Args:
province (str): the province's abbreviation.
@ygalvao
ygalvao / get_cities.py
Last active February 28, 2024 21:52
Fetching major cities within a Canadian province using geonamescache and PostalCodeDatabase
#!/usr/bin/env python3
from pypostalcode import PostalCodeDatabase as pcdb
import geonamescache as geoc
# Fetching all postal code areas in Manitoba using the pypostalcode library
pcdb = pcdb()
radius_results = pcdb.get_postalcodes_around_radius('R3G', 999)
radius_results = [pc for pc in radius_results if pc.province == 'Manitoba']
cities_in_radius = set(pc.city.split('(')[0].strip() for pc in radius_results)
@ygalvao
ygalvao / cassandra keys.md
Created February 13, 2024 16:59 — forked from simonwoo/cassandra keys.md
describe the differences between partition key, composite key and clustering key

1.The primary key is a general concept to indicate one or more columns used to retrieve data from a Table.

  • the primary key may be SIMPLE
create table stackoverflow (
      key text PRIMARY KEY,
      data text      
  );
@ygalvao
ygalvao / task3.sh
Created July 25, 2023 17:45
Google Cloud Skills Boost - Create and Manage Cloud Resources: Challenge Lab - Task 3
#!/bin/bash
echo -e '\nStarting the Bash script for the "Create and Manage Cloud Resources: Challenge Lab - Task 3"\n'
gcloud config set compute/region us-central1
gcloud config set compute/zone us-central1-c
echo -e '\nDefault Region and Zone set for Compute Engine\n'
cat << EOF > startup.sh
@ygalvao
ygalvao / codium_url-handler.desktop
Created May 15, 2023 21:07
A simple .desktop file for Codium
[Desktop Entry]
Name=VSCodium
Comment=Code Editing. Redefined.
GenericName=Text Editor
Exec=FLATPAK_ENABLE_SDK_EXT=node14 /usr/bin/flatpak run --branch=stable --arch=x86_64 --command=/app/bin/codium --file->
Icon=com.vscodium.codium
Type=Application
StartupNotify=false
StartupWMClass=VSCodium
Categories=Utility;TextEditor;Development;IDE;
@ygalvao
ygalvao / maintenance.html
Created February 10, 2023 16:39
Simple maintenance page with simple animation (HTML and CSS)
<!doctype html>
<style>
#wrapper_new { width: 100%; max-width: 725px; margin: 0px auto; }
.gears { width:48%; display: inline-block; }
.gears:first-child { margin-right: 3%; }
.gears-container { width:150px; height: 150px; font-size:24px; padding: 9%; position: relative; margin: 0px auto; }
.gear-rotate {
width: 2em;
height: 2em;
top: 50%;
@ygalvao
ygalvao / gist:07bcce231179a19d71167e885a36688b
Created January 8, 2023 20:32 — forked from flopezluis/gist:1880114
get the last element of a generator (python)
#modification of http://stackoverflow.com/questions/5983265/pythonic-way-of-determining-if-the-current-element-is-the-first-or-last-element
def annotate_last_item(gen):
prev_val = gen.next()
for val in gen:
yield False, prev_val
prev_val = val
yield True, prev_val
@ygalvao
ygalvao / export-linkedin-profile-as-pdf.js
Created December 27, 2022 02:14 — forked from marioplumbarius/export-linkedin-profile-as-pdf.js
Export your linkedin public profile to PDF if you're having trouble with internationalization.
// Reason to create this script:
// My profile was created in portuguese, but when I translated
// it to english and tried to save my profile as PDF, it could not
// translate some words and dates to english, so I created this gist
// as an alternative.
// Usage
// 1. open your public profile in an incognito* browser tab. E.g.: https://www.linkedin.com/in/marioluan
// 2. copy-n-past the code below into the browser console
// 3. save as PDF
@ygalvao
ygalvao / gist:67a037031e83f64da4ac765b405c6a66
Last active January 17, 2024 17:15
Templates for deploying a Python function in Google Cloud Functions using Google Cloud CLI
gcloud functions deploy ops-bigquery-etl \
--source ~/Git/data-pipelines/ops-bigquery-etl \
--entry-point ops_etl \
--gen2 \
--runtime python311 \
--region us-central1 \
--trigger-http \
--max-instances 1 \
--allow-unauthenticated \
--memory 1G