This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | :!tidy -mi -xml % | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | values = [1,3,4,4,4,4,4,10,12,15,18] | |
| bin_width = 5 | |
| ranges = 0.step((values.size/bin_width.to_f).ceil*bin_width, bin_width).each_cons(2).map { |s, e| Range.new(s, e, true) } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | require 'RMagick' | |
| $scale_size = 256.0 | |
| $img_fn1 = ARGV[0] | |
| $img_fn2 = ARGV[1] | |
| $scale_size = ARGV[2].to_f if ARGV[2] | |
| def calculate_threshold(img_fn) | |
| dir_name = File.dirname(img_fn) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | class Array | |
| def to_table_format | |
| return self unless self.grep(/\${image\d+}/).empty? | |
| cached_max = {} | |
| unless self[0].class == Array | |
| cached_max[0] = self.map(&:size).max | |
| else | |
| self[0].size.times.each do |i| | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | data = [{"weight"=>0, "id"=>8153, "text"=>"submits", "blank_id"=>"color1"}, {"weight"=>100, "id"=>3559, "text"=>"reveals", "blank_id"=>"color1"}, {"weight"=>0, "id"=>9458, "text"=>"launches", "blank_id"=>"color1"}, {"weight"=>0, "id"=>552, "text"=>"generates", "blank_id"=>"color1"}, {"weight"=>0, "id"=>2495, "text"=>"audience", "blank_id"=>"color2"}, {"weight"=>0, "id"=>8127, "text"=>"officials", "blank_id"=>"color2"}, {"weight"=>0, "id"=>8535, "text"=>"partners", "blank_id"=>"color2"}, {"weight"=>100, "id"=>6025, "text"=>"staff", "blank_id"=>"color2"}, {"weight"=>100, "id"=>2260, "text"=>"while", "blank_id"=>"color3"}, {"weight"=>0, "id"=>2920, "text"=>"because", "blank_id"=>"color3"}, {"weight"=>0, "id"=>4023, "text"=>"for", "blank_id"=>"color3"}, {"weight"=>0, "id"=>6816, "text"=>"although", "blank_id"=>"color3"}, {"weight"=>0, "id"=>113, "text"=>"exits", "blank_id"=>"color4"}, {"weight"=>100, "id"=>3528, "text"=>"shortages", "blank_id"=>"color4"}, {"weight"=>0, "id"=>1980, "text"=>"absences", "blank_id"=> | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | the simple way is | |
| require 'timeout' | |
| retries = 42 | |
| begin | |
| Timeout::timeout(s){ | |
| open('http://a.url.com') do |f| | |
| # ... stuff with f | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | class Numeric | |
| Alph = ("a".."z").to_a | |
| def alph | |
| s, q = "", self | |
| (q, r = (q - 1).divmod(26)) && s.prepend(Alph[r]) until q.zero? | |
| s | |
| end | |
| end | |
| 3.alph | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | brew install uchardet | |
| $uchardet your file | |
| #puts "UTF-8" | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #encoding image to base64 | |
| base64_str = Base64.encode64(File.open('Your_input_path'){|f| f.read}) | |
| #decoding base64 str to image file | |
| File.open('your_output_path', 'w') {|f| f.write(Base64.decode64(base64_str))} | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | =begin | |
| Message Pack vs similar utilities | |
| ruby 1.8.7 (2010-04-19 patchlevel 253) [i686-darwin10.0.0], MBARI 0x6770, Ruby Enterprise Edition 2010.02 | |
| Packing | |
| user system total real | |
| pack: bert 18.320000 0.770000 19.090000 ( 19.101583) | |
| pack: bson_ext 0.850000 0.030000 0.880000 ( 0.878398) | |
| pack: json_ext 2.540000 0.040000 2.580000 ( 2.582495) |