Skip to content

Instantly share code, notes, and snippets.

View mattetti's full-sized avatar

Matt Aimonetti mattetti

View GitHub Profile
@mattetti
mattetti / CGO.md
Created September 25, 2015 14:23 — forked from dwbuiten/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 December 13, 2015 22:18 — forked from mrichie/gist:4043266
Add libyaml to the requirements (needed for Psych) Updated to use preview2
# 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
mattetti / 0-readme.md
Created October 11, 2012 18:23 — forked from burke/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 January 11, 2012 20:12 — forked from tarcieri/results
Compare Nokogiri on JRuby (Apache Xerces) with 1.9.3 (libxml2)
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 January 11, 2012 17:28 — forked from headius/results
Compare Nokogiri on JRuby (Apache Xerces) with 1.9.3 (libxml2)
$ 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 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
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],
@mattetti
mattetti / gist:1328307
Created October 31, 2011 18:18 — forked from etdebruin/gist:1328122
Interfacing
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
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 >
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)
#!/usr/bin/env ruby
require 'benchmark'
require 'rubygems'
gem 'therubyracer'
gem 'haml'
gem 'tilt'
require 'v8'
require 'haml'