Skip to content

Instantly share code, notes, and snippets.

View mtao's full-sized avatar

Michael Tao mtao

View GitHub Profile
@mtao
mtao / houdini_iterator_wrapper.cpp
Last active August 29, 2017 19:24
simple attempt to make houdini iterators work with range for loops / transform
#include <iostream>
#include <iterator>
#include <algorithm>
#include "houdini_iterator_wrapper.hpp"
int main() {
hdk_test_iter vit(10);
for ( vit.rewind(); !vit.atEnd(); vit.advance() ) {
@mtao
mtao / staggered_grid_looper.cxx
Created July 27, 2017 16:12
a test in using boost::hana to instantiate all of the pertinent calls for calling template specialized functions for each grid type
#include <iostream>
#include <array>
#include <utility>
#include <iostream>
#include <boost/hana/for_each.hpp>
#include <boost/hana/integral_constant.hpp>
#include <boost/hana/range.hpp>
constexpr size_t factorial(size_t v) {
return v==0?1:factorial(v-1) * v;
@mtao
mtao / poor_reflection.cpp
Created May 16, 2017 21:12
wanted to print out extra detail on the types i was using so I wrote a small test case for accessing them through a pattern I was already using
#include <iostream>
#include <typeinfo>
#include <memory>
#include <cxxabi.h>
#include <vector>
class ObjectBase {
public:
virtual std::string held_type() const = 0;
@mtao
mtao / filter.cpp
Last active May 10, 2017 18:25
a quick example that mimics the python2 filter operator using c++14 where filter is implemented as a lambda function
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <iterator>
int main( int argc, char * argv[]) {
@mtao
mtao / unpacking_to_structured_bindings.cpp
Created April 17, 2017 14:21
an experiment on how to use structured bindings with prvalues (it took me a bit to realize the constness doesn't affect the double& embedded within)
#include <iostream>
#include <tuple>
//sample vector class
struct Vec3 {
public:
Vec3(const std::initializer_list<double>& a) { std::copy(a.begin(),a.end(),data); }
double& operator()(size_t i) { return data[i]; }
private:
#include <iostream>
#include <Eigen/Core>
//Mimics http://stackoverflow.com/a/40958644
template <typename Scalar, int D, int E, int... Is>
auto eigen_unpack_impl(const Eigen::Matrix<Scalar, D, E>& a, std::integer_sequence<int,Is...>) {
return std::tie( a(Is)... );
}
@mtao
mtao / active_set.cpp
Created February 26, 2017 00:50
a tool for extracting variables with boundary conditions. currently only have dirichlet there
#include "active_set.h"
#include <set>
template <>
const ActiveSet::IndexPair& ActiveSet::getIndexPair<ActiveSet::VariableType::Free>() const {
return m_active_pair;
}
template <>
const ActiveSet::IndexPair& ActiveSet::getIndexPair<ActiveSet::VariableType::Dirichlet>() const {
return m_dirichlet_pair;
@mtao
mtao / imgui_impl_glut.cpp
Last active August 30, 2021 10:03
imgui glut bindings
// ImGui GLUT binding with OpenGL
// In this binding, ImTextureID is used to store an OpenGL 'GLuint' texture identifier. Read the FAQ about ImTextureID in imgui.cpp.
// If your context is GL3/GL3 then prefer using the code in opengl3_example.
// You *might* use this code with a GL3/GL4 context but make sure you disable the programmable pipeline by calling "glUseProgram(0)" before ImGui::Render().
// We cannot do that from GL2 code because the function doesn't exist.
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown().
// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
@mtao
mtao / pif.hpp
Last active January 19, 2017 16:32
a header dsl for pif who loves perl
#ifndef PIFDSL_HPP
#define PIFDSL_HPP
#include <map>
namespace pif {
using hash = std::map<string,string>;
}
//example:
#include <iostream>
#include <algorithm>
#include <iterator>
#include <vector>
#include <sstream>
template <typename T>
std::string to_csv(const std::vector<T>& vec) {
std::stringstream ss;
std::copy(vec.begin(),vec.end()-1,std::ostream_iterator<T>(ss,","));