Timestamped, gzipped tarball of a directory
#!/bin/sh
# tarit
# tar a given directory with timestamp.
fname=$1-`date +%Y-%m-%dT%H-%M`.tgz
tar czvf $fname $1
echo
echo $fname
#!/bin/sh
# tarit
# tar a given directory with timestamp.
fname=$1-`date +%Y-%m-%dT%H-%M`.tgz
tar czvf $fname $1
echo
echo $fname
thttpd is a small, fast and robust HTTP server that weighs in at less than 100KB of executable.
thttpd can make a fine web server for lean hardware (eg: single board computers).
Here, I am trying to serve a CGI application using tHTTPd.
$ cd
$ wget http://acme.com/software/thttpd/thttpd-2.25b.tar.gz
$ tar -zxvf thttpd-2.25b-tar.gz
$ mv thttpd-2.25b thttpd
$ rm thttpd-2.25b.tar.gz
$ cd thttpd
$ make
Run thttpd
$ sudo ./thttpd
By default thttpd runs on port 80, for which you need to be root. Let’s kill the process and use a higher port, which is accessible to non-super users.
$ sudo killall -9 thttpd
$ ./thttpd -p 8000
Let’s copy the supplied example config file to the current directory and modify it to suite our requirement.
$ cp contrib/redhat-rpm/thttpd.conf .
$ mkdir htdocs
$ mkdir htdocs/cgi-bin
$ mkdir log
$ mkdir run
Note: I’m taking a few liberties in setting up the server. My intention here is to get to cgi programming. Check thttpd docs for safer alternatives, including chrooting thttpd.
dir=/home/pradeep/thttpd/htdocs
user=pradeep
logfile=/home/pradeep/thttpd/log/thttpd.log
pidfile=/home/pradeep/thttpd/run/thttpd.pid
port=8000
host=0.0.0.0
charset=utf-8
cgipat=**.cgi
Let’s test the setup.
$ cat - > htdocs/test.html
<h1>Hello thttpd</h1>
^D
$ ./thttpd -C thttpd.conf
Visiting http://localhost:8000/ should show you the newly created page.
$ cat - > htdocs/cgi-bin/hello.cgi
#!/usr/bin/env python
print "Content-Type: text/html" # HTML is following
print # blank line, end of headers
print "<TITLE>CGI script output</TITLE>"
print "<H1>This is my first CGI script</H1>"
print "Hello, world! <br/>"
for i in range(10):
print i, '<br/>'
print 'Just to show that some stuff is "dynamically" generated server side<br/>'
^D
The above code is directly out of Python CGI library doc.
$ chmod +x htdocs/cgi-bin/hello.cgi
Restart the server and visit http://localhost:8000/cgi-bin/hello.cgi to see this simple CGI script in action.
Building my .zshrc using some of the references below.
Download and unzip Flex to $HOME/flex
Add $HOME/flex/bin to your path
$ cat ~/.bash_profile | grep flex
export PATH=$HOME/flex/bin:$PATH;
$ mkdir hello_flex
HelloWorld.mxml <?xml version="1.0"?>
<Application xmlns="http://www.adobe.com/2006/mxml">
<Label text="Hello, world!" />
</Application>
build.mxml. Change paths to reflect your own. I haven’t investigated how to use environmental variables in ant scripts, yet. <project name="HelloWorld" default="compile">
<property name="flex.mxmlc" location="/home/pgowda/flex/bin/mxmlc" />
<property name="dest.dir" value="bin" />
<property name="media.dir"
value="/home/pgowda/web_project/htdocs/media" />
<target name="init">
<delete dir="${dest.dir}" />
<mkdir dir="${dest.dir}" />
</target>
<target name="compile" depends="init">
<exec executable="${flex.mxmlc}" failonerror="true">
<arg line="-output ${dest.dir}/HelloWorld.swf"/>
<arg line="HelloWorld.mxml"/>
</exec>
<copy file="${dest.dir}/HelloWorld.swf"
tofile="${media.dir}/HelloWorld.swf" />
</target>
</project>
$ ant
Buildfile: build.xml
init:
[delete] Deleting directory
/home/pgowda/web_project/flexclient/bin
[mkdir] Created dir:
/home/pgowda/web_project/flexclient/bin
compile:
[exec] Loading configuration file
/home/pgowda/flex/frameworks/flex-config.xml
[exec]
/home/pgowda/web_project/flexclient/bin/HelloWorld.swf
(175845 bytes)
[copy] Copying 1 file to
/home/pgowda/web_project/htdocs/media
BUILD SUCCESSFUL
Total time: 6 seconds
I’d never paid much attention to the “web archive (.mht)” format used by Internet Explorer, because I do not use IE at all. Yesterday, I was forced to use the dinosaur of a web browser on a bank site, which shall remain nameless except that the programmers of that site would probably give you a “deer in headlights” look if I said anything about palindromes, web standards and cross browser compatibility. Sigh.
So, I saved a completed form in .mht format for later use, on the tiny EEE laptop on which I have windows XP, for it did not have CutePDF installed. Today, Opera on my MacBook opened this file to my relief, but it was to be short lived. Opera kept crashing every time I tried to print the file. I looked around the web for a converter from .mht to a more humane format. I found only paid software.
That’s when I decided to poke into the file itself and see whether I could salvage the document. Surprisingly, .mht file format is defined in RFC 2557. Jacob Palme, one of the proposers of the standard, has a web page explaining the MHTML format.
The format looks simple enough to be parsed using Python’s mimetypes library.
I’ve started a github project — pyMHTML to write a library to parse web archive files.
Hacking on this library is my fallback for the PyCon sprint sessions.