Tuesday, August 02, 2016

oenophile's quandary

Actually, philosophers call that the Oenophile's Quandary! Presented with something that, over time, increases in quality (like wine) or in value (like money in a savings account), when's the right time to use it?

Sunday, July 10, 2016

emacs and installing packages over TLS

I find this article very useful. It walks you through setting up Emacs to download ELPA/MELPA packages over TLS, and also verifying the certificates.

various configs

I might as well put them in one place.

Emacs (from trunk):

./configure --without-pop --with-x-toolkit=lucid \
    --prefix=/usr/local/src --without-toolkit-scroll-bars \
    --without-compress-install --with-file-notification=yes \
    --with-wide-int --with-modules


./configure --with-gl --with-gle --with-xft --with-xshm-ext \
    --with-pixbuf --with-xdbe-ext --with-readdisplay \

SBCL (1.3.x):

sh ./make.sh --fancy --with-sb-fasteval --without-sb-eval


export EXINIT="set noeb sm verbose ruler showmode"



gtk-key-theme-name = "Emacs"
include "/usr/share/themes/Emacs/gtk-2.0-key/gtkrc"
gtk-entry-select-on-focus = 0


gtk-key-theme-name = "Emacs"
include "/usr/share/themes/Emacs/gtk-3.0/gtk-keys.css"


gtk-key-theme-name = Emacs



{:user {:plugins [[cider/cider-nrepl "0.12.0"]
                  [lein-pprint "1.1.2"]
                  [lein-droid "0.4.4"]
                  [venantius/ultra "0.4.1"]
                  [lein-ancient "0.6.10"]]}
 :repl {:dependencies [^:displace [org.clojure/clojure "1.8.0"]]}
 :android-common {:android {:sdk-path "/home/fn/android-sdk"}}}

Monday, April 13, 2015

Taxpayers in Pakistan

Pakistan's FBR, the tax collectors, recently published a PDF file with a list of all tax payers, both corporate and individual. (There's also a third category of "AOPs" -- whatever that is.) The file is linked off of the front page of the website.

I downloaded a copy of the file and used pdftotext (from xpdf) to convert it to a more pliable format, and then went to town. The conversion process wasn't perfect (tabular data doesn't always convert to one PDF row to one text row; see also the disclaimer at the bottom), but it's very easy to figure out the format by visually comparing it with the source.

(Side note: if I'd tried to import it into Google Sheets or Excel, maybe the conversion would've been better.)

Read the file from the string "COMPANY Taxpayer" until you see "332024095867"at the beginning of the line. That's the CNIC for the first individual listed in the file (listed as "#OHD ,NAWAZ"-- what does that say about their data validation procedures?).

Extract all strings in the format <digits>-<digit>. Those are company NTNs.

There are 64,960 companies in the file.

Extract all strings that are 13 digits long. Those are CNICs.

There are 779,077 taxpayers in the file. That's an average of 11.993 taxpayers per company.

How about taxes paid? (There are so many Rs 0 entries!) This is a little harder to extract. For companies: find a line that has NTNs in it, skip the next blank line, then read the taxes lines until you reach another blank line. Unfortunately, there's a problem with this approach: I should read 64,960 entries, but I read 64,886. Close enough!

Companies paid a total of Rs 376,174,769,305. 25,464 paid nothing.

People next, using a similar approach. I found 766,791 entries.

Individuals paid Rs 113,663,076,659 and 294,475 paid nothing.

DISCLAIMER: Because the conversion process isn't completely accurate my numbers are off by a bit. Also there's a lot of garbage in the file -- name fields with numbers before the names; CNIC fields that are empty or are six or seven digits long, etc.

Monday, February 16, 2015


The other day I was helping a co-worker set up Ubuntu in VirtualBox, to simulate the production servers.  At one point, I told him to search for a package by typing "apt dash cache space search space dash n space ..."

He types it in and says, it didn't work.  I walk over to check his display.  He's written "apt-gash search -n ..."

I say "You didn't take pre-med in college, you studied CS!  It's apt-cache, not apt-gash!"  He didn't understand what I meant.

So he corrects it, and types in "apt-cash search -n ..."

Sunday, January 18, 2015

change in brent crude and lahore gasoline prices in 2014

Oil prices have fallen worldwide.  I wanted to see how much of that drop is reflected in the price I pay for gasoline at the pump.  Is the cost of filling my tank dropping at the same rate as crude oil?

Summary: calculated against January 1, 2014's prices, on January 2, 2015 the drop in crude is 49.08% and the drop in my local prices 30.48%.

I downloaded the Brent crude prices for Jan 1 2014 to Jan 2 2015, and grabbed the fields I wanted:

