Skip to content

Instantly share code, notes, and snippets.

Avatar

Matt Aimonetti mattetti

View GitHub Profile
View CGO.md

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
mattetti / gist:4983273
Last active Dec 13, 2015 — 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
View 0-readme.md

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

Overview

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
mattetti / htmlbench.rb
Created Jan 11, 2012 — 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>" #File.read("xmlbench.xml")
(ARGV[0] || 5).to_i.times do
puts Benchmark.measure { 100_000.times { Nokogiri::HTML(text) }}
end
@mattetti
mattetti / results
Created Jan 11, 2012 — 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
mattetti / face_detector.rb
Created Dec 1, 2011 — 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 = Array.new(4){Pointer.new(:double)}
# color_RGB.getRed(components[0],
# green: components[1],
# blue: components[2],
View gist:1328307
module Dog
def species
p "I'm a dog"
end
def race
p "I'm a #{self.class.name}"
end
# 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 = Redis.new(:host => "127.0.0.1", :port => 6379)
View benchmark.rb
#!/usr/bin/env ruby
require 'benchmark'
require 'rubygems'
gem 'therubyracer'
gem 'haml'
gem 'tilt'
require 'v8'
require 'haml'