Skip to content

Instantly share code, notes, and snippets.

View eug's full-sized avatar
🎲
Roll the data!

Eugênio Cabral eug

🎲
Roll the data!
View GitHub Profile
@eug
eug / function_call.py
Last active October 23, 2023 00:29
OpenAI Function Call Syntax Sugar
import json
import functools
class Property:
def __init__(self, name, descr_or_enum, required=False):
self.name = name
self.descr_or_enum = descr_or_enum
self.required = required
def to_dict(self):
"""
Schedule Work Breakdown Structure Uncertainty with Monte Carlo Simulations
"""
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
def simulate(wbs, n=100000, proba=0.9):
""" Simulate the possible completion time of a WBS project.
Parameters
@eug
eug / pdf.sh
Created January 13, 2020 15:51
PDF file manipulation via CLI
sudo apt-get install pdftk poppler-utils texlive-extra-utils
# Merge
pdfunite in-1.pdf in-2.pdf in-n.pdf out-merged.pdf
# Rotate
# 1-endnorth
@eug
eug / mat2csv.py
Last active April 4, 2022 12:42
Convert .mat to .csv file
import numpy as np
import pandas as pd
from scipy.io import loadmat
def mat2csv(file_mat, index=False):
mat = loadmat(file_mat, squeeze_me=True)
for colname in mat.keys():
# ignore private column names
if colname.startswith("__"):
@eug
eug / Morton.cpp
Created May 22, 2018 01:42
Converts (interleave) a vector of integer (bitset) coordinates to a Morton code (represented as a bitset).
#include <vector>
#include <boost/dynamic_bitset.hpp>
namespace morton {
/**
Interleaves a vector of bitsets into a unique bitset.
@param axes the vector of axis.
@return a interleaved bitset.
*/
@eug
eug / shp_to_df.py
Created September 11, 2017 01:24
Convert a ESRI Shapefile to Pandas DataFrame
# -*- coding: utf-8 -*-
import pandas as pd
from shapefile import Reader as read_shp
def shp_to_df(shp_filepath):
data = {}
shp = read_shp(shp_filepath)
fields = shp.fields[1:] # Skip 'DeletionFlag'
records = shp.records()
@eug
eug / arithmetic_features.py
Created November 17, 2016 19:58
Generate a new feature matrix consisting of all arithmetic combinations of the features.
def arithmetic_features(X, operations=['+', '-', '/', '*'], commutative=False, inplace=False):
df = X
if not inplace:
df = X.copy()
from itertools import combinations
for x, y in combinations(df.columns, 2):
if '+' in operations:
df['%s+%s' % (x, y)] = df[x] + df[y]
@eug
eug / logging.sh
Last active November 17, 2016 19:59
Simple log functions for shell scripts
# Functions
__err() { echo -e "\033[31mError:\033[0m $1"; exit; }
__warn(){ echo -e "\033[33mWarn :\033[0m $1"; }
__info(){ echo -e "\033[34mInfo :\033[0m $1"; }
# Use
__err "You must be root."
__warn "Missing temp file"
__info "Copying 'x' file"