Shuffle your Dreamhost rewards page

Back at the day Jesse Ruderman wrote a script putting the block containing “You currently have $X.XX of Rewards payments built up!” at the top of the Dreamhost rewards page. Now some people might find it useful, but there are also other people (like me), without any payments built up (yet…), who would like to see the “Referral Reports” block at the top. Here is the greasemonkey script that does exactly that: shuffle.your.dreamhost.rewards.page.user.js

While considering the code of those two similar scripts, with all due respect to Jesse, I think that my solution is more general and simpler at the same time (always KISS), meaning that it allows you to reorder all of the blocks in any way you want (and it’s done in a painless way too).

There’s also a word of advice to myself (and maybe to others as well) – or in other words, a reminder. When creating greasemonkey scripts, the simpler hack you use, the better your script will be. It’s really futile trying to protect your script from the HTML changes. You just can’t predict every single one of them. All of those scripts are just hacks, that can be broken with just a slight change in the HTML code. So you shouldn’t worry about your script not being robust enough. That’s ok. You will have to fix it at some point in the future anyway.

Have fun!

Trace your referrers in real-time

One of the magic things about Dreamhost is the ability to login to your account using ssh. Apart from standard things that you can do with it, like compile and install any program that you like (excluding those, which require root access, of course), you can also experience a little bit of magic if you run this command:

tail -f current-httpd-accesslog

There is really something special about tracking your website’s visitors as they come. And, of course, the most interesting thing is actually knowing where they come from (also known as referrers). The problem with this command is that it prints lots of garbage on the screen (like timestamps, response codes, sizes, etc.). The problem is that you cannot grep your real-time tailed log. Why? Don’t ask me, I’m not a Linux guru. You just can’t and that’s it. You can, however, write a script, which deals with that in its own way. And this is what I’ve been writing for the whole day. It was both fun and painful to learn for the n-th time all those shell hacks and quirks. Was it worth it? Sure it was! As a result I came up with this little bash script to trace your referrers in real-time. You can download it or view it below. I must warn you, though. It is highly addictive. Really…

#!/bin/bash

# ========================================================================
# REAL-TIME WEBSITE REFERERS TRACER
# ========================================================================
#
# What?
#   Real-time website referrers tracer is a shell script that lets you
#   trace your visitors as they come. Script works in an ultra compact
#   four-columns view :)
#
# Why?
#   Because you cannot do 'tail -f access_log | grep something' and you
#   really want to grep out most of the stuff that your httpd puts in
#   the logs.
#
# Requirements:
#   - website (with not too low and not too high traffic),
#   - shell account on the server where your website is hosted,
#   - access to httpd logs that use the COMBINED format.
#
# Installation:
#   - copy anywhere in your home directory,
#   - edit the script and set the 'log' variable so it actually
#     points to your current httpd log,
#   - make sure the script has execute rights (chmod +x trace-referers).
#
# Running:
#   - just run the script and watch the screen.
#
#
# Version: 0.2 (2005-06-18)
# Author: Paweł Gościcki, http://pawelgoscicki.com
#
# No copyright rights. You can do whatever you want with this. You may even
# claim this scrip has been written by you from the very beginning ;)
#
# If you, however, improve it, send me a copy (paul_AT_pawelgoscicki.com).
#
# Based heavily on the tgrep script by Ed Morton (morton_at_lsupcaemnt.com):
# http://unix.derkeiler.com/Newsgroups/comp.unix.shell/2004-01/0818.html


# CONFIGURATION
# =============

# Where your httpd log file is
log="current-httpd-accesslog"

# What files to exclude (request for those files won't be shown, regexp syntax)
exclude="\.gif|\.jpg|\.png|\.ico|\.css|\.js"

# Width of request and referrer columns (set it to match your terminal's width)
col_width=35


# MAIN SCRIPT
# ===========

# Check if log file actually exists (and is readable)
if [ ! -r "${log}" ]; then
echo "Cannot access log file: $log"
exit 0
fi

# After startup we will output few lines
start=`wc -l < "${log}"`
start=$(( $start - 30 ))
if (( ${start} < 0 ))
then start=$((0))
fi

# Main loop
while :
do
  end=`wc -l < "${log}"`
  end="${end##* }"
  if (( ${end} > ${start} ))
  then
    start=$(( $start + 1 ))
    sed -n "${start},${end}p" "${log}" | egrep -v "${exclude}" | \
    awk -v col_width=$col_width '{

      # we are only interested in GET/POST requests
      if ( match($0, /\"(GET|POST).*?\"/) > 0 )
      {
        split($0, fields, "\"")

        # IP_ADDRESS
        tmp = $1
        while ( length(tmp) < 15 ) tmp = tmp " "
        printf "%s", tmp " "
    
        # HTTP_REQUEST (GET/POST)
        tmp = substr(fields[2], 0, index(fields[2], "HTTP/") - 1 )
        tmp = substr(tmp, index(tmp, " ") + 1, col_width)
        while ( length(tmp) < col_width ) tmp = tmp " "
        printf "%s", tmp " "
    
        # REFERER (the juice)
        tmp = fields[4]
        while ( length(tmp) < col_width ) tmp = tmp " "
        printf "%s", tmp " "
    
        # USER_AGENT
        printf "%s", fields[6]
    
        # new line at the end
        printf "\n"
      }
    }'

    start=${end}
  fi

  # this is an endless loop executed every second
  sleep 1
done

Your current hosting provider does not support ssh access? You might then want to read my other post about hosting with dreamhost for as little as 9$/year. Have fun!

Rolling with Ruby on Rails on Dreamhost

As of yet it is unofficial, but Dreamhost has indeed added support for Ruby on Rails (v0.12.1) together with FastCGI!

I have just tested it briefly and it works as it is supposed to.

If you want to turn FastCGI on, you must log in into your Dreamhost panel and go to Domains -> Web. Single checkbox and FastCGI is enabled. Couldn’t be simpler.

Dreamhost, regarded by many as the hosting company is indeed staying on the cutting edge, being the first major player to support Rails.

UPDATE: It’s now official.

(via)

120GB/mo hosting with ssh/php/mysql for 9$/year

And it also includes 2.4GB disk space, 120GB monthly bandwidth allotment and a free top-level domain registration (.com, .net, .org or .info), worth $15 alone. When you calculate it, you may actually come to the conclusion, that Dreamhost, because this is the hosting company I am shamelessly advertising, is actually paying you $6 just to host with them! Isn’t it amazing?

Now as for the details… Normal price for this offer is about 90-110$/year (depending on whether you pay up front for one or two years of hosting), which is not that bad deal at all. But it gets much better. If you enter the special promotional code, you will have 100$ subtracted from the total amount you have to pay. And the special code is… 777! You must enter it in the fifth step of the registration process (you sign up for the Crazy Domain Insane hosting plan). $9/year is valid only throughout the first year and you can only pay by credit card. I have no idea how much longer will this promotional code be valid, so if it does not work for you, please let me know.

This offer gave me just enough motivation to start treating blogging more seriously, like using my real name and blog in my own top-level domain. And all of this thanks to Jesse Ruderman! You’re the man!

UPDATE: The 777 promo code is no longer accepted (quoting Dreamhost: Sorry, all the promo code 777s have already been used). You may, however, use another promotional code, which takes 50$ off your bill (depending on the plan you choose. The code is quite simple, you just have to enter XXX.

Host with Dreamhost