My Rails book has ended up on a free download site. No comment.
In a RESTful web application design, you typically first identify the resources in your application, the nouns. For example, imagine you're writing a library app., and you're working on adding items to a catalogue. So you've got catalogues and items as your nouns.
You then decide to implement the operations on items, which live in the catalogue. In REST, HTTP verbs map onto the operations you want to perform: POST = create a new resource when you don't know what its identifier should be; PUT = update; DELETE = delete; GET = query resources. So you might end up with:
| HTTP request | Operation performed on resource | Returns |
|---|---|---|
| GET /catalogue/items?term=potter | Retrieve items containing the term "potter" | Representation of items, with a 200 OK status code |
| POST /catalogue/items Request body contains representation of new item | Add a new item to the catalogue | 201 Created status code, with Location header set to URI of new resource, and representation of resource in response body |
| PUT /catalogue/items/<control number> Request body contains representation of updated item | Replace existing representation with an updated one | 200 OK status code |
| DELETE /catalogue/items/<control number> | Remove item at the specified location | 204 No Content status code |
Fairly typical REST.
Then you realise you want to upload a whole pile of items at once, embedded in a single request for efficiency; but you don't want the client to have to wait while the items are inserted into the catalogue and properly indexed etc.. Maybe it will take 5 minutes or something, and you don't want to leave a web client hanging. Or perhaps you want to upload only a single item, but once items are uploaded they are put into a queue for processing by another system, so there's a wait.
What are your choices? Here are some ideas, partly gleaned from the RESTful Web Services book:
However, what I'm not so keen on is the idea of a job or service being a resource. Why? Well, if I want to create items in my catalog, I don't want to wrap them in a job and post them to /jobs; if I want to query my items, I don't want to have to go to a query service at /services/query or similar.
What these paths hint at to me is that an operation is being represented by that path, rather than a resource: effectively, calling them is like doing RPC: you pass the resources you want to act on as arguments to the procedure you're calling. Often, there's also some implicit resource hidden away behind the job or service. Compare:
Or:
It's kind of like the difference between object-oriented design (REST) and procedural design (RPC). While a job might look like a resource, my opinion is that it's really an amorphous wrapper around the real resource you should be representing. Typically, jobs get introduced to cope with asynchronous updates; I'd prefer to see asynchronous operations occurring on proper resources, but exposed using the batch processing approaches outlined above. Otherwise I fear you might lose your resources inside some vague blob of a "job" or "service".
I did my Ph.D. in artificial intelligence, so was interested to read a few Wikipedia articles about it. One distinction I'd never heard of was neats vs. scruffies in the field.
I put myself in the scruffies camp, probably, though I always had a yen for predicate logic and formal grammars. To my mind, some of the AI scruffies weren't scruffy enough, and tried to model human intelligence without any reference to psychological data. I tried to redress the balance a bit, and compared my program's output with psychological data on human inference during story comprehension. You can read all about it here.
At the time I did my Ph.D., I was pretty unfashionable, as I was researching symbolic AI approaches, while everyone around me seemed to be doing neural networks. However, I thought that while sub-symbolic approaches might produce intelligent output, I struggled to see how that would lead to a description of the solution, or anything that might be built on or added to by humans. If you're trying to program a reasoning system, for example, is it enough to train a neural network to create associations, or do you need to write something which can reflect on the process by which it reached its solutions? Neural nets are great for recognition tasks, but I was never convinced they were suitable for reflecting on how they completed the task. I'm sure there are plenty of counter-arguments to my limited opinion, so feel free to enlighten me.
What I've been up to recently, tech first:
I did a presentation on Rails to some students at Coventry University tonight, as part of their e-commerce M.Sc. course. Here are the materials (introductory presentation on Rails and a script for a demo. of Rails functionality).
Quite interesting. Find out about your online presence.
Here's my QDOS.
My mind is like the autumn moon
Shining clean and clear in the green pool.
No, that is not a good comparison.
Tell me, how shall I explain?
I'm the featured team member in this month's Talis Library Platform News.
Using Linux every day means that I often grapple with how to re-encode proprietary formats so that I can watch them on the computer of my choice. I also do some DVD ripping and creating new DVDs of home movies etc., for which the Linux command line tools work very nicely (more quickly, more consistently and in a more stable fashion than some of the GUIs).
So I've gathered a whole load of tips on encoding, ripping, burning, culled from dozens of forums, websites, manpages etc.. This, then, is the current state of my understanding on this topic, and hopefully distills many hours of pain into an easily-digestible format. It's not very well organised, but hopefully useful. I should mention that this stuff works on Ubuntu, but your mileage may vary. Here goes.
All of the tools I use are easily installable on Ubuntu, either from official repositories or universe/multiverse. You will also need to install the proprietary codecs if you want to work with them. Here's what I tend to use:
To work out where your CD/DVD device is:
$ cdrecord -scanbus
scsibus1:
1,0,0 100) 'HL-DT-ST' 'DVD+-RW GSA-T11N' 'A103' Removable CD-ROM
1,1,0 101) *
1,2,0 102) *
1,3,0 103) *
1,4,0 104) *
1,5,0 105) *
1,6,0 106) *
1,7,0 107) *
What you're looking for is an entry with something other than a * in it; then get the content of the first column, which is the device ID (here, it's 1,0,0).
Then:
cdrecord -v -dao dev=1,0,0 image.iso
setting dev= to the ID you found above, and where image.iso is the path to your ISO image file.
First off, download the FLV version of the video. This is the tricky bit, but here's how to find it:
http://www.youtube.com/get_video?video_id=<video ID>&t=<t parameter>
Use your favourite browser or downloader to fetch the file (FLV format).
My new technique for getting the mp3:
ffmpeg -vn -i youtubevideo.flv youtubevideo.mp3
You'll need a recent ffmpeg for some YouTube videos, and will also need mp3 support compiled in to do this conversion.
My old technique for getting the mp3:
Once you've downloaded it, play it through mplayer, resampling the audio at 44.1KHz:
mplayer -vo null -vc null -ao pcm:file=out.wav -af resample=44100:0:0 youtubevideo.flv
Then, use lame to encode the wav file to mp3:
lame -h -V0 out.wav out.mp3
This does a reasonable quality, variable bit-rate mp3.
There are a couple of services which do this (e.g. YouTubeHack) and a command line script, but I couldn't get the services to work, and couldn't be bothered with the command line script.
Use mencoder for this. mp4 version:
mencoder in.mp4 -ovc lavc -oac lavc -o out.mpg
mov version is practically the same:
mencoder in.mov -ovc lavc -oac lavc -o out.mpg
dvgrab --autosplit --timestamp --format jpeg
(The camera should be detected automatically, and I think this waits until it detects some input before the capture starts. I use a firewire cable to connect from the camera to the computer.) The files get named after timestamps coming from the film.
Use:
ffmpeg -i infile.avi outfile.mpg
(though this produces quite low quality output)
This produces better quality (bitrate = 800):
ffmpeg -i infile.avi -vcodec mpeg2video -acodec mp2 -b 800 outfile.mpeg
ffmpeg -i finalmovie.avi -y -target pal-dvd -sameq -aspect 16:9 finalmovie.mpg
If you're in the US, changed pal-dvd to ntsc-dvd.
(See http://www.bunkus.org/dvdripping4linux/single/index.html for lots of good tips)
May need dvdcss decoder to be installed:
sudo /usr/share/doc/libdvdread3/examples/install-css.sh
Use dvdbackup to rip a DVD to hard disk.
See http://dvd-create.sourceforge.net/dvdbackup-readme.html for full instructions
# Get info. about DVD dvdbackup -i /dev/cdrom -I # Rip whole DVD dvdbackup -M -i/dev/cdrom -o /media/usbdisk/dvdripping # Rip main feature dvdbackup -F -i /dev/cdrom -o /media/usbdisk/dvdripping # Rip title set (in this case, title set 2) dvdbackup -T 2 -i /dev/cdrom -o /media/usbdisk/dvdripping # Rip title (here, rip title 1) dvdbackup -t 1 -i /dev/cdrom -o /media/usbdisk/dvdripping
This effectively copies the DVD's iso image to hard disk:
dd if=/dev/cdrom of=file.iso bs=2048
If the disk is encrypted, this might fail. In this case, it might be worth running this first:
dvdbackup -I -i /dev/cdrom
Then try dd again.
See http://gentoo-wiki.com/HOWTO_Backup_a_DVD#dd for more details
Note that this produces a mountable DVD image. However, it does not remove encryption, so you would still need to rip to individual VOBs using dvdbackup to get rid of that. However, it is possible to mount the iso and play it as if it were a DVD (see later): vlc is good for this.
If you've ripped some of the content of a DVD (e.g. using dvdauthor -i /dev/cdrom -F), you can play the partial rip with:
mplayer dvd:// -dvd-device <ripped_dvd_directory>
(vlc might also be able to do this)
mplayer -vo null -vc null -ao pcm:file=outfile.wav infile.VOB
You could probably use ffmpeg for this, too.
If you just have the main feature (a set of .VOB files) and you want to create a playable DVD from them.
Create a dvd.xml file in the top level directory of the ripped DVD (e.g. in VIDEO_TS)
<dvdauthor>
<vmgm />
<titleset>
<titles>
<pgc>
<vob file="VTS_01_1.VOB" />
<vob file="VTS_01_2.VOB" />
<vob file="VTS_01_3.VOB" />
<vob file="VTS_01_4.VOB" />
<vob file="VTS_01_5.VOB" />
</pgc>
</titles>
</titleset>
</dvdauthor>
(Adding another
Then run it with:
dvdauthor -o <output directory for DVD structure> -x dvd.xml
See http://www.linux.com/articles/53702
(I think you might need to have used dvdbackup -M (complete rip) for this to work, or have a DVD structure created using dvdauthor (see above))
growisofs -dvd-compat -Z /dev/cdrom -dvd-video <ripped dvd structure>
If you've ripped the structure of a DVD (e.g. using dvdbackup) or created your own DVD structure (e.g. using dvdauthor), you can turn it into a single iso file with:
mkisofs -dvd-video <ripped dvd directory> | dd of=file.iso obs=32k seek=0
mkdir mountpoint sudo mount -o loop file.iso mountpoint
Once mounted, you can play the mounted iso (including its menu system) using vlc. For example, if we mounted it on the directory "mountpoint" we could do:
vlc dvd:///path/to/mountpoint
If you ripped a VOB off a DVD but you want a smaller mpg:
ffmpeg -i VTS_01_1.VOB -vcodec mpeg2video -acodec mp2 -b 1000 sleeper1.mpg
See https://help.ubuntu.com/community/HowToRipRealaudioStreamsToMp3 for full instructions
Short version:
vsound --timing --dspout --file=myfilename.wav realplay http://url.to.rip
This is a shell script for converting files from m4a to mp3. It uses mplayer and lame behind the scenes. sox is supposed to do this, but I can never work out how to install proprietary codecs for it. This doesn't retain tags, unfortunately. Sneetchalizer will probably also work.
#!/opt/lampp/bin/ruby
# only works if the script is in the directory with the m4a files
prefix = "new_file_prefix"
Dir['*.m4a'].each do |f|
new_filename = prefix + File.basename(f).gsub(' ', '_').slice(3..-5).downcase
wav = new_filename + ".wav"
mp3 = new_filename + ".mp3"
`mplayer -ao pcm:file='#{wav}' '#{f}'`
`lame -h -b192 #{wav} #{mp3}`
`rm #{wav}`
end
Uses ogg123. This script loses all the tags, though. Sneetchalizer would do this, too.
#!/opt/lampp/bin/ruby
filename = ARGV[0]
if filename.nil? or !(/\.ogg$/ =~ filename)
puts "I don't think that's an ogg file, mister"
exit
end
base_filename = filename.chomp(".ogg")
mp3_filename = base_filename + ".mp3"
`ogg123 -d au -f - #{filename} | lame - #{mp3_filename}`
Bit basic, this, but you get the idea:
mpg321 -s input.mp3 | oggenc -r -a "artist" -t "title" -b 100 -M 140 -o output.ogg -
sox is OK for this, as neither codec is proprietary:
sox input.ogg output.wav
I threw together some code for querying and parsing the BBC iPlayer search pages and emailing the results to you. You configure it by putting the names of the programmes you want to look out for into config.yaml, along with your email details, e.g.
search_terms: - mighty boosh - lead balloon - never better email: email_to: email@example.com email_from: email@example.com server: mail.example.com user: email@example.com pass: password auth_type: login
Copy the sample config.yaml.dist to config.yaml in the same directory and edit.
I run the command line script via cron once a day by calling the cli.rb script with an --email switch, e.g. with the following line in crontab:
0 21 * * * /usr/bin/ruby /home/ell/dev/iplayer/cli.rb --email
You could as easily run it from a Windows scheduled task.
Dependencies are:
What it does is request the iPlayer search page with each search term, one after the other. If there are multiple pages of results, it fetches each of those too, aggregating the results. It will then email you a list of links to the programmes on the iPlayer site. One thing it does which the iPlayer search page doesn't do is sort the matching results by how long is left for you to watch them: the ones with the least amount of time left are at the top.
You can also run it as a local web server on port 3334 with:
ruby server.rb
Which then becomes accessible at:
http://localhost:3334/
Nothing fancy: just an HTML page with the search results in it, using the same config. as the command-line client. You can also call the page with extra search parameters to perform custom one-off searches, e.g.
http://localhost:3334/?search=doctor+who
It's not a serious project, just a convenience for me. GPL licence.