Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/ruby
# Test different image libraries (ImageScience/FreeImage versus MiniMagick/GraphicsMagick)
# usage : imglib_test image_file height width x_offset y_offset cropped_height cropped_width
# outputs the results of the benchmark
usage = "usage : imglib_test image_file height width x_offset y_offset cropped_height cropped_width"
# Make sure we have enough arguments passed to us
exit puts(usage) || 1 unless ARGV.size == 7
$ imglib_test Chicago_HDR_5_by_CloudINC00.jpg 900 1500 60 500 400 700
Rehearsal -------------------------------------------------
Image Science 1.910000 0.070000 1.980000 ( 1.986456)
MiniMagick 0.010000 0.030000 2.390000 ( 1.787434)
---------------------------------------- total: 4.370000sec
user system total real
Image Science 1.880000 0.060000 1.940000 ( 1.936208)
MiniMagick 0.010000 0.030000 2.400000 ( 1.702564)
#!/usr/bin/ruby
# A really rough multiple-grouping hash datastore proof-of-concept
module DBastard
end
# internal format: @objects = { :some_identifier => "some blob", :other_identifier => "other blob" }
class DBastard::ObjectStore
# This is where everything gets stored
def objects
@acook
acook / rails_helpers
Created November 16, 2010 23:23
Easy access Ruby on Rails aliases and functions
#!/bin/bash
# Put this file somewhere in your path then do `chmod +x rails_helpers` on it
# Put `source rails_helpers` in your ~/.bash_profile or .bashrc
# Type `rails_helpers ?` to get a quick look at the aliases and functions defined within
if [ $# -gt 0 ]; then
echo 'rails_helpers: rails CLI helpers by Anthony M. Cook 2010-2011'
echo "cat $(which $0) for more info."
echo ''
echo 'aliases:'
" search hilighting control, toggles, then enables intelligently
nnoremap / :set hlsearch<CR>/
nnoremap ? :set hlsearch<CR>?
nnoremap n :set hlsearch<CR>n
nnoremap N :set hlsearch<CR>N
nnoremap <CR> :noh<CR><CR>
nnoremap <leader>/ :set hlsearch!<CR>
" all this works, except the n/N after hlsearch has been toggled
@acook
acook / Gemfile
Created July 21, 2011 22:16
Only use certain gems in a Gemfile if they are already installed, otherwise ignore them.
# In some development environments, different developers have different needs
# and prefer to use different development gems. Now since Gemfiles are Just Ruby,
# it's pretty easy to work around the different environments.
####################################################################################
# to use:
# 1) put the following code into your Gemfile
# 2) change the `optional_development_gems` array to your custom list
# 3) install none, any, or all of the gems in that list
# 4) export custom_gems=enabled
# 5) bundle install
@acook
acook / gist:1169938
Created August 25, 2011 03:47
Output from install redcar
Precaching textmate bundles...
java -XstartOnFirstThread -d32 -client -Xbootclasspath/a:/Users/acook/.redcar/assets/jruby-complete-1.5.3.jar -Dfile.encoding=UTF8 -Xmx320m -Xss1024k -Djruby.memory.max=320m -Djruby.stack.max=1024k org.jruby.Main /Users/acook/.rvm/gems/ruby-1.9.2-p290/gems/redcar-0.11/bin/redcar --no-sub-jruby --ignore-stdin --no-gui --compute-textmate-cache-and-quit --multiple-instance --start-time=1314243239
2011-08-24 20:37:40.774 java[64239:ba03] *** __NSAutoreleaseNoPool(): Object 0x11099b0 of class NSCFString autoreleased with no pool in place - just leaking
2011-08-24 20:37:40.776 java[64239:ba03] *** __NSAutoreleaseNoPool(): Object 0x1e801110 of class NSCFNumber autoreleased with no pool in place - just leaking
2011-08-24 20:37:40.776 java[64239:ba03] *** __NSAutoreleaseNoPool(): Object 0x110a290 of class NSCFString autoreleased with no pool in place - just leaking
2011-08-24 20:37:40.806 java[64239:ba03] *** __NSAutoreleaseNoPool(): Object 0x11114e0 of class NSPathStore2 autoreleased wi
#
# = SuperStruct
#
# SuperStruct is an enhanced version of the Ruby Standard library <tt>Struct</tt>.
#
# Compared with the original version, it provides the following additional features:
# * ability to initialize an instance from Hash
# * ability to pass a block on creation
#
# You can read more at http://www.simonecarletti.com/blog/2010/01/ruby-superstruct/
@acook
acook / spec_helper.rb
Created August 26, 2011 12:23
A spec_helper to assist in testing executable file behaviour, assumes your Gemfile includes the Open4 gem.
require 'bundler'
Bundler.require(:test)
def run(*args)
output = Struct.new(:pid, :stdout, :stderr)
status = Open4.popen4(*args) do |pid, stdin, stdout, stderr|
output = output.new pid, stdout.read, stderr.read
end
@acook
acook / introspection.rb
Created September 2, 2011 22:20
Does a deep inspection of Ruby objects.
#
# You can do `Object.send :include, Introspection`
# Then you can call `.introspect` on anything.
#
# The `introspect` method returns a hash with information about the receiver
# including its Class, the Constants and instance_methods defined inside it.
#
# The "depth" parameter indicates how deeply it should inspect the object.
# By default there is no depth limit. Pass in 1 to just get info on the object itself.
#