Skip to content

Instantly share code, notes, and snippets.

@arrieta
arrieta / lpsub.py
Created December 6, 2017 15:33
Longest Palindromic Substring
def longest_palindrome_constant_space(s):
N = len(s)
if N == 0:
return 0
elif N == 1:
return 1
elif N == 2:
return 1 + (s[0] == s[1])
@arrieta
arrieta / lcs.py
Created December 6, 2017 15:33
Longest Common Subsequence
def lcs(s1, s2):
def lcs_(s1, s2, m, n):
if (m < 0) or (n < 0):
return 0
elif s1[m] == s2[n]:
return 1 + lcs_(s1, s2, m - 1, n - 1)
@arrieta
arrieta / egg_drop.py
Created November 29, 2017 19:08
General Egg Drop Problem (Dynamic Programming)
# egg_drop.py
#
# Solution to the general egg drop problem via:
#
# 1. A recursive-memoized algorithm
# 2. A bottom-up table construction
#
# (C) 2017 J. Arrieta, Nabla Zero Labs
# MIT License.
@arrieta
arrieta / example-linspace.cpp
Created November 1, 2017 22:59
C++ implementation of linspace.
// -*- coding:utf-8; mode:c++; mode:auto-fill; fill-column:80; -*-
/// @file example-linspace.cpp
/// @brief Sample use of Nabla Zero Labs' linspace utilities.
/// @author J. Arrieta <Juan.Arrieta@nablazerolabs.com>
/// @date November 01, 2017
/// @copyright (c) 2017 Nabla Zero Labs
/// @license MIT License
// C++ Standard Library
@arrieta
arrieta / SecureMemoryRegion.cpp
Created October 15, 2017 22:24
Provide a memory region that never swaps to disk.
// -*- coding:utf-8; mode:c++; mode:auto-fill; fill-column:80; -*-
/// @file SecureMemoryRegion.cpp
/// @brief Provide region of memory that never swaps to disk.
/// @author J. Arrieta <Juan.Arrieta@nablazerolabs.com>
/// @date October 15, 2017
/// @copyright (c) 2017 Nabla Zero Labs
///
/// $ clang++ -o SecureMemoryRegion SecureMemoryRegion.cpp -std=c++1z \
/// -Wall -Wextra -Ofast -march=native
@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 / 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 / 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 / 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 / list.hpp
Created August 23, 2016 02:08
Educational implementation of a list in the style of the C++ Standard Library (it is minimal and incomplete, but easier to read than GCC's source).
// -*- coding:utf-8; mode:c++; mode:auto-fill; fill-column:80; -*-
/// @file list.hpp
/// @brief A minimal list implementation copying the style of the C++
/// Standard Library --- it is meant for educational purposes.
/// @author J. Arrieta <Juan.Arrieta@nablazerolabs.com>
/// @copyright Copyright (c) 2016 Nabla Zero Labs. All rights reserved.
/// @license This software is released under the MIT License.
/// @warning Do not use this turd in production code, or for anything that is
/// not strictly educational. Just use std::list (actually you most