background preloader

Ruby

Facebook Twitter

Hackety Hack. Bowline. Ruby File System Watcher. FileSystemWatcher current release 1.0.0 Overview Simple library for watching events occurring on a file system. The events watched are CREATED, MODIFIED and DELETED. This solution is (should be) platform independent. For example, you might use this inside of your server to monitor changes in your config files.

Example require "filesystemwatcher" watcher.join() # join to the thread to keep the program alive Installation Run 'ruby install.rb'. General Usage Create the watcherwatcher = FileSystemWatcher.new() Tell the watcher what to watch watcher.addDirectory(dir[, expression]) watcher.addFile(fileName)You can watch individual files or directories. Notes If you know that your directory contains many many files consider creating multiple FileSystemWatcher(s).

Also, if you know your files are large be careful with the useMD5 option since it must read the contents of each file to generate a hash. Pragmatic Automation. Staking Out File Changes Michael McCracken has the automation spirit. He’s tired of doing anything repetitive, and he’s not gonna take it anymore! For starters, he went looking for a program or script that would run his unit tests whenever his Python source files changed. That search didn’t turn up anything, so he solved his problem the ol’ fashioned way — he wrote a program. From his blog: Inspired by Pragmatic Project Automation, I just posted about getting my unit tests to run automatically whenever I change a file. Since nobody volunteered, I went ahead and wrote what I wanted: stakeout. If you want to run tests anytime a source file changes: stakeout testAll.py *.py If you want to run make anytime a source file changes: stakeout make *. It uses kqueue to watch the files on the argument list. I’ve been using this for a couple of hacking sessions, and it’s great.

Stakeout is an Objective-C application that runs on Mac OS X. . $ stakeout.rb "ant test" *.java. Schacon's grit at master - GitHub. Tech.natemurray.com: 6 Ways to Run Shell Commands in Ruby. Often times we want to interact with the operating system or run shell commands from within Ruby. Ruby provides a number of ways for us to perform this task. Kernel#exec (or simply exec) replaces the current process by running the given command For example: $ irb >> exec 'echo "hello $HOSTNAME"' hello nate.local $ Notice how exec replaces the irb process is with the echo command which then exits.

Because the Ruby effectively ends this method has only limited use. The major drawback is that you have no knowledge of the success or failure of the command from your Ruby script. The system command operates similarly but the system command runs in a subshell instead of replacing the current process. system gives us a little more information than exec in that it returns true if the command ran successfully and false otherwise. $ irb >> system 'echo "hello $HOSTNAME"' hello nate.local => true >> system 'false' => false >> puts $? System sets the global variable $? Notice that $? 0? Riddle - Ruby Sphinx Client. OCR: Converting Images to Text with MODI. Joe Schmoe from Kokomo has a scanned image of a 300-page contract. Joe wishes he could search this file for certain rates and terms, but it's an image, not a text file. OCR might be just what the doctor ordered.

Optical character recognition, usually abbreviated to OCR, is the mechanical or electronic translation of images of handwritten, typewritten or printed text (usually captured by a scanner) into machine-editable text. --Wikipedia One such OCR solution that you may already have available to you is Microsoft Office Document Imaging (MODI), part of the Microsoft Office suite. MODI might not have been installed when you installed Microsoft Office, so your first step may be to install it from the Office install disks.

Accessing the MODI API To begin with, we'll use the win32ole module to create a new instance of the MODI.Document object: require 'win32ole'doc = WIN32OLE.new('MODI.Document') Loading the Image doc.Create('C:\images\image1.tif') NOTE: MODI only works with TIFF files. Doc.OCR() Ruby examples. Ruby Gui Programming With Shoes. Remi.org.

Apple

El operador splat(*) de Ruby. Learning Ruby.