Skip to content

Instantly share code, notes, and snippets.

Avatar
🐢
As fast as a Pentium I

esmitt esmitt

🐢
As fast as a Pentium I
View GitHub Profile
@esmitt
esmitt / stack_template.cpp
Created Aug 15, 2021
Example of Stack implementation using operator overloading using an array (fixed size).
View stack_template.cpp
#include <iostream.h> //example of operator overloading
template<class T>
class Stack {
public:
Stack(int n);
Stack(Stack<T>& s); //copy constructor
~Stack() {delete [] stackPtr;} // destructor
Stack<T> operator + (const Stack<T>& s2) const; //overloading +
Stack<T>& operator = (const Stack<T>& s); //overloading assignment
@esmitt
esmitt / csv_to_xlsx.py
Created Jun 21, 2021
Convert a .csv file into a Microsoft Excel .xlsx format. It is mandatory to install the package openpyxl and pandas
View csv_to_xlsx.py
import sys
import pandas as pd
filename = sys.argv[1]
filename = filename[:-4]
read_file = pd.read_csv (filename + ".csv")
read_file.to_excel (filename + ".xlsx", index = None, header=True)
# run as
# python csv_to_xlsx.py %1
@esmitt
esmitt / starting_functionalCNN.py
Created Jun 21, 2021
Sample in how to build a functional model in Tensorflow. This is a starting code where random images are created, training and predictions. The network is a simple convolutional block (conv2D + maxpool + norm -> flatten + dense layer))
View starting_functionalCNN.py
from tensorflow.keras import Model
from tensorflow.keras.layers import Convolution2D
from tensorflow.keras.layers import MaxPool2D
from tensorflow.keras.layers import BatchNormalization
from tensorflow.keras.layers import Input
from tensorflow.keras.layers import Flatten
from tensorflow.keras.layers import Dropout
from tensorflow.keras.layers import Dense
from tensorflow.keras.layers import concatenate
from tensorflow.keras.optimizers import Adam
@esmitt
esmitt / transparency_glfw.cpp
Created Jun 4, 2021
Main file to create a transparency window + transparency framebuffer using GLFW. This sample only draws a rotating rectangle.
View transparency_glfw.cpp
#include <windows.h>
#include <GLFW/glfw3.h>
#include <iostream>
// change this to int main() to allow the console
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, char*, int nShowCmd)
{
GLFWwindow* window;
int windowSizeW = 640, windowSizeH = 480;
// initialize the library
@esmitt
esmitt / tostring.cpp
Created Apr 23, 2021
A function to convert a numerical data type into a string using precision decimals
View tostring.cpp
#include <iostream>
#include <string>
#include <sstream>
template <typename T>
std::string to_string_with_precision(const T a_value, const int n = 4)
{
std::ostringstream out;
out.precision(n);
out << std::fixed << a_value;
@esmitt
esmitt / load_mat.py
Last active Jul 19, 2022
A simple function to load a .mat file using scipy from Python. It uses a recursive approach for parsing properly Matlab' objects
View load_mat.py
import scipy.io as scio
from typing import Any, Dict
import numpy as np
def load_matfile(filename: str) -> Dict:
def parse_mat(element: Any):
# lists (1D cell arrays usually) or numpy arrays as well
if element.__class__ == np.ndarray and element.dtype == np.object_ and len(element.shape) > 0:
return [parse_mat(entry) for entry in element]
@esmitt
esmitt / pokemon_jupyter.py
Created Feb 3, 2021
Mostrar la imagen de un pikachu utilizando pokeapi.co. Pensado para ser desplegado en una ventana emergente en PyCharm.
View pokemon_jupyter.py
# first, install requests and matplotlib (pip install requests matplotlib)
from urllib.request import urlopen
from PIL import Image
import matplotlib.pyplot as plt
import requests
api_url_pokemon = 'https://pokeapi.co/api/v2/pokemon/pikachu'
result = requests.get(api_url_pokemon)
if result.status_code == 200:
pokemon_data = result.json()
@esmitt
esmitt / statistic-list.py
Last active Oct 14, 2020
Prints statistics over an array of numbers using describe function from scipy and numpy range of values function (ptp)
View statistic-list.py
from scipy.stats import describe
import numpy as np
# arr_values is a numpy array
def print_stats(arr_values: np.array) -> None:
stats = describe(arr_values)
print(f'min: {stats.minmax[0]:.5f}, max: {stats.minmax[1]:.4f}')
print(f'mean: {stats.mean:.5f}')
print(f'standard: {np.std(arr_values):.5f}')
print(f'variance: {stats.variance:.5f}')
@esmitt
esmitt / cleaning-csharp.bat
Created Jul 26, 2020
A script to clean my C# projects
View cleaning-csharp.bat
@echo off
REM Remove files generated by compiler in this directory and all subdirectories.
REM Essential release files are kept.
echo Removing "*.csproj.user" files...
for /f "delims==" %%i in ('dir /b /on /s "%~p0*.csproj.user"') do del "%%i" /f /q
echo.
echo Removing "*.exe.config" files...
@esmitt
esmitt / plot-ROC.py
Last active Oct 15, 2020
Plotting the ROC curve using matplotlib
View plot-ROC.py
from sklearn.metrics import roc_auc_score, roc_curve
def plot_roc(name: str, labels: numpy.ndarray, predictions: numpy.ndarray, **kwargs) -> ():
fp, tp, _ = roc_curve(labels, predictions)
auc_roc = roc_auc_score(labels, predictions)
plt.plot(100*fp, 100*tp, label=name + " (" + str(round(auc_roc, 3)) + ")",
linewidth=2, **kwargs)
plt.xlabel('False positives [%]')
plt.ylabel('True positives [%]')
plt.title('ROC curve')