Skip to content

Instantly share code, notes, and snippets.

@jefftrull
jefftrull / main.cpp
Created October 22, 2011 02:00
Example of embedding Ruby interpreter into C/C++ program
// very basic embedded Ruby interpreter for C++ programs
// thrown together by Jeff Trull <jetrull@sbcglobal.net> based on googling and asking questions on #ruby-lang
#include <ruby.h>
// access to C variables
static VALUE getter(VALUE ns, VALUE var) {
return Qfalse;
}
VALUE setter(VALUE ns, VALUE var, VALUE val) {
@jefftrull
jefftrull / gist:9d890f6fb67873351d16fb709e9811b2
Last active April 14, 2021 17:50
long double Boost Python conversion assembly output
.section .text._Z11extract_fooIeET_N5boost6python3api6objectE,"axG",@progbits,long double extract_foo<long double>(boost::python::api::object),comdat
.p2align 4
.weak long double extract_foo<long double>(boost::python::api::object)
.type long double extract_foo<long double>(boost::python::api::object), @function
long double extract_foo<long double>(boost::python::api::object):
.LFB10151:
.cfi_startproc
.cfi_personality 0x9b,DW.ref.__gxx_personality_v0
.cfi_lsda 0x1b,.LLSDA10151
endbr64
@jefftrull
jefftrull / gist:fc577f994cc613d5f371bad0ca618d26
Created August 12, 2020 01:42
telling clangd where to find my compile_commands.json
(setq lsp-clients-clangd-args
(list (concat "--compile-commands-dir="
(projectile-project-root)
"build")
"--log=verbose"
"-j=1"
"--debug"
"--clang-tidy"
"--background-index")))
@jefftrull
jefftrull / main.cpp
Created January 9, 2012 09:53
Example of producer-consumer for Ruby interpreter with separate thread in C++
// Example of running Ruby in a separate thread
// 2012-01-08 by Jeff Trull <jetrull@sbcglobal.net>
#include <iostream>
#include <queue>
#include <string>
#include <set>
#include <boost/thread.hpp>
#include <boost/thread/mutex.hpp>
@jefftrull
jefftrull / gist:5625b77c0f86c439f29f
Created August 15, 2014 06:05
Replacement for harmonic_oscillator.cpp with Eigen Matrix as state type and necessary changes made
/*
Copyright 2010-2012 Karsten Ahnert
Copyright 2011-2013 Mario Mulansky
Copyright 2013 Pascal Germroth
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or
copy at http://www.boost.org/LICENSE_1_0.txt)
*/
@jefftrull
jefftrull / error_testcase.cpp
Last active October 28, 2019 13:25
testcase for useful expectation failure error messages when using spirit::lex
// testcase for nice error messages in lexer-based parser
#define BOOST_SPIRIT_USE_PHOENIX_V3
#include <iostream>
#include <sstream>
#include <boost/spirit/include/phoenix.hpp>
#include <boost/spirit/include/lex_lexertl.hpp>
#include <boost/spirit/include/lex_lexertl_position_token.hpp>
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/support_istream_iterator.hpp>
@jefftrull
jefftrull / tangle.org
Created July 28, 2019 20:41
org-babel demo from Emacs SF meetup 2019-07-24

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)))

Testing C++ tangling from org-mode

@jefftrull
jefftrull / js_spirit2.cpp
Created April 8, 2012 00:49
Attempted solution to "Boost Spirit vs. Flex/Bison" comparison
// Attempt at making a Boost grammar that successfully parses Jason Shankel's predicate logic language
// #define BOOST_SPIRIT_DEBUG
#include <boost/spirit/include/qi.hpp>
#include <boost/variant/recursive_variant.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
#include <boost/spirit/include/phoenix.hpp>
#include <boost/optional.hpp>
// start with the AST
// 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);