Skip to content

Instantly share code, notes, and snippets.

View cjameshuff's full-sized avatar

Christopher James Huff cjameshuff

View GitHub Profile
@cjameshuff
cjameshuff / cppformat.h
Created November 21, 2012 21:07
Extensible formatted strings for C++
// Usage:
// string s = (fstring("Testing...%d, %f, %d\n")% 1 % 2.0 % 42).str();
// cout << fstring("Testing...%d, %f, %d\n")% 1 % 2.0 % 42;
// cout << fstring("%s%d, %f, %d\n")% "Testing..." % 1 % 2.0 % 42;
// cout << fstring("%s%c%c%c%d, %f, %d\n")% "Testing" % '.' % '.' % '.' % 1 % 2.0 % 42;
// cout << fstring("%s%d, %f, %d\n")% string("Testing...") % 1 % 2.0 % 42;
#ifndef CPPFORMAT_H
#define CPPFORMAT_H
@cjameshuff
cjameshuff / gist:85642de07f2af4e0b21efae6a97b22df
Created January 1, 2018 00:19
Clang 5.0 toolchain install
# https://stackoverflow.com/questions/39332406/install-libc-on-ubuntu
# Adapted for Clang 5.0
sudo apt-get update
sudo apt-get install -y clang-5.0 clang-5.0-doc \
libclang-common-5.0-dev libclang-5.0-dev libclang1-5.0 libclang1-5.0-dbg \
libllvm5.0 libllvm5.0-dbg lldb-5.0 llvm-5.0 llvm-5.0-dev llvm-5.0-runtime \
clang-format-5.0 python-clang-5.0 liblldb-5.0-dev lld-5.0 libfuzzer-5.0-dev \
subversion cmake
@cjameshuff
cjameshuff / format.cpp
Last active January 26, 2017 23:09
boost::format with type-safe C-style format strings
#include "boost/format.hpp"
#include <string>
#include <utility>
inline auto fmt_r(boost::format & format) -> boost::format & {return format;}
template<typename T, typename... Args>
auto fmt_r(boost::format & format, T && val, Args &&... args) -> boost::format & {
return fmt_r(format % std::forward<T>(val), std::forward<Args>(args)...);
}
#include <cstdlib>
#include <iostream>
#include <iterator>
#include "boost/format.hpp"
using boost::format;
namespace iter {
template<typename T>
auto BBox::SlopeTest(const t_ClassifiedRay<T> & ray) const -> bool
{
auto && tl = (minExt - ray.origin)*ray.rdir;
auto && th = (maxExt - ray.origin)*ray.rdir;
auto && tmin = std::min(tl.x, th.x);
auto && tmax = std::max(tl.x, th.x);
tmin = std::max(tmin, std::min(std::min(tl.y, th.y), tmax));
tmax = std::min(tmax, std::max(std::max(tl.y, th.y), tmin));
#include <iostream>
#include <cstdlib>
#include <cfloat>
#include <cmath>
#include "simpletest.h"
#include "allocator.h"
// *****************************************************************************
// The MIT License (MIT)
//
// Copyright (c) 2013 Christopher James Huff
// https://github.com/cjameshuff/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
static Foo * foo = nullptr;
static Mutex fooLock;
Foo * GetFoo()
{
if(!foo)
{
fooLock.Lock();
class Fault: public TerrainFn {
protected:
const float4 center;
const float4 plane;
const float4 displacement;
const float amplitude;
public:
Fault(fn_handle _input, float4 c, float4 p, float amp):
TerrainFn{std::move(_input)},
auto tfn = fn_handle{new TerrainFn};
thickness = 10.0f;
layerIdx = 1;
tfn = fn_handle{new PlaneLayer(std::move(tfn), layerIdx++, elev, 100.0f)};
tfn = fn_handle{new Turbulate(std::move(tfn), turbScl, turbAmp)};
elev += thickness;
layerIdx = igneous;