Skip to content

Instantly share code, notes, and snippets.

View isaquealves's full-sized avatar

Isaque Alves isaquealves

View GitHub Profile
@Lonami
Lonami / launchasync.py
Last active January 3, 2024 12:47
Wrapper to launch async tasks from threaded code
import threading
import asyncio
from queue import Queue as BlockingQueue
class TwoSidedQueue:
"""
Behaves like an `asyncio.Queue`, but `get` and `put` act on different ends.
"""
def __init__(self, queue_in, queue_out):
@jerry-git
jerry-git / vax_app.py
Last active September 19, 2022 04:14
Simple modern Python web app
import datetime as dt
import os
import motor
from beanie import Document, Indexed, PydanticObjectId, init_beanie, operators
from fastapi import FastAPI, Response, status
from pydantic import BaseModel
app = FastAPI()
@rochacbruno
rochacbruno / parse_dotenv.bash
Last active March 16, 2021 16:44 — forked from judy2k/parse_dotenv.bash
Parse a .env (dotenv) file directly using BASH
# Pass the env-vars to MYCOMMAND
eval $(egrep -v '^#' .env | xargs) MYCOMMAND
# … or ...
# Export the vars in .env into your shell:
export $(egrep -v '^#' .env | xargs)
# set variables from .compose.env but don't override existing exported vars
eval "$(grep -v '^#' .compose.env | sed -E 's|^(.+)=(.*)$|export \1=${\1:-\2}|g' | xargs -L 1)"
# Load up .env
@joshteng
joshteng / app.py
Created March 30, 2020 10:02 — forked from seanbehan/app.py
Flask with Django ORM
'''
Run the following commands (bc. gists don't allow directories)
pip install flask django dj-database-url psycopg2
mkdir -p app/migrations
touch app/__init__.py app/migrations/__init__.py
mv models.py app/
python manage.py makemigrations
python manage.py migrate
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
language_version: python3
- id: trailing-whitespace
- id: debug-statements
language_version: python3
@ruanbekker
ruanbekker / lxd-usage.txt
Created November 14, 2016 06:34
LXD Usage
Docs - LXD Helpful Docs:
https://www.stgraber.org/2016/03/30/lxd-2-0-image-management-512/
https://www.flockport.com/flockport-first-look-at-lxd/
http://insights.ubuntu.com/2016/03/14/the-lxd-2-0-story-prologue/
Docs - Installation:
http://insights.ubuntu.com/2016/03/14/the-lxd-2-0-story-prologue/
Docs - API:
https://linuxcontainers.org/lxd/getting-started-cli/
@lumengxi
lumengxi / Makefile
Created March 17, 2016 16:44
Makefile for Python projects
.PHONY: clean-pyc clean-build docs clean
define BROWSER_PYSCRIPT
import os, webbrowser, sys
try:
from urllib import pathname2url
except:
from urllib.request import pathname2url
webbrowser.open("file://" + pathname2url(os.path.abspath(sys.argv[1])))
endef
@isaquealves
isaquealves / gist:aad1046307b9c6412e8d
Created May 9, 2015 05:56
Django new application loading
try:
from django.apps import apps
get_model = apps.get_model
except ImportError:
from django.db.models.loading import get_model
@igorcosta
igorcosta / cpf_cnpj_validator
Created June 26, 2014 19:13
Regex para validar CPF e CNPJ
Para CPF
/^\d{3}\.\d{3}\.\d{3}\-\d{2}$/
Para CNPJ
/^\d{2}\.\d{3}\.\d{3}\/\d{4}\-\d{2}$/
Para ambos ao mesmo tempo
@theju
theju / dropbox_upload_handler.py
Created July 17, 2012 11:18
Upload files to dropbox from your django app
from django.core.files.uploadhandler import TemporaryFileUploadHandler
from django.core.files.base import File
from dropbox.client import DropboxClient
from dropbox.session import DropboxSession
from django.conf import settings
import os
class DropboxFileUploadHandler(TemporaryFileUploadHandler):
def __init__(self, *args, **kwargs):
super(DropboxFileUploadHandler, self).__init__(*args, **kwargs)