Monday, September 24, 2007
File I/O in Ruby
Ruby FAQ which seems to constantly move around and is currently not available (Google cache is though) has a very useful section 10.6 Should I feel uneasy if I don't close a file :
There are at least four good ways of ensuring that you do close a file:
- Use close (remembering to catch exceptions).
f = open "file" begin f.each {|l| print l} ensure f.close end- Use the block form of open
File.open("file") do |f| f.readlines.each { |l| print l } end- Use foreach
IO.foreach("file") {|l| print l}- Use readlines.
IO.readlines("file").each {|l| print l}
Labels: ruby
Friday, September 14, 2007
Copy DVD
Well, the next best thing after using gmplayer is copying (protected) DVDs. Number of good utilities exist under Windows, e.g. free DVD Decrypter and non-free but very good Magic DVD Ripper. Here we will cover what is available under Linux.
First, very good review, and only slightly outdated, is available in Gentoo Wiki. In fact, from all the tools mentioned there I only tried the simplest one: dvdbackup.
Here is what to do:
- Install libdvdcss ;
- Install libdvdread . Run configure command like that: ./configure --with-libdvdcss-libs=/usr/local/lib
- Get dvdbackup;
- Goto "src" subdirectory;
- (optional) Consider applying this patch;
- Compile dvdbackup like that: gcc -I/usr/local/include dvdbackup.c -o dvdbackup /usr/local/lib/libdvdread.a /usr/local/lib/libdvdcss.a -ldl (Note: linking libdvdread.so does not work for some reason, but feel free to use libdvdcss.so)
- Copy dvdbackup to /usr/local/bin or whatever
- Use like that:
(to copy DVD)
dvdbackup -v 4 -M -i /media/cdrecorder -o ~/mytopdir -n my_name
(to get info)
dvdbackup -i /media/cdrecorder -I
gmplayer dvd://1 -dvd-device ~/mytopdir/my_name