Skip to content

Instantly share code, notes, and snippets.

View josemarcosrf's full-sized avatar
🏔️
Working from a mountain top

Jose Marcos RF josemarcosrf

🏔️
Working from a mountain top
View GitHub Profile
@josemarcosrf
josemarcosrf / minimal_celery_worker_example.py
Last active October 26, 2023 16:00
A minimal celery worker client example
import fire
import pika
import redis
import os
from typing import Any
from typing import Dict
from typing import List
from typing import Tuple
import celery
@josemarcosrf
josemarcosrf / pdf_mine_with_boxes.py
Last active October 10, 2023 13:25
Quick and dirty implementation of a text and bounding box extraction from PDFs using pdfminer.six==20191110
from collections import defaultdict
import fire
from pdfminer.converter import PDFPageAggregator
from pdfminer.layout import LAParams
from pdfminer.layout import LTChar
from pdfminer.layout import LTTextBox
from pdfminer.layout import LTTextLine
from pdfminer.pdfinterp import PDFPageInterpreter
from pdfminer.pdfinterp import PDFResourceManager

convert google takeout archive for location history from kml to gpx and split file into one per day

gpsbabel -i kml -f Location\ History.kml -o gpx -F out.gpx
gpsbabel -t -i gpx -f out.gpx -x track,merge,pack,split,title="ACTIVE LOG # %Y%m%d" -o gpx -F split.gpx
python2 gpxsplitter.py split.gpx
@josemarcosrf
josemarcosrf / whoosh-search.ipynb
Created December 8, 2022 15:50
Whoosh Search example notebook
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@josemarcosrf
josemarcosrf / layoutlmv3-funsd-train.ipynb
Last active March 23, 2023 11:59
layoutlmv3-funsd-train.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@josemarcosrf
josemarcosrf / github_pip.sh
Created November 11, 2022 15:04
pip install from github
pip install -e git://github.com/{ username }/{ reponame }.git@{ tag name }#egg={ desired egg name }
@josemarcosrf
josemarcosrf / stt-exploratory-telebot.ipynb
Last active September 29, 2022 20:32
stt-exploratory-telebot.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
# 1. Install system deps
apt install ghostscript python3-tk
# 2. Install python deps
pip install
excalibur-py \
python3-ghostscript \
"jinja2<3.1.0" \
"Flask==1.1.4" \
"markupsafe==2.0.1"

pymongo vs Motor

Motor is an async Python driver for MongoDB.

When should I use Motor?

You should use Motor when you're trying to interact with a MongoDB database in an asynchronous context. When you're making something that needs to be asynchronous (like a web server, or most commonly from what I've seen here, Discord bots), you also want all the database calls to be done asynchronously. But pymongo is synchronous, i.e it is blocking, and will block the execution of your asynchronous program for the time that it is talking to the database.

Okay, How do I switch now?!

Thankfully for us, switching from pymongo to Motor isn't too hard, and won't need you to change much code. This process can be roughly summarized as:

Step 1: Install Motor, and import it

Installing can be done with pip - pip install motor

@josemarcosrf
josemarcosrf / sqlite_to_postgres.md
Created July 13, 2022 21:38
SQLite to Postgress migration

SQLite to Postgres

Extracting from SQLite

We have two options:

  1. Create a dump: