On-demand Web Server with Python

A friend of mine has just showed me something that is not only useful but extremely simple to use. I’d say it fits the mind-blowing category.

How many times have you wanted to serve a file on an HTTP server for someone to download it from? Well, just install Apache, you’d say. I used to do that, but it feels like overkill. Maybe Lighttpd? I honestly found it was easier to just host it somewhere else than install and configure any of these in case they’re not already in use.

But here’s another solution: use Python! It is installed by default on most Linux distributions, if not all. It is so widespread right now that, if you’re not using it already – be it for programming or as a dependency for something else you use – you will need it sooner than you think. And not only it should already be installed, it needs zero configuration!

Fire up your terminal and try this:

$ python -m SimpleHTTPServer 8000

Next, point your browser to http://localhost:8000. Voilà! You just got yourself a web server! In case you haven’t tried this yourself yet, a directory listing for the current directory should appear. Close it with Ctrl-C when you’re done with it.

Extra tip: you can create a directory under your home such as webjail, or whatever name suits you, and start your webserver from there. Create symbolic links for stuff you want avaiable so you can keep your other files “secret”. Unlike my previous Apache setups with public_html, symlinks do work, so there is no need for hard copies. The only difference from regular files is that they will show a “@” appended to the filename on the listing, but that’s not really an issue, is it? 😉


Multiple terminals in a single SSH session

When I sit to work, I am using linux terminals 95% of the time. And I tend to use lots of them. One for vim, another for compiling and testing, another for checking whatever files the program outputs, and so on… If you’re a multiple windows/tabs kind of guy (or gal, why not?) like me, you know what I am talking about!

Ctrl + Shift + N is my favorite shortcut ever on gnome-terminal, but when I am not physically on the machine but working via SSH, it is not nearly as fun. In fact, it is annoying as hell as it opens a new local terminal, and I have to log in again, go to the path I am interested in, and only then being able to do whatever I want to do (which, sometimes, is pretty quick and I end up closing the terminal, just to regret next time I need it again). Thankfully, I found a nice way to solve this!

Read the rest of this entry »

Hello world!

First blog post… Why not start with this widespread, familiar sentence us programmers know so well? It was also the title for WordPress’ (automatic) first post, so I thought: why change it?

This blog is probably the realization of a long latent, dormant idea of having a personal website. A place to put little programs/utilities I tend to do every once in a while, be it as a fancy repository for myself in the future or as a place to share with others; ideas or cool things I found out by myself and, as such, have no way to bookmark in del.icio.us or similar… 😉

It was inspired by a enthusiastic reaction of a friend of mine after I told him of a cool thing I thought of, and which sounded very clever and helpful for me. At that exact moment, I felt the urge to share things with the world, and I went on this blogging spree.

I’m not sure what the future will bring (if I’ll keep this on WordPress or if I’ll eventually take a step further and make a real website), but I plan on posting cool stuff that computer geeks, programmers, linux users and people alike (that should be enough to cover you) might find useful or interesting.

Hope you like it! Please leave a comment when you stop by, it is good to know we’re not writing to ourselves sometimes, and what people think about it! 😎