Skip to content

Instantly share code, notes, and snippets.

View RHDZMOTA's full-sized avatar
👨‍💻
More info at: rhdzmota.com

Rodrigo H. Mota RHDZMOTA

👨‍💻
More info at: rhdzmota.com
View GitHub Profile

Keybase proof

I hereby claim:

  • I am rhdzmota on github.
  • I am rhdzmota (https://keybase.io/rhdzmota) on keybase.
  • I have a public key ASCLjW-y4L43TZVJ76_0iElh_vZInP3rtww0Oud7lAUvdgo

To claim this, I am signing this object:

import inspect
import json
from typing import Dict, TypeVar
SerializableADT = TypeVar("SerializableADT", bound="Serializable")
class Serializable:
@RHDZMOTA
RHDZMOTA / environment-variable-check.sh
Created May 8, 2020 20:22
You can use the following function to check if an environment variable is set via parameter expansion. Early exit if it's not.
#!/usr/bin/env bash
function environ-check() {
local environ_tag="${1}"
local environ_val="${!1}"
if [[ -z "${environ_val}" ]]
then echo "Environ variable is not set ${environ_tag}"; exit 1
fi
}
import numpy as np
def irr(cashflows):
# Get polynomial roots
res = np.roots(cashflows[::-1])
# Filter out imaginary component.
mask = (res.imag == 0) & (res.real > 0)
if not mask.any:
return np.nan
@RHDZMOTA
RHDZMOTA / example-output.json
Last active May 4, 2020 00:21
Multiprocessing when having a blocking process (matplotlib and disk writes) - a quick hack
{
"ASYNC-PROCESS": 2.6283581256866455,
"ASYNC-THREAD": 11.003680944442749,
"SYNC": 10.771448135375977
}
@RHDZMOTA
RHDZMOTA / irr-jax.py
Created April 27, 2020 06:13
Internal rate of return using JAX.
import jax.numpy as np
def irr(cashflows):
res = np.roots(cashflows[::-1])
mask = (res.imag == 0) & (res.real > 0)
# Filter out imaginary component.
if not mask.any():
return np.nan
res = res[mask].real
@RHDZMOTA
RHDZMOTA / snippet.md
Last active May 6, 2020 00:14
Some utility commands for git & github!

Update your repo!

One-time setup

Run the following commands on the first setup:

  1. Create an empty repository on github.
    • Name: credit-risk-lecture
    • Description: [team-name]
  2. Create the repo and add rhdzmota as a collaborator.
@RHDZMOTA
RHDZMOTA / Dockerfile
Created January 2, 2020 17:49
Alpine python with postgresql and mysql deps
FROM python:3.7-alpine3.9
ENV PYTHONBUFFERED 1
RUN apk add --update --no-cache --virtual .build-deps \
ca-certificates gcc postgresql-dev python3-dev linux-headers musl-dev \
libffi-dev jpeg-dev zlib-dev g++ mariadb-dev
RUN mkdir /code
WORKDIR /code

The enrollment-database contains data resembling the following:

  • student
id first_name last_name gender gpa age
1 Amelia O'Sullivan female 3.7 20
2 Rachel Stevens female 3.5 25
3 Sarah Dunn female 3.2 23
4 Liam Baker male 3.3 24
@RHDZMOTA
RHDZMOTA / README.md
Created October 18, 2019 22:54
Tree Traversal Exercise

Tree Traversal Exercise

Given a tree-like structure like:

          3  
        / | \
       1  5 10   
      /  / \  \
     6  1   4  5