Skip to content

Instantly share code, notes, and snippets.

@arrieta
arrieta / lexer.cpp
Last active May 3, 2024 13:06
Simple C++ Lexer
// A simple Lexer meant to demonstrate a few theoretical concepts. It can
// support several parser concepts and is very fast (though speed is not its
// design goal).
//
// J. Arrieta, Nabla Zero Labs
//
// This code is released under the MIT License.
//
// Copyright 2018 Nabla Zero Labs
//
@arrieta
arrieta / cascade-classifier.cpp
Created October 5, 2017 00:52
Basic OpenCV C++ example: Object detection using Haar cascades.
// -*- coding:utf-8; mode:c++; mode:auto-fill; fill-column:80; -*-
/// @file cascade-classifier.cpp
/// @brief OpenCV object recognition example.
/// @author J. Arrieta <juan.arrieta@nablazerolabs.com>
/// @date October 04, 2017
/// @copyright (c) 2017 Nabla Zero Labs
/// @license MIT License.
///
/// I wrote this example program for my later reference.
@arrieta
arrieta / sha256.cpp
Created October 10, 2017 20:23
Calculate and display the SHA-256 hash of a list of files using OpenSSL from C++
// -*- coding:utf-8; mode:c++; mode:auto-fill; fill-column:80; -*-
/// @file sha256.cpp
/// @brief Calculate and display the SHA-256 hash of a list of files.
/// @author J. Arrieta <Juan.Arrieta@nablazerolabs.com>
/// @date October 10, 2017
/// @copyright (c) 2017 Nabla Zero Labs
/// @license MIT License
///
/// Compiled in macOS High Sierra 10.13 (previous installation of OpenSSL 1.1.0).
@arrieta
arrieta / heartbeat.cpp
Last active September 1, 2023 03:49
Dirt Simple Heart Beat Server in C++
#include <cerrno>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <chrono>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <unistd.h>
@arrieta
arrieta / color.hpp
Last active April 22, 2023 20:25
C++ std::basic_ostream manipulators for adding ANSI color to terminal- and console-based applications.
// -*- coding:utf-8; mode:c++; mode:auto-fill; fill-column:80; -*-
/// @file color.hpp
/// @brief Output stream manipulators to add ANSI console colors.
/// @author J. Arrieta <Juan.Arrieta@nablazerolabs.com>
/// @date March 14, 2017
/// @copyright (c) 2017 Nabla Zero Labs
///
/// This code is released under The MIT License
///
@arrieta
arrieta / spk.py
Created March 19, 2017 20:47
Example demonstrating how could one work with SPICE SPK files in their original DAF format.
"""spk.py
This is an example meant to demonstrate how could one work directly
with SPICE SPK files in their original DAF format.
It can correctly compute the position and velocity provided by Type II
and Type III ephemerides. As a basis for comparison it calculates the
states of the Galilean satellites for a relatively large number of
epochs and compares it agains CSPICE (which you need to have available
as a shared library if you want to run the test case, but you don't
@arrieta
arrieta / fsm.cpp
Created November 2, 2021 16:38
Basic Table-Driven State Machine in C++
// clang-format off
/*
Basic example showing how could one implement a table-driven state machine in
C++.
Suppose one has a lamp which can be in one of three states: "Off", "On",
"Blink". At any time and via some mechanism, the lamp can trigger two events:
"Switch Off" or "Switch On".
# A test of python
print "Hello World!"
@arrieta
arrieta / node-coloring-greedy.cpp
Created November 8, 2021 14:27
Graph Coloring Algorithms
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <vector>
using Graph = std::vector<std::set<int>>;
using Coloring = std::vector<int>;
@arrieta
arrieta / kdtree.cpp
Created November 8, 2021 14:22
Trivial k-d tree implementation in C++
// Educational implementation of a k-d tree.
#include <algorithm>
#include <array>
#include <iostream>
#include <random>
#include <stdexcept>
#include <string>
#include <vector>