Skip to content

Instantly share code, notes, and snippets.

@abscondment
abscondment / bench_jruby-1.7.0.txt
Created November 28, 2012 21:48
Stupid benchmark for various max methods
brendan@flask:~$ ruby -v
jruby 1.7.0 (1.9.3p203) 2012-10-22 ff1ebbe on Java HotSpot(TM) 64-Bit Server VM 1.6.0_37-b06-434-11M3909 [darwin-x86_64]
brendan@flask:~$ ruby max.rb
user system total real
[].max 3.690000 0.170000 3.860000 ( 3.004000)
proc 3.280000 0.170000 3.450000 ( 2.699000)
Math.max 0.850000 0.020000 0.870000 ( 0.783000)
if/else 0.680000 0.030000 0.710000 ( 0.671000)
user system total real
vagrant@precise:/vagrant/paperkarma/server$ sudo gem install pg
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/usr/bin/ruby1.9.3 extconf.rb
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
--with-pg-config=/path/to/pg_config
checking for libpq-fe.h... no
sudo apt-get install libcurl4-openssl-dev libexpat1-dev libgcrypt11-dev
tar xvzf clamz-0.5.tar.gz
cd clamz-0.5
./configure
make
sudo checkinstall -D -y --fstrans=no --nodoc --pkgname='clamz' --pkgversion='0.5' --provides='clamz' --requires='libcurl4-openssl-dev,libexpat1-dev,libgcrypt11-dev' --maintainer='brendan.ribera@gmail.com'
@abscondment
abscondment / alphanumerics.clj
Created December 20, 2011 00:58
Monkeying around with numbers.
(ns alphanumerics)
(use 'clojure.math.numeric-tower)
(defn to-alphabet [number alphabet-str]
(let [alpha (vec alphabet-str)
base (count alpha)]
(loop [result (list)
quotient number]
(if (zero? quotient)
(if (empty? result) "0"
import java.io.InputStream
import java.io.InputStreamReader
import java.io.IOException
class Test
# take an InputStream, return a String
def inputstream_to_string(is:InputStream)
buffer = char[0x10000]
out = StringBuilder.new
inreader = InputStreamReader.new(is, "UTF-8")
@abscondment
abscondment / fallacy.md
Created November 15, 2011 23:58
Spot the Fallacy

Spot the Fallacy

From the Rails core mailing list:

> But point releases (e.g. 3.1.x) don't add features or change too much code, they just try to have bugfixes. Bugs are fixed by adding a failing test and making it pass, while ensuring the rest of the test suite passes too. This means each point release has less bugs than the previous one. Upgrading to the newest bugfix release is quick, safe, and should be done as often as possible.

// Generated from Test.mirah
public class Test extends java.lang.Object {
public static void main(java.lang.String[] argv) {
new Test();
}
public java.lang.String baz_method() {
return "baz";
}
public Test() {
java.lang.String bar = null;
#!/bin/sh
cd $HOME/code/jruby
ant clean
ant jar-complete
cd $HOME/code/bitescript
rvm use system
yes | $HOME/code/jruby/bin/jruby -S gem uninstall bitescript
$HOME/code/jruby/bin/jruby -S gem build bitescript.gemspec
@abscondment
abscondment / gist:1099761
Created July 22, 2011 16:16
phash notes
# ruby-1.9.2-p180 :001 > require 'mini_magick'
# => true
# ruby-1.9.2-p180 :002 > i = MiniMagick::Image.open('sample.jpg')
# => #<MiniMagick::Image:0x000000015bc448 @path="/tmp/mini_magick20110721-11512-ru54lb.jpg", @tempfile=#<File:/tmp/mini_magick20110721-11512-ru54lb.jpg (closed)>>
# ruby-1.9.2-p180 :003 > i.resize '8x8'
# => ""
# ruby-1.9.2-p180 :004 > i.type 'Grayscale'
# => ""
# ruby-1.9.2-p180 :005 > i.write 'out.jpg'
vagrant@dev:/vagrant/server$ gem -v
1.8.3
vagrant@dev:/vagrant/server$ bundle -v
Bundler version 1.0.13
vagrant@dev:/vagrant/server$ bundle install
Fetching https://github.com/mongoid/mongoid.git
remote: Counting objects: 26697, done.
remote: Compressing objects: 100% (10246/10246), done.
remote: Total 26697 (delta 16810), reused 24542 (delta 14889)
Receiving objects: 100% (26697/26697), 3.25 MiB | 691 KiB/s, done.