Tuesday, April 12, 2011

SHARE - Client OS Detection

    <%= request.env['HTTP_USER_AGENT'] %>
    <%= request.env['HTTP_USER_AGENT'] =~ /Linux/ %>
    <%= request.env['HTTP_USER_AGENT'] =~ /Windows/ %>
    <%= request.env['HTTP_USER_AGENT'] =~ /Mac/ %>
    <%= request.env['HTTP_USER_AGENT'] =~ /iPhone/ %>

SHARE - How to get mp3 information (id3v1 and id3v2 tags) using ruby-mp3info

how to install gem
    gem install ruby-mp3info
how to use
    require "mp3info"
    begin
      mp3=Mp3Info.open(file_full_path)
      mp3.tag.title
      puts mp3.tag.artist  
      puts mp3.tag.album
    rescue Exception => e
      puts e.inspect
    end
for more information you can see here
http://ruby-mp3info.rubyforge.org/

SHARE - How to get image information using RMagick

    require 'RMagick'
    include Magick
    begin
      image=Image.read(pic_full_path).first
      image.filename #filename
      image.filesize #filesize
      image.columns #width
      image.page.width #width
      image.rows #height
      image.page.height #height
    rescue Exception => e
      puts e.inspect
    end