Skip to content

Instantly share code, notes, and snippets.

View berlotto's full-sized avatar

Sérgio Berlotto Jr berlotto

View GitHub Profile
@berlotto
berlotto / python_3_email_with_attachment.py
Created June 24, 2020 12:01 — forked from rdempsey/python_3_email_with_attachment.py
Use Python 3 to send an email with an attachment using Gmail
#!/usr/bin/env python
# encoding: utf-8
"""
python_3_email_with_attachment.py
Created by Robert Dempsey on 12/6/14.
Copyright (c) 2014 Robert Dempsey. Use at your own peril.
This script works with Python 3.x
NOTE: replace values in ALL CAPS with your own values
@berlotto
berlotto / postgresql_date_function_index_howto.md
Created July 26, 2019 16:30 — forked from cobusc/postgresql_date_function_index_howto.md
Short explanation of the issues faced when trying to create a PostgreSQL index using the date() function and how to resolve it.

Given a table...

CREATE TABLE foo (
  id SERIAL PRIMARY KEY,
  created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
  ...
);
@berlotto
berlotto / all_aws_lambda_modules_python.md
Created May 19, 2019 01:50 — forked from gene1wood/all_aws_lambda_modules_python.md
AWS Lambda function to list all available Python modules for Python 2.7 3.6 and 3.7

This gist contains lists of modules available in

in AWS Lambda.

It also contains the code to run in Lambda to generate these lists. In addition there is a less_versbose module in the code that you can call to get a list of the top level modules installed and the version of those modules (if they contain a version

@berlotto
berlotto / prompt.sh
Created August 16, 2018 17:47 — forked from singpolyma/prompt.sh
Awesome git prompt
# Determine if the current directory is a GIT repo
# and print out '*' if there are changes to be committed
iz_git_dirty() {
#IZ_GIT=`git status 2>/dev/null`
IZ_DIRTY=`git status 2>/dev/null | grep 'nothing to commit (working directory clean)'`
#if [ "." != "$IZ_GIT." ]; then
if [ "." == "$IZ_DIRTY." ]; then
echo '*'
fi
@berlotto
berlotto / reltime.py
Created July 21, 2017 14:40 — forked from deontologician/reltime.py
Relative datetimes in python
def reltime(date, compare_to=None, at='@'):
r'''Takes a datetime and returns a relative representation of the
time.
:param date: The date to render relatively
:param compare_to: what to compare the date to. Defaults to datetime.now()
:param at: date/time separator. defaults to "@". "at" is also reasonable.
>>> from datetime import datetime, timedelta
>>> today = datetime(2050, 9, 2, 15, 00)
>>> earlier = datetime(2050, 9, 2, 12)
@berlotto
berlotto / senha.sh
Created April 25, 2017 12:40 — forked from fabioadrianosoares/senha.sh
Gerar senha aleatório
#! /usr/bin/bash
#echo 'Obtendo senha do ddg...';
#senha=`wget -q --no-check-certificate -O - \
# https://duckduckgo.com/?q=password+10 | \
# sed -e 's/.*class="zero_click_answer">//' -e 's/ .*//'`;
echo 'Obtendo senha do /dev/urandom';
senha=`cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 10`;
@berlotto
berlotto / async_flask.py
Created March 1, 2017 20:59 — forked from viksit/async_flask.py
Asynchronous requests in Flask with gevent
"""Asynchronous requests in Flask with gevent"""
from time import time
from flask import Flask, Response
from gevent.pywsgi import WSGIServer
from gevent import monkey
import requests
@berlotto
berlotto / gist:9b9c37b4d3b7063ef23f876de46bdaea
Created November 9, 2016 01:31 — forked from lentil/gist:810399
PEP8 pre-commit hook in Python
#!/usr/bin/env python
from __future__ import with_statement
import os
import re
import shutil
import subprocess
import sys
import tempfile
@berlotto
berlotto / wsgi.py
Created September 14, 2016 17:42 — forked from LeZuse/wsgi.py
WSGI script with virtualenv activation with Flask
import os
import sys
# Install venv by `virtualenv --distribute venv`
# Then install depedencies: `source venv/bin/active`
# `pip install -r requirements.txt`
activate_this = '/var/www/apache/csshat.com/csshat.com/venv/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))
path = os.path.join(os.path.dirname(__file__), os.pardir)
# Public Domain, i.e. feel free to copy/paste
# Considered a hack in Python 2
import inspect
def caller_name(skip=2):
"""Get a name of a caller in the format module.class.method
`skip` specifies how many levels of stack to skip while getting caller
name. skip=1 means "who calls me", skip=2 "who calls my caller" etc.