Skip to content

Instantly share code, notes, and snippets.

View jonesinator's full-sized avatar

Aaron Jones jonesinator

  • SolidFire
  • Boulder, CO
View GitHub Profile
@jonesinator
jonesinator / chroot_package_diff
Created March 14, 2018 14:53
Generate the difference in packages between two Debian-derived chroots.
#!/usr/bin/env bash
set -e
# Validate the command-line arguments.
if [[ $# -ne 3 ]]; then
echo "Usage: $0 [chroot1] [chroot2] [only_in_1,only_in_2,in_both]"
exit 1
elif [[ ! -d "$1" ]]; then
echo "$1 is not a directory."
exit 1
@jonesinator
jonesinator / decompose.cpp
Created October 10, 2017 22:46
c++17 - Decompose a std::chrono::duration into several component durations.
#include <chrono>
#include <iostream>
#include <tuple>
template <typename lhs_t, typename rhs_t, typename... other_ts>
constexpr bool has_decreasing_periods() {
if constexpr (std::ratio_less_v<typename lhs_t::period,
typename rhs_t::period>) {
return false;
} else if constexpr (sizeof...(other_ts)) {
@jonesinator
jonesinator / input.cpp
Last active October 12, 2017 19:10
c++17 - Get several inputs at once from an input stream.
#include <iostream>
#include <tuple>
template <typename... input_ts>
auto stream_get(std::istream& stream) {
if constexpr (sizeof...(input_ts) == 1) {
std::tuple_element_t<0, std::tuple<input_ts...>> input;
stream >> input;
return input;
} else {
@jonesinator
jonesinator / combination.py
Created March 15, 2017 02:40
Compute the nth combination in lexicographic order more efficiently.
#! /usr/bin/python
#
# This snippet provides a simple function "combination" that can compute an
# arbitrary k-combination of n elements given an index m into the
# lexicographically ordered set of all k-combinations of n elements.
from math import factorial