Tuesday, August 24, 2010

Sydney Cityrail (131500) Timetable on Command-line (ver: 0.2)

Sydney CiryRail (www.131500.info) changed how parameters are fed in the URL from user's browser which broke my previous command line attempt.

Changes in this version:
  • Time format to use with '-t' is: "16:00" or "04:08:pm"
  • Date format to use with '-d' is: "2010:08:24"
Here is a fixed version (0.2) of the script:

    1 #!/bin/bash -e
    2 
    3 print_url=0
    4 timeout=10
    5 
    6 from_sta='Central'
    7 dest_sta='Town+Hall'
    8 
    9 old_now_date=$(date +%d%%2F%m%%2F%y)
   10 old_now_time=$(date +%I%%3A%M%p)
   11 
   12 now_date=$(date +%Y%m%d)
   13 now_hour=$(date +%I)
   14 now_min=$(date +%M)
   15 now_ampm=$(date +%P)
   16 
   17 function usage()
   18 {
   19 echo
   20 cat <<EOF
   21 [*] usage: `basename $0`  options
   22 
   23 OPTIONS:
   24  -u print url
   25  -h show this message
   26  -a set from station
   27  -b set dest. station
   28  -t set search time (08:30AM)
   29  -d set search date (21/5/10)
   30 EOF
   31 echo
   32 exit
   33 }
   34 
   35 function get_cookie()
   36 {
   37  wget -q -O /dev/null --keep-session-cookies --save-cookies="cookie.txt" "${
   38  1}"
   39 }
   40 
   41 while getopts "uha:b:t:d:" flag
   42 do
   43  if [ "$flag" == 'u' ]
   44  then
   45   print_url=1
   46  fi
   47 
   48  if [ "$flag" == 'h' ]
   49  then
   50   usage
   51  fi
   52 
   53  if [ "$flag" == 'a' ]
   54  then
   55   A=$(echo -n "${OPTARG:0:1}" | tr "[:lower:]" "[:upper:]")
   56   from_sta="$(echo -n "${A}${OPTARG:1}" | sed 's/ /+/g')"
   57  fi
   58 
   59  if [ "$flag" == 'b' ]
   60  then
   61   A=$(echo -n "${OPTARG:0:1}" | tr "[:lower:]" "[:upper:]")
   62   dest_sta="$(echo -n "${A}${OPTARG:1}" | sed 's/ /+/g')"
   63  fi
   64 
   65  if [ "$flag" == 't' ]
   66  then
   67   now_time=$(echo -n "$OPTARG" | tr '[:lower:]' '[:upper:]')
   68   now_time=$(echo "$now_time" | sed 's/://g;s/\-//g;s/\///g;s/\\//g')
   69 
   70   now_hour=$(echo -n "${now_time:0:2}")
   71   now_min=$(echo -n "${now_time:2:2}")
   72   now_ampm=$(echo -n "${now_time:4:2}")
   73  fi
   74 
   75  if [ "$flag" == 'd' ]
   76  then
   77   now_date="$OPTARG"
   78   now_date=$(echo "$now_date" | sed 's/://g;s/\-//g;s/\///g;s/\\//g')
   79  fi
   80 done
   81 
   82 old_url="http://www.131500.com.au/fullEnquiry.asp?&Vehicle=Bus,Train,
   83 Ferry&WalkSpeed=NORMAL&&IsAfter=A&MaxChanges=-
   84 1&FromLocType=s&ToLocType=s&x=64&y=11&FromLoc=$from_sta+Station~~;$from_sta+
   85 Station;$from_sta+Station~~LOCATION&ToLoc=$dest_sta+Station~~;$dest_sta+
   86 Station;$dest_sta+Station~~LOCATION&Time=$now_time&Date=$now_date"
   87 
   88 ori_url='http://www.131500.com.au/plan-your-trip/trip-
   89 planner?session=invalidate&itd_cmd=invalid&itd_includedMeans=checkbox&itd_in
   90 clMOT_5=1&itd_inclMOT_7=1&itd_inclMOT_1=1&itd_inclMOT_9=1&itd_anyObjFilter_o
   91 rigin=2&itd_name_origin=central&itd_anyObjFilter_destination=2&itd_name_dest
   92 ination=redfern&itd_itdDate=20100824&itd_itdTripDateTimeDepArr=dep&itd_itd
   93 TimeHour=2&itd_itdTimeMinute=0&itd_itdTimeAMPM=pm&x=56&y=11'
   94 
   95 url="http://www.131500.com.au/plan-your-trip/trip-
   96 planner?session=invalidate&itd_cmd=invalid&itd_includedMeans=checkbox&itd_in
   97 clMOT_5=1&itd_inclMOT_7=1&itd_inclMOT_1=1&itd_inclMOT_9=1&itd_anyObjFilter_o
   98 rigin=2&itd_name_origin=${from_sta}
   99 &itd_anyObjFilter_destination=2&itd_name_destination=${dest_sta}
  100 &itd_itdDate=${now_date}&itd_itdTripDateTimeDepArr=dep&itd_itdTimeHour=${
  101 now_hour}&itd_itdTimeMinute=${now_min}&itd_itdTimeAMPM=${now_ampm}
  102 &x=56&y=11"
  103 
  104 if [ $print_url == '1' ]
  105 then
  106  echo $url
  107 fi
  108 
  109 echo
  110 echo "From: $from_sta Station"
  111 echo "Dest: $dest_sta Station"
  112 echo "Time: $(echo $now_hour:$now_min $now_ampm | sed 's/\%3A/:/g')"
  113 echo "Date: $(echo ${now_date:0:4}:${now_date:4:2}:${now_date:6:2} | sed
  114 's/\%2F/\//g')"
  115 echo
  116 
  117 referer='http://www.131500.com.au/'
  118 agent='Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2.8)
  119 Gecko/20100722 Firefox/3.6.8 (.NET CLR 3.5.30729)'
  120 
  121 #get_cookie $url
  122 #wget $url -q -O - --referer "$referer" --load-cookies=cookie.txt --user-
  123 agent="$agent" | html2text | grep 'Option \([0-9]\+\)\|Arr:\|Dep:'
  124 lynx -noredir -dump $url | grep 'Option \([0-9]\+\)\|Arr:\|Dep:'
  125 
  126 echo

