January 31, 2015

From inline to reference style links

I began using Markdown in 2009, before which, I wrote everything in HTML. Despite switching, the habit of using inline links persisted, resulting in a folder full of draft posts that I now find harder to read and edit. Here’s where I find pandoc really helpful. This following example shows how to convert a file named textinline.md that has inline style links into another file called textref.md with reference links.

pandoc -f markdown -t markdown --reference-links --no-wrap textinline.md -o textref.md

Batch convert

To do this for a folder full of files with .mdown extension to .md, here’s a batch shell script:

#!/usr/bin/env zsh
# 2015 ckunte
#
# Save this script as inl2ref.sh and run the following at zsh
# prompt:
#
#  $ zsh inl2ref.sh
#
autoload -U zmv
for file in *.mdown; do pandoc -f markdown -t markdown --reference-links --no-wrap "$file" -o "$file.md"; done
zmv '(*).mdown.md' '$1.md'

December 23, 2014

Phuket

Ten years on, I am on ground zero, and this place barely looks like anything fateful ever happened here. Sharp eyes will however notice evac. routes are now as prominent as road signs around town. But otherwise, it’s business as usual: the hawkers, the bars, the beach.

Maya bay, the idea of paradise in the film, The Beach.

I was in Kuala Lumpur in December of 2004, glued to screens when the deadly Indian Ocean tsunami first struck parts of Indonesia and Thailand. A day later, I signed-up to join a group of self-organizing TsunamiHelp volunteers online, after reading about an opportunity to offer assistance. I worked briefly as a wiki editor, combing through the rolling blog, where the latest information first got posted by a larger pool of posters, and organize information by self-contained topical pages. Volunteering time online — gathering (hopefully) useful information to those unfortunate to be in places where the tsunami struck — was a lot like hit or miss, not knowing if it was of any use at all.1 The premise was that cellphone lines would be jammed but not so with the internet, which meant whoever had access could potentially search for information, find the blog and wiki pages. That said, one only needs to look at the exposed electricity and telephone lines, and realize they’d likely never survive the first and second order effects of a tsunami, which uprooted buildings and trees without discretion. Of course, we were not thinking about things like these.2

Also, unlike the blog, the wiki had its share of downtime. At some point, the wiki had to be switched to domain(s) or service(s) from Wikinews — I forget now, but remember SocialText offered a free account to run the TsunamiHelp team. So, I think we spent some time copying over from one site to another twice. I presume other wiki volunteers did something similar. (With the exception of Wikinews, none of the other wiki sites survive today.)

As news began to spread, the TsunamiHelp blog did eventually get some recognition and was even on Google’s dedicated tsunami page for a while. (Some remnants of links can still be found on the web.) And in the following years, some organizations and a conference or two did applaud the effort — perhaps for its novelty, if not for its usefulness, which I think was nice.

The area destroyed by the tsunami could have been an opportunity to plan town and rebuild its streets well beyond its pre-tsunami days, but then this is Asia. Phuket is back on its feet, although day-tour guides still do remind us of the event.


  1. I was working mostly on the information but none connecting with whoever human on the other end of the line looking for help (others in the team tried to do that with Skype — a relatively new thing at the time), so it was hard to tell without any sort of feedback or useful stats. I am pretty sure help via the internet was both absurd and useless in areas like Banda Aceh, where the only way to help was to somehow to eject oneself physically there, or alternatively send food, aid material. 

  2. There is a lot of grief associated in any aftermath, which volunteers tend to internalize, and develop a certain emotional stability — stop hands from shaking. Needless to say, I was not cut out for this, and I did not sign up for other such noble pursuits after. 

November 23, 2014

Square and cube series conjecture

My ten year old younger daughter has been discovering number series on her own. Today, she said to me that she has developed two conjectures:

  1. Square series conjecture: When any two square values in series are known, an entire series can be built.
  2. Cube series conjecture: When any three cube values in series are known, an entire series can be built.

Here’s how she explains them:

Square series conjecture

Let’s say we have two square values in series:

25, 36
 |  |
 +--+
  11

The difference between square series is always an even number: 2. For instance,

1,  4,  9,  16
|   |   |   | 
+---+---+---+
  3   5   7
  |   |   |
  +---+---+
    2   2

So, you add 2 to the difference plus the last number to get the next in series.

25, 36,   49 (= 36 + 11 + 2)
 |  |     ^
 +--+     |
  11 + 2--+

Likewise, one can find the previous in the series as below:

25 - (11 - 2) = 16

Imagine a series of sequential square values as below:

\begin{aligned} …, a_{x-1}, a_{x}, a_{x+1}, a_{x+2}, … \end{aligned}

If you know any two in sequence, then you can build the series. Here’s how:

\begin{aligned} a_{x-1} = 2 \cdot a_{x} - a_{x+1} + 2 \newline a_{x+2} = 2 \cdot a_{x+1} - a_{x} + 2 \end{aligned}

This series is built one step at a time, of course, but it can be programmed to whatever iteration required to build the series.

Cube series conjecture

Let’s say we have three cube values in series:

27,   64, 125, 216, 
 |    |    |    |
 +----+----+----+
   37   61   91   
    |    |    |
    +----+----+
      24   30
      |    |
      +----+
        6

The difference between cube series is always an even number: 6. So, you come up with the next number as follows:

 64 - 61 + 30 - 6 = 27
216 + 91 + 30 + 6 = 343

Now Let us again imagine a series of sequential cube values as below:

\begin{aligned} …, b_{x-2}, b_{x-1}, b_{x}, b_{x+1}, b_{x+2}, … \end{aligned}

If you know any three in sequence, then you can build the series. Here’s how.

\begin{aligned} b_{x-2} = 3 \cdot (b_{x-1} - b_{x}) + b_{x+1} - 6 \newline b_{x+2} = 3 \cdot (b_{x+1} - b_{x}) + b_{x-1} + 6 \end{aligned}

Again like the square series, this series too is built one step at a time, of course, but it can be programmed to whatever iteration required to build the series.

She had to explain this whole thing to me twice before I could get my head around the concept and help formalize into equations, since she’s not yet into it herself.