Skip to content

Instantly share code, notes, and snippets.

View srawlins's full-sized avatar

Sam Rawlins srawlins

View GitHub Profile
# The Computer Language Benchmarks Game
# http://shootout.alioth.debian.org/
# transliterated from Mario Pernici's Python program
# contributed by Rick Branson
# made 'functional' by Sam Rawlins
require "rubygems"
require "gmp"
@srawlins
srawlins / gist:704017
Created November 17, 2010 20:29
bug in GMP gem
ruby-1.9.1-p378 > g_one = GMP::Z(1)
=> 1
ruby-1.9.1-p378 > a = b = GMP::Z(0)
=> 0
ruby-1.9.1-p378 > a += g_one
=> 1
ruby-1.9.1-p378 > a
=> 1
ruby-1.9.1-p378 > b
=> 0
@srawlins
srawlins / gist:706859
Created November 19, 2010 17:52
rbx: Bignum#<=> doesn't do something right... coersion?
In ruby-1.8.7
C:\sam>irb
irb(main):001:0> class A
irb(main):002:1> @a
irb(main):003:1> def initialize(a)
irb(main):004:2> @a=a
irb(main):005:2> end
irb(main):006:1> def coerce(other)
irb(main):007:2> if other.is_a? Integer
C:\sam\code\rubinius>rake
(in C:/sam/code/rubinius)
Unable to build using the running Ruby executable.
To resolve this issue:
* Use 'C:/Ruby191/bin/ruby.exe.exe' to build.
@srawlins
srawlins / gist:879943
Created March 21, 2011 18:34
CC=/usr/local/gcc-4.4.5/bin/gcc rvm install --trace 1.9.2-gcc_4.4.5
craig:~ sam$ CC=/usr/local/gcc-4.4.5/bin/gcc rvm install --trace 1.9.2-gcc_4.4.5
--trace 1.9.2-gcc_4.4.5
rvm 1.2.9 by Wayne E. Seguin ([email protected]) [http://rvm.beginrescueend.com/]
+ [[ -z '' ]]
+ export 'PS4=+[${BASH_SOURCE}] : ${LINENO} : ${FUNCNAME[0]:+${FUNCNAME[0]}() $ }'
+ PS4='+[${BASH_SOURCE}] : ${LINENO} : ${FUNCNAME[0]:+${FUNCNAME[0]}() $ }'
+[/Users/sam/.rvm/scripts/cli] : 705 : __rvm_parse_args() $ [[ -z install ]]
+[/Users/sam/.rvm/scripts/cli] : 707 : __rvm_parse_args() $ [[ 0 -eq 1 ]]
@srawlins
srawlins / ruby-1.9.2_bignum.html
Created May 31, 2011 17:55
Ruby 1.9.2 Bignum performance, when compiled with different GCCs
<html>
<head>
<script type='text/javascript' src='https://www.google.com/jsapi'></script>
<script type='text/javascript'>
google.load('visualization', '1', {packages:['corechart']});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data_bench_right_shift = new google.visualization.DataTable();
data_bench_right_shift.addColumn('string', 'Bench');
data_bench_right_shift.addColumn('number', 'ruby-1.9.2-p180-gcc460');
@srawlins
srawlins / mem_install_kc.rb
Created March 22, 2012 22:36
quick binary for creating MEM jira tickets
require './rebase-or-no/lib/kjira4r'
release = ARGV.shift
env = ARGV.shift
j = KJira4R.new(USER, PASS)
mem8928 = j.getIssue("MEM-8928") # A standard "Install KC x on KC y" ticket
new_issue = mem8928.dup # Cloning for ease in custom fields, components, etc.
new_issue.created=nil
@srawlins
srawlins / tomcat-context-FAIL
Created April 12, 2012 23:20
tocmat context fail startup KFS 3.0
Apr 12, 2012 3:55:57 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/amd64/server:/usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/amd64:/usr/lib/jvm/java-6-sun-1.6.0.26/jre/../lib/amd64:/opt/oracle/instantclient_11_2:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
Apr 12, 2012 3:55:58 PM org.apache.coyote.http11.Http11BaseProtocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Apr 12, 2012 3:55:58 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 564 ms
Apr 12, 2012 3:55:58 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Apr 12, 2012 3:55:58 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/5.5.16
@srawlins
srawlins / adhoc-fyi.rb
Created September 13, 2012 01:15
Automated Ad Hoc Router for Kuali Coeus
require 'rubygems'
require 'capybara'
require 'capybara/dsl'
require 'highline/import'
require 'uri'
class AdHoccer
include Capybara::DSL
def initialize(url, recipient)
@srawlins
srawlins / commaize.rb
Created February 28, 2013 01:09
Method chaining can still _be_ magical, and not have to _look_ like magic.
number = 1234567
# Chaining methods more than once-ish is confusing; the developer has to keep
# in mind wtf is going on:
number.to_s.reverse.split(//).each_slice(3).map(&:join).join(',').reverse
# Commenting the state of each chain helps:
number.to_s. # String, e.g. "1234567"
reverse. # reverse it, e.g. "7654321"
split(//). # split on every character, e.g. ["7", "6", "5", "4", "3", "2", "1"]