$ awk -F, 'BEGIN { OFS="," } { print $1, $5}' ~/Downloads/CHRIS-ICE_B1.csv  | tail -r > crude.csv
$ head crude.csv

There are several gas stations on my way to work, but only two Shell stations that I can get to without making a U-turn.  For the local gasoline prices, I visited the regulator (OGRA)'s site and grabbed the prices for Shell.  I saved the PDF files and did

for i in *.pdf; do
  pdftops $i - 2>/dev/null | ps2ascii - ${i%pdf}txt
  echo done with $i

pdftops ships with xpdf and ps2ascii with Ghostscript.  It's not a perfect process, but close enough:

1388983409-201401.txt:386 LINK FILLING STATION LAHORE MODEL TOWN LINK ROAD 113.25 117.24 na
1391506062-201402.txt:383 LINK FILLING STATION LAHORE MODEL TOWN LINK ROAD 113.25 117.24 na
1393998747-201403.txt:383 LINK FILLING STATION LAHORE MODEL TOWN LINK ROAD 110.52 117.24 na
1396419125-201404.txt:384 LINK FILLING STATION LAHORE MODEL TOWN LINK ROAD 108.80 114.34 na
1399270867-201405.txt:385 LINK FILLING STATION LAHORE MODEL TOWN LINK ROAD 108.45 109.82 na
1401789424-201406.txt:385 LINK FILLING STATION LAHORE MODEL TOWN LINK ROAD 108.44 109.81 na
1404290583-201407.txt:385 LINK FILLING STATION LAHORE MODEL TOWN LINK ROAD 108.44 109.81 na
1407392347-201408.txt:386 LINK FILLING STATION LAHORE MODEL TOWN LINK ROAD 108.44 109.81 na
1412235166-201410.txt:386 LINK FILLING STATION LAHORE MODEL TOWN LINK ROAD 104.09 107.86 n/a
1415185107-201411.txt:387 LINK FILLING STATION LAHORE MODEL TOWN LINK ROAD 94.66 101.68 n/a
1417519204-201412.txt:LINK FILLING STATION LAHORE MODEL TOWN LINK ROAD 84.99 94.55 n/a
1420218912-201501.txt:LINK FILLING STATION LAHORE MODEL TOWN LINK ROAD 78.73 86.68 n/a

The first column of figures is what I want.

Combining the local prices with the crude oil prices, I get a simple spreadsheet, and voila:

The figures seem to show a large gap between changes to local prices and Brent crude (no surprise there).  Calculated against January 1, 2014's prices, on January 2, 2015 the drop in crude is 49.08% and the drop in local prices 30.48%.


  • While crude oil is priced in dollars and gasoline in rupees, I'm looking at the daily change in percentage terms, with the base set to January 1, 2014's prices.  I don't think the exchange rate has changed much in the past year.
  • Since OGRA's PDF files don't tell me when the gasoline prices went into effect, I'm going to assume the first working day of each month.
  • I don't know the exact cost of importing crude (or refined) oil to Pakistan.  The Brent crude price might not be all that relevant here.  However, this post is about investigating my perception of how much the price has dropped, based on what I see in the news and what I see at the gas pump.
  • This looks at the prices for just one company's gas station -- the one I frequent.  Other gas stations, located closer to the port of Karachi or local refineries, might show a larger drop.
(edited on January 25, 2015 to add a summary and fix a typo)

Saturday, January 10, 2015

manarat jeddah, january 2015

One of my brothers went to Saudi Arabia with his family for umrah a couple of weeks ago.  He was able to spend a few days visiting places in Jeddah -- places he hadn't seen since his last visit in 1995.

One of them was his (and my) old school, Manarat Jeddah.  I'm re-sharing his pictures below, with a guide to where they were taken.  You can find the campus on Google Maps, at the corner of Jabal Kudai and Jabal Dallah.  The school itself has moved to a different location.

Wednesday, December 03, 2014

chibi-scheme and native client

Getting chibi-scheme to work with Native Client was easier than I expected.  I used
  • chibi-scheme 0.7
  • pepper-37
  • Chrome 40
  • on OS X 10.9.5
I unpacked the chibi-scheme tarball and the Native Client SDK into ~/Source, and ran naclsdk update to grab the latest stable toolchain.  Then,

export NACL_SDK_ROOT=$HOME/Source/nacl_sdk/pepper_37
export CHIBI_ROOT=$HOME/Source/chibi-scheme-0.7

