]]>http://ivanhq.net/2012/02/15/spotfav-webcams-y-weather-reporting/feed/4Ivan++http://ivanhq.net/2011/12/27/ivan-2/
http://ivanhq.net/2011/12/27/ivan-2/#commentsTue, 27 Dec 2011 00:37:16 +0000http://ivanhq.net/?p=593ivan.age = 33
]]>http://ivanhq.net/2011/12/27/ivan-2/feed/3A motion-jpeg stream with Ruby and Sinatrahttp://ivanhq.net/2011/11/30/a-motion-jpeg-stream-with-ruby-and-sinatra/
http://ivanhq.net/2011/11/30/a-motion-jpeg-stream-with-ruby-and-sinatra/#commentsWed, 30 Nov 2011 11:37:57 +0000http://ivanhq.net/?p=584Continue reading A motion-jpeg stream with Ruby and Sinatra]]>I’ve been trying to set up a Motion-JPEG streaming with ruby, for a webcam which uploads a picture per second to a server. I want new images to be served via streaming instead of making the browser call them every second via a javascript call.

I found many different solutions, some of them including EventMachine, which now is not necessary thanks to the new Sinatra 1.3 streaming feature.
The tricky part was related to the headers, the boundary, and the need to send the content type before each image.

For the test I first created a directory and stored some pictures inside

## ... or get the newest image## In this case I'm not taking the latest file ## uploaded by the camera, but the previous one.## This is to avoid grabbing a currently uploading ## file, which may be shown as corrupt or incomplete.##def latest_file(dir)
files = Dir.entries(dir).collect{|file| file }.sort{|file2,file1|File.mtime(dir+file1)<=>File.mtime(dir+file2)}
files -= ['.', '..']
files[1]end

Then simply create a Gemfile including Sinatra and Thin, as WebRick is not evented and does not support this kind of stream.

]]>http://ivanhq.net/2011/08/27/el-banco-sabadell-y-el-comercio-electronico-inseguro/feed/0Facebook apps, auto-resize and scroll to tophttp://ivanhq.net/2011/07/04/facebook-apps-auto-resize-and-scroll-to-top/
http://ivanhq.net/2011/07/04/facebook-apps-auto-resize-and-scroll-to-top/#commentsMon, 04 Jul 2011 20:47:21 +0000http://ivanhq.net/?p=567Continue reading Facebook apps, auto-resize and scroll to top]]>Have you ever written a Facebook application?
One of the most common problems for iframe apps is making canvas auto-resize. It’s solved this way:

Place this snippet after the body tag, and set your application (at facebook developers config center) to be auto-resizable. And that’s it!

Other common problem is how to make window scroll up when you click on a link. Usually the page renders but leaves you at the same vertical position you were before clicking.
If you are suffering this and you are using jquery, you can solve it this way:

]]>http://ivanhq.net/2011/04/20/comercio-electronico-seguro-y-el-banco-sabadell/feed/10Copy files using rubyhttp://ivanhq.net/2011/04/13/copy-files-using-ruby/
http://ivanhq.net/2011/04/13/copy-files-using-ruby/#respondWed, 13 Apr 2011 17:16:29 +0000http://ivanhq.net/?p=553Continue reading Copy files using ruby]]>I’m translating my usual sysadmining shellscripts into ruby for fun and practice. One thing I hate from Ruby (maybe the only or the most important one) is its documentation. It is zero browseable and friendly, and makes you waste half of your time trying to find on google which module/class does what you need.

One thing I’ve been trying to find is how to copy a file (OMG!).
Can it be so difficult?? … please, try to find it on File class reference.

You have to figure out that exists a module called FileUtils or its old bro (ruby 1.8.6) ftools. Using them you can easily copy, move, rename and make basic file management.
What I find more surprising is that the File class reference does not mention any of them (Uh!?).

Once I found it the job was easy (using ftools as I’m still on Ruby 1.8.7):