Wednesday, 28 August 2013

unblock-us and DynDNS

My new ISP (Vodafone) provided me a new router (a Huawei HG658c) with their own firmware on it.  They also don't guarantee me a static IP address.  Unblockus says you can handle this with a DynDNS account.

 However, my router does not seem to be able to correctly update DynDNS, and even if it did I'm not entirely convinced that these magical "IP update" packets would get picked up by the good folks at Unblockus.  I've solved the DynDNS issue by installing and configuring ddclient, but Unblockus explicitly don't update your IP address when done by software DynDNS clients.

With a little bit of googling around and finding some decent partial solutions, I've devised what seems to be a pretty straight-forward shell-scripting mechanism that will keep track of your public IP address (it does assume you have only one public IP address) and if it changes will log you back in at unblock-us.com.  This script is also cron-able, should you so desire.  It should work on any Unix (Linux, OSX) with wget installed.

Also, this can entirely avoid a DynDNS account if all the more you want it for is to update Unblockus.  If you don't have a Linux machine, let me suggest getting a RaspberryPi and sticking that onto your network!

#!/bin/bash

usage() {
  echo "usage: $(basename $0) -u unblock-us_userid -p unblock-us_password"
  exit 1
}

unblock_user=""
unblock_pass=""
while getopts "u:p:" name; do
 case $name in
      u) unblock_user="$OPTARG" ;;
      p) unblock_pass="$OPTARG" ;;
 esac
done

if [ -z "$unblock_user" -o -z "$unblock_pass" ]; then
  usage
fi

lastIP_file=lastip.public
log_file=updater.log
ipechoURL="http://ipecho.net/plain"
unblockURL="https://api.unblock-us.com/login?${unblock_user}:${unblock_pass}"

cd $(dirname $0)

echo "Updating at $(date)" >> $log_file

if [ ! -f $lastIP_file ]; then
  touch $lastIP_file
fi
lastIP=$(cat $lastIP_file)
if [ -z "$lastIP" ]; then
  lastIP=0.0.0.0
fi

currentIP=$(wget -qO- $ipechoURL)
if [ ! -z "$currentIP" ]; then
  ping -q -c 1 $currentIP >/dev/null 2>&1
  if [ $? -ne 0 ]; then
    echo "ping of currentIP=[${currentIP}] obtained from $ipechoURL was unsuccessful" >> $log_file
    exit 1
  fi
else
  echo "Empty IP address from $ipechoURL" >> $log_file
  exit 1
fi

if [ "$lastIP" != "$currentIP" ]; then
  echo "IP has changed from $lastIP to $currentIP" >> $log_file
  echo $currentIP > $lastIP_file
  rm -f unblock.out
  wget -qO- $unblockURL > unblock.out
  if [ ! -f unblock.out -o "$(cat unblock.out)" != "active" ]; then
    echo "Output from $unblockURL is not as expected, may not be logged in. Content follows:" >> $log_file
    cat unblock.out >> $log_file
    exit 1
  fi 
else
  echo "IP unchanged" >> $log_file
fi

Friday, 7 June 2013

Being not-so-Genius

So I came across a post on Facebook from Be Genius which I'll reproduce here:

This is why the Japanese are better at math. Once you figure this out it'll blow your mind...

The lines and numbers above may not make any sense at first, but according to William C. at Themetapicture.com:

“The lines over the circles are color coded. Notice the single red line and 3 blue lines representing "13" group together while the single green and 2 black lines take their own group. [Simply] draw your first group of lines in one direction then your second group of lines going over the first, count the groups of intersections and there's your answer.”


Well, this has really gotten up my nose for some reason.  This tool is not "why the Japanese are better at math," and it doesn't even really explain "why the Japanese are better at standardized math tests" (I suspect the reasons for that are an emphasis on rote memorization).

Really, this is a manual tool for doing two-digit multiplication...and it isn't even a very good one at that.  If curious, this blog has a pretty good explanation for how this technique works (it is indirectly FOILing).  For me, what this technique most critically lacks is facilitating any sort of insights as to "what is going on in the maths" - the fact that it takes a blog post to describe is somewhat telling.

Try the technique with 18 x 19 (= 342):
  

You're sure as snot not going to count in the lower right...so hopefully you've memorized your single-digit multiplication tables (8 x 9 = 72), there's 8 + 9 = 17 on the diagonal, and 1 in the upper-left.  It's not as simple as just concatenating together these numbers (as the simple =156 example might lead you to think).  The upper left represents 100s, so that's really 1 x 100 = 100, the diagonal 17 is 10s, so that's really 10 x 17 = 170, and then the lower right is 1s, so that's 1 x 72 = 72.  Combine these by addition: 100 + 170 + 72 = 342.

(That's a lot of lines to draw!)

Now, try to see if you can figure out how to use this tool:
Same answer (and a lot fewer lines to draw!).  Crucially to me, you could probably figure out how this works on your own, without resorting to a blog post...and that is the power of the tool - it is closer to how the math works, not just some sort of accelerative technique that gets you an answer more quickly than the "multiply and carry" technique so many of us (of a certain age, at least) were taught in primary school.

Where this tool gets even more powerful is when Algebra gets introduced...remember the FOIL method?
                     First     Outside   Inside    Last 
(A + B) x (C + D) = (A x C) + (A x D) + (B x C) + (B x D)

Doesn't the solving the problem 18 x 19 with this square look suspiciously like (10 + 8) x (10 + 9)?   That's because that is exactly what you're doing.  So, you can teach the FOIL method by recalling something the students are already adept at, simply substituting different values for the polynomial terms, before getting into more complexities like squared numbers.

The Japanese technique  (assuming that's what it is) doesn't really help you understand that you're FOILing...you're just using a handy accelerator and might as well be using a calculator for all the math it is teaching you...