MySQL Conference 2009
Friday, April 24, 2009
CodeFutures @ MySQL Conference 2009
Tuesday, April 14, 2009
Ruby/Webrick File upload using multipart/form-data
Sunday, January 25, 2009
The following Ruby source is for a web server with a file upload servlet that accepts multpart/form-data file uploads.
#!/usr/local/bin/ruby
require 'webrick'
require 'stringio'
include WEBrick
s = HTTPServer.new( :Port => 8090 )
class FileUploadServlet < HTTPServlet::AbstractServlet
def do_POST(req, res)
filedata= req.query["filename"]
f = File.open("foo.out", "wb")
f.syswrite req.filedata
f.close
puts "Saved file OK"
end
end
s.mount("/upload", FileUploadServlet)
trap("INT"){ s.shutdown }
s.start
This is the HTML form to test this servlet with
<form action="http://localhost:8090/upload" method="POST" enctype="multipart/form-data">
File: <input type="file" name="filename"><br/>
<input type="submit" value="Upload">
</form>
Labels: ruby example
FireStorm now supports Ruby
Wednesday, January 21, 2009
The new release is available to download here.
Labels: ruby mysql dao
Python first impressions
Wednesday, January 14, 2009
However, I am now building some tooling for dbShards, our database sharding, replication, and failover solution, using Python. The main reason for choosing Python over Java is that we wanted a lightweight framework that makes it easy to monitor and control operating system processes on remote servers. Python was recommended to me by a friend (thanks, Paul!) and so far it looks like a pretty good choice, although I'm sure Ruby would also have been a good choice for this project.
Both Python and Ruby are object oriented to varying degrees but both allow good object oriented design and implementation making it easy for Java developers to pick up the language. The Python syntax has a couple of things that don't feel too natural, such as constructors being called __init__() and the fact that all non-static methods on a class must have a 'self' parameter rather than having a built in 'this' attribute as in Java. Neither of these is really a problem at all and they soon start to feel natural enough. The only real bugbear I have have with the Python language itself is the indentation syntax - Python purely relies on indentation (tabs and spaces) in the code to determine nesting rather than using curly braces or any other form of begin/end syntax. As a result, I find myself constantly switching between text editors and vi to fix indenting issues at the moment. I will have to spend some time researching IDEs for Python (so far I have been using the IntelliJ plugin, the PyDev plugin for Eclipse, and TextMate and none of them seem great at preserving the indents correctly). If anyone has any recommendations for Python tools please let me know.
Those issues aside, Python is a nice language and easy to learn. Most tasks can be implemented faster than the same tasks using Java, but not to the degree that many report (I have seen many claims of 5-10x productivity gains over Java and these might be true for someone who is not proficient in Java I suppose). The bigger challenge is the Python standard library which is very poorly documented. I spent almost a full day yesterday implementing a web server that supports "multipart/form-data" using the built-in BaseHTTPServer and cgi classes based on the documentation. I think the main issue was that I was using version 3.0 and it appears that this release is perhaps a bit too new to be used for production. When I ported my code back to version 2.5.1 it worked fine.
Python is undergoing some major changes at the moment and version 3.0 was released just a few weeks ago. There are some pretty fundamental changes between version 2.6.x and 3.0 such as "print" changing from being a statement to being a function, that make it impractical, to say the least, to write code that can work with both versions.
I have decided to stick with version 2.5.1 for now and port my code at a later date once 3.0 is stable enough (and once binary distributions are available for the platforms we need to support).

