Skip to content

Instantly share code, notes, and snippets.

View esmitt's full-sized avatar
As fast as a Pentium I

esmitt esmitt

As fast as a Pentium I
View GitHub Profile
esmitt / stack_template.cpp
Created August 15, 2021 17:12
Example of Stack implementation using operator overloading using an array (fixed size).
#include <iostream.h> //example of operator overloading
template<class T>
class Stack {
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 /
Last active November 2, 2023 09:01
Iris detection from an eye photo
# Numpy is needed because OpenCV images in python are actually numpy arrays.
import numpy
import cv2
class iris_detection():
def __init__(self, image_path):
initialize the class and set the class attributes
self._img = None
esmitt / transparency_glfw.cpp
Created June 4, 2021 15:09
Main file to create a transparency window + transparency framebuffer using GLFW. This sample only draws a rotating rectangle.
#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 /
Last active July 19, 2022 18:34
A simple function to load a .mat file using scipy from Python. It uses a recursive approach for parsing properly Matlab' objects
import 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 / cleaning-csharp.bat
Created July 26, 2020 18:06
A script to clean my C# projects
@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 Removing "*.exe.config" files...
esmitt /
Created June 21, 2021 16:12
Convert a .csv file into a Microsoft Excel .xlsx format. It is mandatory to install the package openpyxl and pandas
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 %1
esmitt /
Created June 21, 2021 16:08
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))
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 / keyPressCallback.cpp
Last active April 26, 2021 11:29
VTK way using lambda function in C++ to detect when a key was pressed
vtkNew<vtkCallbackCommand> keypressCallback;
auto KeypressCallbackFunction = [](vtkObject* caller, long unsigned int vtkNotUsed(eventId), void* clientData, void* vtkNotUsed(callData)) {
vtkRenderWindowInteractor* iren = static_cast<vtkRenderWindowInteractor*>(caller);
std::cout << "Pressed: " << iren->GetKeySym() << std::endl;
renderWindowInteractor->AddObserver(vtkCommand::KeyPressEvent, keypressCallback);
esmitt / tostring.cpp
Created April 23, 2021 15:03
A function to convert a numerical data type into a string using precision decimals
#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 << std::fixed << a_value;
#include <iostream>
#include <chrono>
int main()
std::cout << "Starting computation ..." << std::endl;
auto start = std::chrono::steady_clock::now();
// insert code to measure here
auto end = std::chrono::steady_clock::now();
auto diff = end - start;