I’m too lazy to connect my scanner every time I have some papers to scan. It’s more convenient if the scanner is always connected, and if I just press a button to perform the scan. I figured out that the states of those buttons can be obtained using SANE library. I didn’t find any simple way to read those states apart from writing some low level C code. Obviously it’s much more fun to do that in Ruby instead – that’s why I decided to write FFI bindings to SANE library. I didn’t manage to do everything in Ruby (scanner was hanging up at some point during the scan), but the scanimageCLI does the rest for me. I ended up with something like that:
The script saves everything on my local NAS device, but you can modify it to email the scans somewhere, or to send them to your Google Docs account. You can also make use of other buttons, providing different scan settings, format or destinations.
You just need an Ubuntu box with Upstart to run the script as a daemon:
Simply save the configuration file in /etc/init/scanner.conf. To run the daemon manually use start scanner command.
When I was browsing through the Ruby on Rails Security Guide yesterday, I stumbled upon an interesting configuration option:
This will create an empty whitelist of attributes available for mass assignment for all models in your app. As such, your models will need to explicitly whitelist or blacklist accessible parameters by using an attr_accessible or attr_protected declaration.
Shouldn’t this be enabled by default, just like escaping HTML output in ERb templates? The only drawback of this solution is that you’ll need to turn the protection off explicitly when assigning attributes by hand (i.e. rails console):
Recently I needed to test compatibility of a static webpage on Internet Explorer running on VM. It’s not really handy to sync the files after every single change, so I decided to run a simple webserver to provide access to the directory via HTTP. After struggling with 5 liners using WEBrick, my friend came up with the idea to use Rack::Static to do so. You can simply save the following code in config.ru file in the directory that you want to publish, and run rackup command to start the server (don’t forget to gem install rack before).