Skip to content

Instantly share code, notes, and snippets.


Matt Aimonetti mattetti

View GitHub Profile
mattetti /
Created September 25, 2015 14:23 — forked from dwbuiten/

Problems & Solutions for Interaction Between C and Go

At Vimeo, on the transcoding team, we work a lot with Go, and a lot with C, for various tasks such as media ingest. This means we use CGO quite extensively, and consequently, have run into bits that are perhaps not very well documented, if at all. Below is my effort to document some of the problems we've run into, and how we fixed or worked around them.

Many of these are obviously wrong in retrospect, but hindsight is 20/20, and these problems do exist in many codebases currently.

Some are definitely ugly, and I much welcome better solutions! Tweet me at @daemon404 if you have any, or have your own CGO story/tips, please! I'd love to learn of them.

Table of Contents

mattetti / gist:4983273
Last active December 13, 2015 22:18 — forked from mrichie/gist:4043266
Add libyaml to the requirements (needed for Psych) Updated to use preview2
View gist:4983273
# First, make sure that you have the most recent rvm. Several bugs with 2.0.0-preview1 & preview 2
# have recently been fixed.
# Second, the openssl that comes with MacOS is too old for Ruby 2.0. You need to install
# a newer one with homebrew or the rvm pkg command.
# Option 1, with homebrew openssl:
brew update
brew install libyaml
mattetti /
Created October 11, 2012 18:23 — forked from burke/

Ruby 1.9.3-p194 with DTrace probes, Perf Patches, and backported COW-friendly GC


This script installs a patched version of ruby 1.9.3-p194 with DTrace probes, boot-time performance improvements (#66 and #68), and runtime performance improvements (#83 and #84). It also includes the new backported GC from ruby-trunk.

Many thanks to funny-falcon for the performance patches and to Aaron Patterson for the DTrace instrumentation.

mattetti / htmlbench.rb
Created January 11, 2012 20:12 — forked from tarcieri/results
Compare Nokogiri on JRuby (Apache Xerces) with 1.9.3 (libxml2)
View htmlbench.rb
require 'rubygems'
require 'nokogiri'
require 'benchmark'
text = "<html><body><h1>Mr. Belvedere Fan Club</h1></body></html>""xmlbench.xml")
(ARGV[0] || 5).to_i.times do
puts Benchmark.measure { 100_000.times { Nokogiri::HTML(text) }}
mattetti / results
Created January 11, 2012 17:28 — forked from headius/results
Compare Nokogiri on JRuby (Apache Xerces) with 1.9.3 (libxml2)
View results
$ jruby -v xmlbench.rb
jruby 1.6.5 (ruby-1.8.7-p330) (2011-10-25 9dcd388) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_29) [darwin-x86_64-java]
/Users/mattetti/.rvm/gems/jruby-1.6.5/gems/nokogiri-1.5.0-java/lib/nokogiri/css.rb:3 warning: global variable `$-w' not initialized
3.455000 0.000000 3.455000 ( 3.455000)
2.074000 0.000000 2.074000 ( 2.074000)
1.601000 0.000000 1.601000 ( 1.601000)
1.614000 0.000000 1.614000 ( 1.614000)
1.602000 0.000000 1.602000 ( 1.602000)
$ ruby -v xmlbench.rb
mattetti / face_detector.rb
Created December 1, 2011 15:11 — forked from seanlilmateus/gist:1386468
Macruby Face Detection in Mac OS X Lion. Usage: $ macruby face_detector.rb or $ macruby face_detector.rb image_url
View face_detector.rb
framework 'Cocoa'
class NSColor
def toCGColor
color_RGB = colorUsingColorSpaceName(NSCalibratedRGBColorSpace)
## approach #1
# components ={}
# color_RGB.getRed(components[0],
# green: components[1],
# blue: components[2],
mattetti / gist:1328307
Created October 31, 2011 18:18 — forked from etdebruin/gist:1328122
View gist:1328307
module Dog
def species
p "I'm a dog"
def race
p "I'm a #{}"
# To implement in the interface implementation
View gist:1300226
ruby-1.9.2-p290 :009 > r = Record.where(:e => "x")
Record Load (42.8ms) SELECT "records".* FROM "records" WHERE "records"."e" = 'x'
=> []
ruby-1.9.2-p290 :010 > r.class
=> ActiveRecord::Relation
ruby-1.9.2-p290 :011 > r.where(:c => "y")
Record Load (41.3ms) SELECT "records".* FROM "records" WHERE "records"."e" = 'x' AND "records"."c" = 'y'
=> []
ruby-1.9.2-p290 :012 >
View StreamCampaign.rb
require 'pp'
require 'tweetstream'
require "hiredis"
require "redis/connection/hiredis"
require 'redis'
# Just so I can run without your rails stack
unless $redis
$redis = => "", :port => 6379)
View benchmark.rb
#!/usr/bin/env ruby
require 'benchmark'
require 'rubygems'
gem 'therubyracer'
gem 'haml'
gem 'tilt'
require 'v8'
require 'haml'