Skip to content

Instantly share code, notes, and snippets.

View otrenav's full-sized avatar

Omar Trejo otrenav

View GitHub Profile
@otrenav
otrenav / .md
Last active December 9, 2020 04:48
Fast Python

Fast Python

Measure Time

To measure a function's execution time start ipython, import code without running the "main" part, and execute your code. You can also do it directly by importing and calling the timeit.timeit function.

@otrenav
otrenav / GitHub Tips.md
Last active December 19, 2020 22:02
Compare GitHub branches

Compare two branches

github.com/<user>/<repo>/compare/<branch_one>..<branch_two>

Keybase proof

I hereby claim:

  • I am otrenav on github.
  • I am omartrejo (https://keybase.io/omartrejo) on keybase.
  • I have a public key whose fingerprint is DFA1 4773 63B9 9A8F CE6A 4C90 54D6 155D 9175 79CC

To claim this, I am signing this object:

@otrenav
otrenav / lets-ecnrypt-certificates.sh
Last active May 21, 2018 20:02
Let's Encrypt Certificates
sudo certbot certonly --manual --preferred-challenges dns -d [DOMAIN] -d www.[DOMAIN]
sudo cat /etc/letsencrypt/live/[DOMAIN]/fullchain.pem
sudo cat /etc/letsencrypt/live/[DOMAIN]/privkey.pem
@otrenav
otrenav / docker-commands.sh
Created May 21, 2018 19:42
Docker Commands
# Stop all containers
docker kill $(docker ps -q)
# Remove all containers
docker rm $(docker ps -a -q)
# Remove all docker images
@otrenav
otrenav / python-uml.sh
Last active November 27, 2020 00:44
Python UML Diagrams
# Setup
sudo apt install graphviz
pip install pylint
# Usage: should be executed from within root
# directory and have a `__init__.py` file
pyreverse -A -f ALL -o png -p [PROJECT_NAME] .
@otrenav
otrenav / scheduling-on-ubuntu-server.sh
Created May 2, 2018 07:01
Scheduling on Ubuntu Server
#
# Use indirection with bash script and change into working directory
#
# To gain root in Ubuntu
sudo su
# To see CRON logs after execution
grep -i cron /var/log/syslog
@otrenav
otrenav / non-ajax-post-submit.js
Last active May 2, 2018 06:57
Non-AJAX (HTTP) submit using JavaScript
// http://stackoverflow.com/questions/5524045/jquery-non-ajax-post
function submit(action, method, values) {
var form = $('<form/>', {
action: action,
method: method
});
$.each(values, function() {
form.append($('<input/>', {
@otrenav
otrenav / python-execution-with-stdout-and-stderr-logging.sh
Last active May 2, 2018 06:59
Execute Python and log both stdout and stderr to a file
#
# Print Python script output as well as save it to a file. The `-u`
# switch tells Python to avoid buffering `stderr` and `stdout`
# which is required by `tee` to save the output to the file.
#
python -u main.py | tee output.log