Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Gyoung-Yoon Noh

« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS 

Resizing images using RMagick

require 'rubygems'
require 'RMagick'

include Magick

def append_filename(filename, suffix)
  extrac = filename.split('.')
  extrac[-2] += suffix
  extrac.join('.')
end                                                                                  
ARGV.each do |f|
  ImageList.new(f).resize(800, 600).write(append_filename(f, '_l'))
  ImageList.new(f).resize(400, 300).write(append_filename(f, '_m'))
  ImageList.new(f).resize(40, 30).write(append_filename(f, '_s'))
end

Using glade interface file in ruby-gnome2.

require 'gtk2'
require 'libglade2'

class SignalHandler
  def method_missing(method, *args)
    puts "#{method}: #{args}"
  end
end
sigmap = SignalHandler.new

Gtk.init
glade = GladeXML.new('hello.glade', nil, 'helloglade')
window = glade['main_window']
window.signal_connect("destroy") { Gtk.main_quit }
glade.signal_autoconnect_full do |source, target, signal, handler, data|
  source.signal_connect(signal) { sigmap.send(handler, data) }
end

window.show
Gtk.main


I did not know what file should I require. :(

How to display message when collection is empty

>> for i in [1]
>>   puts i
>> end.any? or puts "empty!"
1
=> true
>> for i in [ ]
>>   puts i
>> end.any? or puts "empty!"
empty!
=> nil


short circuit evaluation is not intutitive? try this.

>> class Array
>>   alias :__empty? :empty?
>>   def empty?
>>     yield if __empty? and block_given?
>>     __empty?
>>   end
>> end
=> nil
>> for i in [1]
>>   puts i
>> end.empty? { puts "empty!" }
1
=> false
>> for i in [ ]
>>   puts i
>> end.empty? { puts "empty!" }
empty!
=> true
« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS