Skip to content

Instantly share code, notes, and snippets.

Jeff Trull jefftrull

Block or report user

Report or block jefftrull

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jefftrull
jefftrull / tangle.org
Created Jul 28, 2019
org-babel demo from Emacs SF meetup 2019-07-24
View tangle.org

Brief intro to Source Code in Org

Required Setup

;; add support for C++ and Python
(org-babel-do-load-languages
  'org-babel-load-languages
  '((C . t) (python . t)))
View cxx_tangle.org

Testing C++ tangling from org-mode

View ja1.cpp
// std::vector<Eigen::VectorXf> -> Eigen::MatrixXf
#include <iostream>
#include <vector>
#include <Eigen/Dense>
int main() {
using namespace Eigen;
const int cols = 10;
const int rows = 10; // or do you get it from the sizes of each entry in *d?
std::vector<VectorXf> * d = new std::vector<VectorXf>(cols);
View ja1.cpp
// demonstrating use of Eigen::Map
#include <iostream>
#include <vector>
#include <Eigen/Dense>
int main() {
using namespace Eigen;
std::vector<float> foo{1.0, 2.0, 3.0, 4.0};
Map<Matrix<float, Dynamic, 1>> foom(foo.data(), foo.size());
IOFormat OctaveFmt(StreamPrecision, 0, ", ", ";\n", "", "", "[", "]");
@jefftrull
jefftrull / gist:f5d8ecb218815523f5d7af836eea8b9a
Created Apr 25, 2017
Cannot sort with boost::iterator::zip_iterator
View gist:f5d8ecb218815523f5d7af836eea8b9a
// experimenting with zip iterator and sort
#include <vector>
#include <iostream>
#include <boost/iterator/zip_iterator.hpp>
#include <boost/fusion/adapted/std_tuple.hpp>
using zip_it = boost::zip_iterator<std::tuple<std::vector<std::size_t>::iterator,
std::vector<std::size_t>::iterator,
@jefftrull
jefftrull / gist:983d783cf508249e5352de8e844a27cb
Created Sep 20, 2016
Interesting (possibly wrong) synthesized attribute behavior
View gist:983d783cf508249e5352de8e844a27cb
#include <iostream>
#include <boost/spirit/include/qi.hpp>
#include <boost/optional.hpp>
#include <boost/optional/optional_io.hpp>
int main() {
using namespace std;
// parsing parentheses that may or may not contain integers
string in("(10) () (20)");
@jefftrull
jefftrull / gist:0d7ecfef151c39885a7633d7547df8e6
Created Apr 18, 2016
*qi::string is compatible with both std::string (concatenation) and std::vector<std::string> (push_back) attributes
View gist:0d7ecfef151c39885a7633d7547df8e6
#include <string>
#include <vector>
#include <boost/spirit/include/qi.hpp>
using string_it_t = std::string::const_iterator;
int main() {
using namespace boost::spirit;
using namespace boost::spirit::qi;
@jefftrull
jefftrull / gist:2fbbd52a0dec25c1e14d1e69af3361ac
Created Apr 18, 2016
Spirit sequence-of-sequences: struct vs. string
View gist:2fbbd52a0dec25c1e14d1e69af3361ac
// To see if a rule whose attribute is sequence-of-sequence can make appends happen somehow
#include <string>
#include <vector>
#include <boost/spirit/include/qi.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
struct tiny {
std::string thing;
@jefftrull
jefftrull / test_ub.cpp
Created Mar 5, 2016
Simple test of signed overflow UB
View test_ub.cpp
#include <iostream>
#include <cstdint>
#include <limits>
int main(int argc, char **argv) {
std::int32_t i = std::numeric_limits<int32_t>::max();
i++; // signed overflow
if (i < 0) {
std::cerr << "i<0 and i=" << i << "\n"; // "expected" or "safe" result (-O1)
} else {
@jefftrull
jefftrull / as_string.cpp
Created May 18, 2015
Demonstration of apparent need for as_string when synthesizing a sequence of characters to a std::string
View as_string.cpp
#include <string>
#include <iostream>
#include <sstream>
#define BOOST_SPIRIT_USE_PHOENIX_V3
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix.hpp>
int main() {
You can’t perform that action at this time.