Wednesday, June 11, 2014

Standard Lib research

big decimal, cmath, coverage, benchmark, csv, cgi, abbrev, base64, curses





bigDemimal
  Size C
  http://makandracards.com/makandra/1178-bigdecimal-arithmetic-in-ruby
  http://raveendran.wordpress.com/2012/01/24/ruby-big-decimal-sample-usage/
require 'bigdecimal'

float_integer_plain = 400.56 - 400

float_integer_bigdecimal = BigDecimal("400.56") - BigDecimal("400")

#-----------------------------------
print "$"
puts float_integer_plain

print "$"
puts float_integer_bigdecimal.to_f

When it is run:
$0.5600000000000023
$0.56

cmath
  Size C

coverage
  Size A



benchmark
  Size B

csv 
  Size C
  comma separated value
  http://www.sitepoint.com/guide-ruby-csv-library-part/

cgi 
  Size C
http://ruby-doc.org/stdlib-2.1.0/libdoc/cgi/rdoc/CGI.htmlThe Common Gateway Interface (CGI) is a simple protocol for passing an HTTP request from a web server to a standalone program, and returning the output to the web browser.
Basically, a CGI program is called with the parameters of the request passed in either in the environment (GET) or via $stdin (POST), and everything it prints to $stdout is returned to the client.



abbrev
  Size A

base64
  Size A
How to save a base64 string as an image using ruby 
The best approach is to specify the correct flag on the open call:
File.open('shipping_label.gif', 'wb') do|f|
  f.write(Base64.decode64(base_64_encoded_data))
end 


http://stackoverflow.com/questions/201479/what-is-base-64-encoding-used-for/201510#201510 

"When you have some binary data that you want to ship across a network, you generally don't do it by just streaming the bits and bytes over the wire in a raw format. Why? because some media are made for streaming text. You never know -- some protocols may interpret your binary data as control characters (like a modem), or your binary data could be screwed up because the underlying protocol might think that you've entered a special character combination (like how FTP translates line endings).

So to get around this, people encode the binary data into characters. Base64 is one of these types of encodings. Why 64? Because you can generally rely on the same 64 characters being present in many character sets, and you can be reasonably confident that your data's going to end up on the other side of the wire uncorrupted."

 curses (It is deprecated - only works in ruby 2.0.0 right now)
  Size C
  http://www.ruby-doc.org/stdlib-2.0/libdoc/curses/rdoc/Curses.html
  cursor actions
  Curses::Window - class with the means to draw a window or box
  Curses::MouseEvent - class for collecting mouse events

  ncurses http://www.tldp.org/HOWTO/NCURSES-Programming-HOWTO/index.html

No comments:

Post a Comment