Java EE – What is a Servlet

“A servlet is a small Java program that runs within a Web server (such as Apache Tomcat). Servlets receive and respond to requests from Web clients, usually across HTTP, the HyperText Transfer Protocol.

To implement this interface, you can write a generic servlet that extends javax.servlet.GenericServlet or an HTTP servlet that extends javax.servlet.http.HttpServlet.”

Content taken verbosely from the Servlet Interface documentation page, found on the Java EE 6 API Javadoc.

Bypass Ext File System Read-Only Mode on Errors

If you have poorly written software which corrupts your file system e.g. during its installation, you probably face the problem that once the error occurs, the filesystem will lock for writing, and then your installation suddenly dies, hopeless.

Well, in the case that you want to force it to continue, even after (it) having broken your file system, you can, if it is in the EXT family (EXT2, EXT3 filesystems). The command is (as root) this:

tune2fs -e continue device

device is the one device this option is going to be applied.

Then, after the next reboot, e2fsck (file system check) will check the error, anyway, so you are “safe”. I had two situations installing poorly written software (I hope only the installer is poor in quality), and it helped going on until the end. One of them uses file system intensively and did not present any errors during production execution.

This is analogous to the mount command’s option errors (mount -o errors=continue). Or it can also be one of the options field’s values, in the fstab file e.g. “defaults,errors=continue“.

Padrino Routes Accept Regex URL Map

As Sinatra, Padrino route definitions accept regex when used as the :map option’s value in named aliases.

A standard named alias (‘thisroute’) mapped to some url with a code parameter embedded in the URL:

# For URLs like /someslug/anytext
get :thisroute, :map => '/someslug/:code' do
  # code param available as params[:code]
end

Accessing it as a block parameter, like in Sinatra, is also possible:

# For URLs like /someslug/anytext
get :thisroute, :map => '/someslug/:code' do |code|
  # code param available as request scope variable named code
end

And the killer one, if we want to enforce a pattern to the parameter, we capture it in a regex (suppose we only want to allow digits for that parameter, one or more), like this:

# For URLs with digits in param., only e.g. /someslug/123
get :thisroute, :map => %r|/someslug/([\d]+)| do |code|
  # code made of digits captured by regex available as code var.
end

Behold! And YES!! The first capture (text matched by the regex portion inside the parenthesis – the regex syntax element which delimits a capturing group) is available as the first block parameter, super conviniently! Now go enjoy it, and boost up your Padrino application routing!

Git Archive Analogous to an Export

To export the HEAD of your current branch (the one with an asterisk before it, on ‘git branch’ command’s output) in your git repository, do the following:

git archive HEAD | (cd ~/somedir_where_to_put_it/ && tar -xvf -)

Provided that ~/somedir_where_to_put_it already exists, otherwise, mkdir it.

Instead of HEAD you could use any revision’s hash number and then the codebase as it was in that commit would then be exported. To obtain such hash number read git log’s output.

Note: tar -xvf - is the command that consumes the subshell’s (delimited by the parenthesis after the pipe) input. It extracts a tar content from stdin (represented by the minus symbol at the end of the command, before closing the parenthesis) which was provided by git archive, thus, it is possible to conclude that git archive provides in its stdout a.k.a. standard output stream, the contents of the codebase at the given revision, in tar archive format.