Skip to content

Instantly share code, notes, and snippets.

@carsonmcdonald
carsonmcdonald / revspdynpn.sh
Created April 27, 2011 14:52
How to set up ruby, eventmachine and spdy to use NPN
#
# Get development tools installed
#
sudo yum install -y git cvs zlib-devel
sudo yum groupinstall -y "Development Tools"
#
# Install RVM
#
bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)

From the standpoint of OSSL (Ruby’s OpenSSL binding), 1.9.3 is a small release; bug fixes, performance improvements, official OpenSSL 1.0.0 support and a few API enhancements. We had a new digital time-stamp and ASN.1 Template(DSL) implementation presented by Martin Boßlet, but we could not merge those bleeding-edge new features into 1.9.3, since there's no Ruby developer who can review it. It was quite obvious for us to ask him to be a maintainer of OSSL, as an expert in crypto and network security.

Since then, he helped us to clean up lots of OSSL issues piled on our issue tracker, by fixing SEGV bugs, consulting with users, and tailoring the build system to fit OpenSSL versions/variants. Though he discreetly didn’t merge his new feature implementations into 1.9.3, it seems clear that you can utilize those at the next release.

OSSL is the best language binding implementation of OpenSSL in the way of offering most OpenSSL features through an easy API with some help from Ruby. Without Martin Boßlet's help,

system ~/projects/jruby $ jruby --1.9 -rbenchmark -e "def foo(x, y, z); end; 5.times { puts Benchmark.measure { 1_000_000.times { foo(1, 2, 3) } } }"
0.117000 0.000000 0.117000 ( 0.117000)
0.092000 0.000000 0.092000 ( 0.092000)
0.089000 0.000000 0.089000 ( 0.089000)
0.090000 0.000000 0.090000 ( 0.090000)
0.089000 0.000000 0.089000 ( 0.089000)
system ~/projects/jruby $ jruby --1.9 -rbenchmark -e "def foo(x); end; 5.times { puts Benchmark.measure { 1_000_000.times { foo(a: 1, b: 2, c: 3) } } }"
0.385000 0.000000 0.385000 ( 0.385000)
0.357000 0.000000 0.357000 ( 0.357000)
require 'benchmark'
TIMES = 5000000
Benchmark.bmbm(40) do |x|
x.report('hoge[:fuga] = foo') do
hoge = {}
foo = :foo
TIMES.times do
hoge[:fuga] = foo
###
# Read in XML as a stream, write out JSON as a stream. As little information
# is kept in memory as possible.
require 'nokogiri'
require 'psych'
class JSONTranslator < Nokogiri::XML::SAX::Document
attr_reader :emitter
def initialize emitter
@headius
headius / gist:1354902
Created November 10, 2011 13:55
Red/black tree benchmark across Ruby impls
# MRI 1.9.3
system ~/projects/redblack $ rvm use ruby-1.9.3
Using /Users/headius/.rvm/gems/ruby-1.9.3-p0
ruby-1.9.3-p0 ~/projects/redblack $ ruby -I. bm1.rb 10
3.275654
GC.count = 7
3.271799
GC.count = 10
@authorNari
authorNari / gc-cow.rb
Created March 24, 2012 00:38 — forked from wr0ngway/gc-cow.rb
test to see if GC in ruby 2 is truly copy on write friendly
#!/usr/bin/env ruby
rss = '.+?Rss:\s+(\d+)'
share = '.+?Shared_Clean:\s+(\d+)'
share << '.+?Shared_Dirty:\s+(\d+)'
priv = '.+?Private_Clean:\s+(\d+)'
priv << '.+?Private_Dirty:\s+(\d+)'
MEM_REGEXP = /\[heap\]#{rss}#{share}#{priv}/m
def mem_usage()
@dchest
dchest / gist:4467707
Last active December 10, 2015 17:28
Cocoa HashDoS
#import <Foundation/Foundation.h>
NSString *collidingString() {
char rs[15];
for (int i = 0; i < 14; i++)
rs[i] = arc4random_uniform('Z'-'A') + 'A';
rs[14] = 0;
return [NSString stringWithFormat:@"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa%saaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa________________aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
rs];
@headius
headius / gist:4632203
Created January 25, 2013 06:31
Using Martin Bosslet's "krypt" library to support PKCS5. The future is now!
ext-jruby-local ~/projects/jruby $ jruby --2.0 --version
jruby 1.7.3.dev (2.0.0dev) 2013-01-24 0a82737 on Java HotSpot(TM) 64-Bit Server VM 1.6.0_37-b06-434-11M3909 [darwin-x86_64]
ext-jruby-local ~/projects/jruby $ jruby --2.0 ../ruby/test/openssl/test_pkcs5.rb
Run options:
# Running tests:
......