Skip to content

Instantly share code, notes, and snippets.

View renegarcia's full-sized avatar

Rene Garcia renegarcia

View GitHub Profile
@renegarcia
renegarcia / dias_transcurridos.py
Created December 16, 2023 17:27
Elapsed days from daterange
from datetime import datetime
# Formato de la fecha: 'dd-mm-yyyy'
fecha_inicio = '01-01-2023'
fecha_fin = '16-12-2023'
# Convertir las cadenas a objetos datetime
fecha_inicio = datetime.strptime(fecha_inicio, '%d-%m-%Y')
fecha_fin = datetime.strptime(fecha_fin, '%d-%m-%Y')
@renegarcia
renegarcia / onedrive_dd_generator.py
Created November 19, 2023 15:33 — forked from JoeThunyathep/onedrive_dd_generator.py
Generate direct download link from OneDrive
import base64
def create_onedrive_directdownload (onedrive_link):
data_bytes64 = base64.b64encode(bytes(onedrive_link, 'utf-8'))
data_bytes64_String = data_bytes64.decode('utf-8').replace('/','_').replace('+','-').rstrip("=")
resultUrl = f"https://api.onedrive.com/v1.0/shares/u!{data_bytes64_String}/root/content"
return resultUrl
@renegarcia
renegarcia / mkdir_recursively.py
Created November 17, 2023 15:57
Python tip: Create directories recursively if don´t exist
from pathlib import Path
def create_dirs_recursively(location: str):
Path(location).mkdir(parents=True, exist_ok=True)
@renegarcia
renegarcia / extract_zip_to_sqlite.py
Created November 2, 2023 17:51
Extract a zipped collection on csv files into a fresh sqlite3 database
"""
extract_zip_to_sqlite.py: Extract a zipped collection on csv files into a fresh sqlite3 database.
== Requirements ==
* A fairly recent version of Pandas.
* An schema of the tables definitions.
== Ussage ==
@renegarcia
renegarcia / export_access_to_csv.py
Created October 12, 2023 21:45
Export access tables as a zip-compressed collection of csv files
"""
export_access_to_csv.py - Creates a compressed dump of an MSAccess database tables.
USAGE
invoke from the same directory where `settings.toml` is located.
RETURNS
A comprezed zip file in the format '%Y-%m-%dT%H_%M_%S-database_name.zip'
@renegarcia
renegarcia / create_post.py
Last active October 8, 2023 17:44
Python script to create a new post in jekyll.
import argparse
from datetime import date
from pathlib import Path
FRONTMATTER_TEMPLATE = """---
layout: page
title: {args.title}
comments: true
published: true
@renegarcia
renegarcia / git-clone.py
Last active August 31, 2023 20:45
A lightweight tool to clone git repositories.
#!/usr/bin/env python3
from subprocess import run
from os.path import split
from cleo import Command, Application
import os
ROOT = {'github': 'git@github.com',
'bitbucket': 'git@bitbucket.org'}
@renegarcia
renegarcia / bat.sh
Last active July 28, 2023 17:26
Show battery status cli
#!/usr/bin/bash
upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep -E "state|to full| percentage"
@renegarcia
renegarcia / words.py
Created July 15, 2023 07:19
Reads from stdin and prints words one per line.
"""
words.py: Reads from stdin and prints words one per line.
"""
import fileinput
for line in fileinput.input():
for word in line.split():
print(word)
@renegarcia
renegarcia / CONFIG-example.ini
Created July 11, 2023 17:57
Fbexport Query - Exports queries from an Firebird database
# Rename to CONFIG.ini if using this file to add the path to fbexport
[DEFAULT]
# Update with the path to fbexport
FBEXPORT = /path/to/fbexport