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

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

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 / get-npm-package-version
Last active June 21, 2021 09:30 — forked from DarrenN/get-npm-package-version
Extract version from package.json (NPM) using bash / shell
# Version key/value should be on his own line
cat ./package.json | grep -m 1 version | sed 's/[^0-9.]//g'
echo $PACKAGE_VERSION
@josemarcosrf
josemarcosrf / configure_cuda_with_xorg_in_cpu.md
Created February 20, 2021 21:01 — forked from alexlee-gk/configure_cuda_p70.md
Use integrated graphics for display and NVIDIA GPU for CUDA on Ubuntu 14.04

This was tested on a ThinkPad P70 laptop with an Intel integrated graphics and an NVIDIA GPU:

lspci | egrep 'VGA|3D'
00:02.0 VGA compatible controller: Intel Corporation Device 191b (rev 06)
01:00.0 VGA compatible controller: NVIDIA Corporation GM204GLM [Quadro M3000M] (rev a1)

A reason to use the integrated graphics for display is if installing the NVIDIA drivers causes the display to stop working properly. In my case, Ubuntu would get stuck in a login loop after installing the NVIDIA drivers. This happened regardless if I installed the drivers from the "Additional Drivers" tab in "System Settings" or the ppa:graphics-drivers/ppa in the command-line.

@josemarcosrf
josemarcosrf / decrypt_dbeaver.py
Created June 26, 2020 19:58 — forked from felipou/decrypt_dbeaver.py
DBeaver password decryption script - for newer versions of DBeaver
# https://stackoverflow.com/questions/39928401/recover-db-password-stored-in-my-dbeaver-connection
# requires pycrypto lib (pip install pycrypto)
import sys
import base64
import os
import json
from Crypto.Cipher import AES
@josemarcosrf
josemarcosrf / ToggleColorSchemeCommand.py
Last active March 22, 2020 16:55 — forked from rbf/Default (OSX).sublime-keymap
A simple way to toggle between dark and light themes in Sublime Text 2, also for open files in the .workspace settings file.
# From https://gist.github.com/rbf/195acdfe8f51b65e5ecd
# Forked from https://gist.github.com/jasonlong/5395357
# // Copy this to your keybindings (Preferences > Key Bindings - User)
# // Change the keybinding, color schemes, and themes to your preferences
#
# {
# "keys": ["ctrl+shift+s"], "command": "toggle_color_scheme",
# "args": {
# "light_color_scheme": "Packages/User/Soda Light - Espresso.tmTheme",
@josemarcosrf
josemarcosrf / multiline-values.yaml
Created February 25, 2020 15:01 — forked from rjattrill/multiline-values.yaml
Break YAML over multiple lines
# Join multiple lines without new line
value: >
part 1
part 2
# Join with newline
value2: |
line 1
line 2
@josemarcosrf
josemarcosrf / postman_install.sh
Created November 28, 2019 10:50 — forked from cagcak/postman_install.sh
Postman install Ubuntu 18.04
#!/bin/bash
# Get postman app
wget https://dl.pstmn.io/download/latest/linux64 -O postman.tar.gz
sudo tar -xzf postman.tar.gz -C /opt
sudo ln -s /opt/Postman/Postman /usr/bin/postman
#Create a Desktop Entry
cat > ~/.local/share/applications/postman.desktop <<EOL
[Desktop Entry]
Encoding=UTF-8
@josemarcosrf
josemarcosrf / language_to_iso_code.py
Last active November 14, 2019 15:10 — forked from flaviussn/language_to_iso_code.py
From language name to ISO code
import pycountry
from pprint import pformat
from data.model_languages import bert_languages, xlm_lang_codes
def get_codes(language):
lang = pycountry.languages.get(name=language)
alpha_2 = alpha_3 = None
try:
#!/usr/bin/env python3
"""
quicky script that compares two conda environments
can be handy for debugging differences between two environments
This could be made much cleaner and more flexible -- but it does the job.
Please let me know if you extend or improve it.