Skip to content

Instantly share code, notes, and snippets.

@arrieta
arrieta / base64.hpp
Last active January 29, 2019 17:43
Implementation of Base64 encoding and decoding in C++
// -*- coding:utf-8; mode:c++; mode:auto-fill; fill-column:80; -*-
/// @file base64.hpp
/// @brief Base64 encoding and decoding.
/// @author J. Arrieta <juan.arrieta@nablazerolabs.com>
/// @date January 28, 2019
/// @copyright (C) 2019 Nabla Zero Labs
#pragma once
// C++ Standard Library
@arrieta
arrieta / tle.cpp
Created January 25, 2019 23:54
TLE Parser
// -*- coding:utf-8; mode:c++; mode:auto-fill; fill-column:80; -*-
/// @file tle.cpp
/// @brief Implementation of tle.
/// @author J. Arrieta <juan.arrieta@hesslag.com>
/// @date January 25, 2019
/// @copyright (C) 2019 Hesslag, Inc.
// Component header
#include "tle.hpp"
@arrieta
arrieta / slurp.hpp
Created January 13, 2019 00:06
Read file into std::string
#pragma once
#include <fstream>
#include <string>
#include <system_error>
#include <iterator>
inline std::string slurp(const std::string& path) {
constexpr auto flags = std::ios::in | std::ios::binary;
if (auto fp = std::ifstream(path, flags); fp) {
@arrieta
arrieta / benchmark-poly.py
Created November 27, 2018 23:15
Basic benchmark polynomial evaluation using Horner's Method
"""Simple re-arrangement can yield significant performance improvements in
naive, low-order polynomial evaluation. The interested reader may wish to read
about "Horner's method."
(C) 2018 Nabla Zero Labs
MIT License
"""
import time
def p0(a, x):
@arrieta
arrieta / memory_map.hpp
Created November 23, 2018 21:21
Simple Memory Mapping in C++
// -*- coding:utf-8; mode:c++; mode:auto-fill; fill-column:80; -*-
/// @file nzl/memory_map.hpp
/// @brief A mapped memory region.
/// @author J. Arrieta <juan.arrieta@nablazerolabs.com>
/// @date November 23, 2018
///
/// Copyright 2018 Nabla Zero Labs
///
/// Permission is hereby granted, free of charge, to any person obtaining a copy
@arrieta
arrieta / lexer.cpp
Last active March 6, 2024 02:41
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 / pool_of_T.cpp
Created November 3, 2018 18:21
Aligned Object Pool
#include <cassert>
#include <iostream>
#include <memory>
#include <type_traits>
#include <vector>
template <typename T>
class Pool {
public:
using Block = typename std::aligned_storage<sizeof(T), alignof(T)>::type;
@arrieta
arrieta / pds.cpp
Created October 27, 2018 15:56
PDS OBJ Parser Excercise
#include <cctype>
#include <fstream>
#include <iostream>
#include <iterator>
#include <sstream>
#include <stdexcept>
#include <string>
inline bool semantic_compare(std::size_t n, const char *value,
const std::string &s) {
@arrieta
arrieta / string_view_and_arguments.cpp
Created October 23, 2018 16:24
Experiments with std::string_view, argument dispatching, and stuff like that.
/// Experiments with string view, dispatching, and stuff like that.
/// J. Arrieta
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <locale>
#include <string>
// POSIX only
#include <sys/stat.h>
@arrieta
arrieta / non-owning-ts-cache.cpp
Created October 6, 2018 22:12
C++ Non-Owning Thread-Safe Object Cache
#include <chrono>
#include <iostream>
#include <memory>
#include <string>
#include <thread>
#include <unordered_map>
#include <vector>
// In practice these would be actual types instead of aliases.
using Id = int;