Skip to content

Instantly share code, notes, and snippets.

View headius's full-sized avatar

Charles Oliver Nutter headius

View GitHub Profile
@headius
headius / not_ugly_test.rb
Created April 10, 2012 04:18 — forked from funny-falcon/not_ugly_test.rb
uglier is sometimes faster
#!/usr/bin/env ruby
require 'yaml'
y=[]
(1..10000).each{|x|
#next unless x/2==(1.0*x)/2
z=x
divisors=[1]
_continue=true
# gem install benchmark_suite
require 'benchmark/ips'
class Foo1
def foo
"bar"
end
def foo_call
foo
class Foo
def initialize
@var = 0
# pad the variables apart to try to force them onto different cache lines
32.times do |i|
eval "@pad#{i} = nil"
end
@updated = false
end
@headius
headius / gist:1138026
Created August 10, 2011 19:59 — forked from anonymous/gist:1137946
JRuby versus Java impls of fib(35), both using RubyFixnum objects
# Java impl of fib, statically typed but still using RubyFixnum objects
headius@headius-desktop:~/projects/jruby$ ~/hsx-hotspot/build/linux/jdk-linux-i586/bin/java -server -cp lib/jruby.jar:build/classes/test/ org.jruby.test.bench.BenchFixnumFibRecursive
Took 936ms for boxedFib(35) = 9227465
Took 847ms for boxedFib(35) = 9227465
Took 905ms for boxedFib(35) = 9227465
Took 943ms for boxedFib(35) = 9227465
Took 873ms for boxedFib(35) = 9227465
# Ruby impl of fib. The 20% different from Java is optimization opportunities in JRuby and invokedynamic, but we're very close to Java perf here.
@headius
headius / gist:1125369
Created August 4, 2011 15:03 — forked from joelash/gist:1125362
jruby-1.6.3 Digest#file bug when run with JRUBY_OPTS=--1.9
require 'pathname'
require 'digest'
`touch foo.txt`
path = Pathname.new 'foo.txt'
digest = Digest::MD5.new # digest type doesn't matter, see same problem with SHA1
# digest.file path # this line throws an error when have JRUBY_OPTS=--1.9
@headius
headius / gist:707061
Created November 19, 2010 20:02 — forked from evanphx/gist:663404
#!/usr/bin/env ruby
=begin
INSTALL:
curl http://github.com/defunkt/gist/raw/master/gist.rb > gist &&
chmod 755 gist &&
sudo mv gist /usr/local/bin/gist

Installing libxml2 with NestedVM

Prequisites

curl

darcs

Install NestedVM

First, install NestedVM:

String.metaClass.methodMissing { String name, args ->
String camel = ''
name.split('_').eachWithIndex { part, i ->
if (i == 0) camel += part
else camel += (part[0].toUpperCase() + part[1..-1])
}
delegate."$camel"(args)
}
@headius
headius / pickjdk.sh
Last active August 30, 2015 13:15 — forked from nicksieger/pickjdk.sh
JDK picker for OS X.
#!/bin/bash
#
# Provides a function that allows you to choose a JDK. Just set the environment
# variable JDKS_ROOT to the directory containing multiple versions of the JDK
# and the function will prompt you to select one. JAVA_HOME and PATH will be cleaned
# up and set appropriately.
# Usage:
# Include in .profile or .bashrc or source at login to get 'pickjdk' command.
# 'pickjdk' alone to bring up a menu of installed JDKs on OS X. Select one.
class ChunkedArray
def initialize(bucket_size = 500)
@array, @bucket_size = [[]], bucket_size
end
def push(item)
if !@array.last || @array.last.size == @bucket_size
@array << []
end
@array.last << item