Introduction

Index


Matlab/Octave I/O for Ruby

What is this?

OctaveIO is a library to read/write octave/matlab4 files (actually, writing to matlab files is currently unimplemented).

In most cases functions OctaveIO.load and OctaveIO.save (which read/write the whole file at once) should suffice. If sequential read/write is needed one can use instance methods get (or read) and write (or <<). Iterating over the file content can be done with each.

If you want to know more check the Documentation

If you want to download it, get the tarball


A bare bone parser for HTTP-like requests

For the impatient...

Download the tarball

What is this?

A little, handy module which implements a very bare-bone parser for HTTP-like requests. No semantic is builtin in the parser, so one can it use with any protocol with an HTTP-like request syntax. (Actually, to be honest, the header Content-length is recognized. This is necessary for reading the request body).

Why did you write it? There are others HTTP servers in Ruby

Yes, that is true, but the problem is that such servers are... too complete. Actually, I did not need an HTTP parser, but something that would parse text with HTTP-like format, but without any builtin semantic about methods and headers. I wrote the first skeleton of this module in an evening, so I believe that it has been more convenient rewriting it from scratch rather than modifying an already available HTTP parser.

How do I install/use it?

Installation

Just copy http_like_parser.rb in some place where your code will find it.

Usage

The main class is the class Parser which implements... well, the actual parser.

The main method of a Parser object is #parse which accepts as parameter any object which answer to methods #getc, #ungetc and #read with the same semantic of the same methods of IO class (therefore, any descendant of IO will do) (isn't duck typing great?). #parse return an object which describes the parsed request. You can find a more detailed description of the user interface in the comments inside the Ruby file. (I believe in keeping the interface documentation inside the source file since it is easier to keep it in synch with the actual code).

Example


              #
              # Shameless borrowed from "Programming Ruby"
              #
              
              require 'socket'
              require 'http_like_parser'
              
              parser = HTTP_Like::Parser.new
              server = TCPServer.new ('127.0.0.1', 8000)
              
              while (session = server.accept)
                p parser.parse(session)
              
                session.print "HTTP/1.1 200/OK\r\nContent-type: text/html\r\n\r\n"
                session.print "<html><body><h1>#{Time.now}</h1></body></html>\r\n"
                session.close
              end