Skip to content

Instantly share code, notes, and snippets.

class Cell < ActiveRecord::Base
composed_of :extent, :class_name => "Vector", :mapping => %w(extent_x extent_y extent_z), :constructor => Proc.new { |x,y,z| Vector.elements([x, y, z]) }
def as_json(options={})
{:name => self.name, :id => self.id, :extent => [self.extent_x, self.extent_y, self.extent_z]}
end
end
@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 / 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 / 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 / debug_pass_nondebug_fail.cpp
Created April 6, 2012 03:09
Testcase for BOOST_SPIRIT_DEBUG changing lexer/parser behavior
#include <sstream>
#include <iostream>
#include <boost/spirit/include/lex_lexertl.hpp>
#include <boost/spirit/include/lex_lexertl_position_token.hpp>
#include <boost/spirit/include/support_istream_iterator.hpp>
// if this gets defined, my parse passes and all input is consumed
// #define BOOST_SPIRIT_DEBUG
// if it is not defined, my parse passes but not all input is consumed
@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
@jefftrull
jefftrull / coupling_odeint.cpp
Created May 25, 2012 18:40
VLSI signal coupling analysis with odeint
// Test of odeint using intersignal coupling
// Jeff Trull <edaskel@att.net> 2012-05-16
#include <vector>
using namespace std;
#include <boost/numeric/odeint.hpp>
using namespace boost::numeric;
typedef vector<double> state_type;
@jefftrull
jefftrull / coupling.cir
Created May 25, 2012 18:42
Basic signal integrity test case
.title NGSpice coupling simulation circuit for comparison with odeint
* by Jeff Trull <edaskel@att.net> 2012-05-25
*** passive subcircuit module representing the driver impedances, traces, and receiver loads
*** (leaves input voltages to caller)
.subckt coupling_testcase aggdrv vicdrv aggrcv vicrcv gnd
+ raggdrv=100 ragg1=1k cagg1=100f ragg2=1k cagg2=100f caggl=20f
+ rvicdrv=100 rvic1=1k cvic1=100f rvic2=1k cvic2=100f cvicl=20f
+ ccoup=100f
@jefftrull
jefftrull / gist:3178642
Created July 25, 2012 20:58
accessing all values from a map when stored objects are non-copyable
#include <iostream>
#include <memory>
#include <boost/thread.hpp>
#include <thread>
#include <map>
#include <vector>
typedef std::map<std::size_t, boost::thread> ThreadContainer;
// this one produces the same error:
// typedef std::vector<std::pair<std::size_t, boost::thread> > ThreadContainer;
@jefftrull
jefftrull / gist:3441824
Created August 23, 2012 21:12
Exploring class specialization, member function specialization, and overloading; and how they interact
// experiments for varying class member function behavior with
// class template args, member template args, and member function overloads
// Jeff Trull 2012-08-23
#include <string>
#include <iostream>
template<typename T>
struct Foo {