DokuWiki Beautifier: Floating Table of Contents (TOC) and others

Just put the following code inside  conf/userstyle.css  inside DokuWiki directory.

P.S. What you get from the code:
  1. The table of content moves up/down as you scroll.
  2. "Edit" buttons are a bit more stylish. (comment out if you don't like it)

    1 /* Place customisations to screen mode style sheet here */
    2 
    3 /* table-of-content sidebar*/
    4 div.toc {
    5   position: fixed !important;
    6   top: 1em !important;
    7   bottom: 3em !important;
    8   right: 0px !important;
    9   overflow-y: auto !important;
   10   display: -moz-box !important;
   11   height: 90% !important;
   12   width: 16% !important;
   13 }
   14 
   15 /* reducing page width to save it from going under toc */
   16 div.header, div.bar, div.doc, div.breadcrumbs {width:82% !important}
   17 div.page {
   18   width: 80% !important;
   19   border: 0px #6C9AD0 solid !important;
   20   padding: 1em !important;
   21 }
   22 
   23 /* styling the 'Edit' button */
   24 input[value="Edit"] {
   25 font-weight: bold !important;
   26 font-size:1em !important;
   27 border-width: 0.2em !important;
   28 }
   29 

Wednesday, August 18, 2010

Mounting HTC Android (G1) SD card on Windows 7

  1. Connect phone to the Windows 7 computer with USB cable
  2. On phone, select "Turn on USB storate" from status bar (slides down from top)
  3. On Windows 7, go to Control Panel > Device Manager
  4. Expand/Click on "Disk Drives" and select "HTC Android Phone USB Device"
  5. Right click on "HTC Android Phone USB Device" and Click "Disable"
  6. Now right click again on "HTC Android Phone USB Device" and Click "Enable"
  7. Windows 7 should show you the SD card files now ;)

Tuesday, August 17, 2010

Debian/Ubuntu: Delay in getting SSH login prompt

On some of my Debian/Ubuntu machines, I get an annoying 10-20 seconds delay in seeing the prompt while trying to login. My first guess was - something wrong in key exchange and it's must be falling back with standard password authentication, as can be seen with ssh -vv babil@servername

But the solution seems to be in disabling DNS resolution for the SSH server. I found the solution here: http://www.unix.com/linux/96010-delay-getting-ssh-login-prompt.html. /etc/ssh/sshd_conf needs a "UseDNS no" line, followed by a "sudo /etc/init.d/ssh restart".
Cheers.

Thursday, August 12, 2010

Stopping Gnuplot from flashing a plot window and disappear

In Ubuntu/Debian, Gnuplot tends to use terminal 'X11' if no terminal has been defined before the 'plot' command. The reason for not specifying a terminal could be various (eg. being lazy and ignorant, subsequent use of 'replot' command using other terminal types in several other scripts)

In my case I had a loop of 5x5x5x5 times in my NS-2 script invoking Gnuplot 6 times with every run. The flashing window literally leaves the screen unusable as the Gnuplot X11 terminal window keeps popping up and out in a blink.

A temporary fix (which doesn't require rewriting my whole Gnuplot script set) is to use:
set terminal unknown
Doing this stops the flash with the first 'plot' command. The subsequent 'replot' commands can define their own terminals as needed.

Sunday, August 1, 2010

Suppressing page number in LaTeX

\thispagestyle{empty}
\pagestyle{empty}