Skip to content

Instantly share code, notes, and snippets.

#include <ctype.h>
void trim(char * const a)
{
char *p = a, *q = a;
while (isspace(*q)) ++q;
while (*q) *p++ = *q++;
*p = '\0';
while (p > a && isspace(*--p)) *p = '\0';
}
@RhysU
RhysU / gist:5420724
Last active December 16, 2015 10:29
How not to land a job.
// Whatever you do, when asked to enumerate permutations of length n,
// don't demonstrate that you can quickly produce this solution...
#include <algorithm>
#include <cerrno>
#include <cstdlib>
#include <iostream>
#include <iterator>
#include <numeric>
#include <stdexcept>
@RhysU
RhysU / gist:5281465
Last active March 18, 2021 11:35
Using Boost Spirit 2.1+ to evaluate constant arithmetic expressions. See http://agentzlerich.blogspot.com/2011/06/using-boost-spirit-21-to-evaluate.html
//--------------------------------------------------------------------------
//
// Copyright (C) 2011, 2012, 2013 Rhys Ulerich
// Copyright (C) 2012, 2013 The PECOS Development Team
// Please see http://pecos.ices.utexas.edu for more information on PECOS.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
@RhysU
RhysU / running_statistics.hpp
Last active November 27, 2018 18:53
In his article "Accurately computing running variance", John D. Cook presents a small class for computing a running mean and variance using an algorithm with favorable numerical properties reported by Knuth in TAOCP. Departing from Cook's sample, my rewrite below includes templating on the floating point type, permitting accumulating multiple st…
//--------------------------------------------------------------------------
//
// Copyright (C) 2012, 2013 Rhys Ulerich
// Please see http://pecos.ices.utexas.edu for more information on PECOS.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
//--------------------------------------------------------------------------