make SEXP_USE_DL=0 \
  CC=$NACL_SDK_ROOT/toolchain/mac_pnacl/bin/pnacl-clang++ \
  CFLAGS="-I$NACL_SDK_ROOT/include -I$NACL_SDK_ROOT/include/pnacl" \
  LDFLAGS="-L$NACL_SDK_ROOT/lib/pnacl/Release -lnacl_io -lppapi -lpthread" \
  EXE=.pexe \

You don't need chibi-scheme-static.pexe, but you do need the .o files.  Don't run make clean in this directory!

Next up, integrating chibi-scheme into a pnacl module, and then accessing that from a web page.  Here, I simply copied and adapted $NACL_SDK_ROOT/getting_started/part1: Makefile and code.  It shouldn't be too hard to adapt the example's index.html to use the new module; at minimum, modify the example's page to say

    <div id="listener">
      <script type="text/javascript">
        var listener = document.getElementById('listener');
        listener.addEventListener('load', moduleDidLoad, true);
        listener.addEventListener('message', handleMessage, true);

      <embed id="pn1"
             width=0 height=0
             type="application/x-pnacl" />

Run make serve, and visit http://localhost:5103/ in Chrome to load the page and module.  Pop open a console and type

HelloTutorialModule.postMessage('(+ 2 3)');

You'll probably want to modify the page to add an input field for your input and a p tag or textarea for the result of your evaluated form.  Here's what I started with: index.html.

Thursday, September 04, 2014

trying stumpwm

I've tried tiling window managers before, and I haven't been happy with them (especially with how they fail to deal with transient modal boxes), but I'm going to give them another shot. I followed the Ubuntu 12.04 + Gnome instructions, and set up stumpwm a couple of days ago. I've changed the control key from C-t to F12. It's still a little confusing, and I keep clicking on windows to focus on them (maybe there's a switch for that?), but the experience isn't terrible this time.

Maybe my feelings will change the next time I fire up Gimp, though I see someone's posted an example config for that on the wiki.

Wednesday, September 03, 2014

satellite images of earth.

For a while now, I've wanted a desktop background like xearth, but with updated (near-live) imagery. I've found a bunch of services that won't give me exactly that, but something I can live with.

Near Real-Time Data: Rapid Response has imagery from a bunch of instruments in satellites. I've had good experience with the Aqua MODIS images. Two tools on that site that I've tried are LANCE and Worldview.

Worldview shows the entire (mapped) planet with a short delay (they say 2.5-3 hours after a satellite pass). You can select base layers from the Aqua or Terra MODIS sources, and overlays from OpenStreetMap for borders, coastlines, and place names. You can also select a date to see what the world looked like in the past, going as far back as May 8, 2012. The best thing about it is that you can click on the camera icon, select an area, and it'll give you a link to an image. The image resolution goes down to 250 meters per pixel.

The Worldview image links appear to be stable, and look like


The TIME field is the current year followed by the day of the year (September 3 is the 246th day). Incrementing this field should get you the next day's image; you can easily write a script to generate a desktop background once a day, or fetch a bunch of files and generate an animation.

Image subsets are also available of the MODIS data for certain areas of the world. Selecting South America brings up a page where I can select, say, True Color images of La Paz and the surrounding area. It's the same data as Worldview, but with a different interface. It gives you a JPEG download link that, again, appears to be stable; it looks like


Another way to grab imagery is with GDAL. The subset image page has a link that describes how to download the data using GDAL. In summary, you create a file that looks like

      <service name="TMS">

Install the gdal tools (Ubuntu: apt-get install gdal-bin), and type

gdal_translate -of GTiff -outsize 3840 2880 \
    -projwin -72.44865700501 -13.302075710262 -63.681994009835 -19.777183974533 \
    your-gdal-filename.xml AERONET_La_Paz.tif
gdal_translate -of JPEG AERONET_La_Paz.tif AERONET_La_Paz.jpg

Change MODIS_Terra_CorrectedReflectance_TrueColor to MODIS_Aqua_CorrectedReflectance_TrueColor for the Aqua images. I used Worldview to figure out a bounding box for my city, and modified the -projwin parameter to match (and also -outsize to match my display resolution), and voila! a desktop background!

Friday, June 27, 2014


My grandmother turned 95 on Monday. She has trouble walking without help, and her short-term memory's not as good as it used to be, but she's still here.

Friday, June 20, 2014

read: Stonemouth, by Iain Banks

I liked how the story built up slowly, and I enjoyed the "crime fiction" angle of the Event that led to the narrator leaving the town before the events of the novel. I was afraid that if I didn't read carefully I'd lose track of the characters, but that didn't happen. 5/5.

Saturday, June 14, 2014

read: The Dig, by Alan Dean Foster

I bought the game a while ago (some Steam sale of LucasArts games), but I never got around to finishing it. The book was enjoyable.