Skip to content

Instantly share code, notes, and snippets.

@noelwarr
noelwarr / ruby_decorators.rb
Last active August 29, 2015 13:56
Ruby Decorators
class Object
def self.method_added(m)
super(m)
if @wrap_method
@wrap_method = nil
a = "__#{m}__".to_sym
alias_method a, m
define_method(m){
begin
@noelwarr
noelwarr / gist:6887398
Created October 8, 2013 16:28
CGAL and Ruby not playing nice together
//hello_world.cpp
//The following DOESN'T compile
#include <ruby.h>
#include <boost/shared_ptr.hpp>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Polygon_2.h>
#include <CGAL/create_straight_skeleton_2.h> //ADDING THIS CAUSES COMPILATION TO FAIL
@noelwarr
noelwarr / needle.rb
Last active December 17, 2015 09:58
Parrallel processing for ruby
# Use needle by telling it how many cpus you want to use
# and what you want it to do.
# Then just feed it data and watch all your cores go crazy.
# You can feed it standard ruby objects and it will return all
# results in the same order you gave them to it.
# n = Needle.new(cpus) {|input| input.do_something }
# result_of_all = n.sew[a,b,c,d,e,f,g,h,i...]
# uncomment the lines at the bottom to run the test
@noelwarr
noelwarr / Stitcher.rb
Created May 14, 2013 10:42
Stitch cavities in meshes in SketchUp
class DynameshTool
def initialize
end
def sort_vertices(v1,v2,orientation,direction,view)
coords = [v1,v2].collect{|v|
pos = view.screen_coords(v.position)
case orientation
when :horizontal then pos[0]
when :vertical then pos[1]
@noelwarr
noelwarr / gist:5517957
Last active December 16, 2015 23:59
Nester nests a module or class into another module.
class Nester
def initialize
@checklist = []
end
def nest(source, target, source_sym = nil)
if source.is_a?(Module)
source_sym = source.name.split("::").last.to_sym if source_sym.nil?
if source.is_a?(Class)
kls = source.clone
@noelwarr
noelwarr / slicer.rb
Created December 6, 2012 22:20
A simple class for slicing polyhedral structures into polygon points
#Slicer takes a polyhedron and slices it accross the xy plane
#at a given interval. It uses a technique called vertex shifting
#to avoid planes intercepting vertices and edges.
#It has only been tested on triangulated manifold volumes.
class Slicer
#Specify the starting and finishing values for the z axis
#Optionally specify how often to perform the slice
def initialize(z_from, z_to, z_step = 0.5)