What orientation do you read in?


I have made a strange observation after extensive reading on an iPhone and then an iPad. I am most comfortable reading on an iPhone in portrait orientation, with night theme, and turning pages instead of scrolling. With the iPad, on the other hand, I like to read books with lots of text in landscape mode, with the day theme (i.e. white background), and using scrolling instead of page turning.

I have yet to figure out why that is so. I think the iPad resembles the PC form factor where reading is done on a wider screen. Then there is the kind of reading that is very iPad specific, such as reading a magazine. That is when I usually read in the portrait mode.

Table manipulation in Lua


In Lua, arrays are tables. Tables can be iterated over using inbuilt functions such as pairs. Tables can have indexes other than numeric values. The example below creates two tables, adds contents of one to another, then prints the data in the resulting table.

table1 = {
  ["red"] = {Description="Red", RGB=0xFF0000},
  ["green"] = {Description="Green", RGB=0x00FF00}
}

table2 = {
  ["blue"] = {Description="Blue", RGB=0x0000FF}
}

for color,val in pairs(table1) do
  table2[color] = table1[color]
  -- or table2[color] = val
end

for color in pairs(table2) do
  print(string.format("%06x - %s", table2[color].RGB, table2[color].Description))
end

Here’s how the output looks. The order in which the colors appear is entirely unpredictable.

0000ff - Blue
00ff00 - Green
ff0000 - Red

SSH and SFTP on the iPad


I am using ServerAuditor, a wonderful and free SSH terminal app, on my iPad to access a Linux box. I needed to get the text contents (certificate) of a pem file into the app for authentication. I originally received the file by e-mail and had no app that would open the pem extension.

After some fruitless attempts I realized that the iPad has absolutely no app to view arbitrary text files. Browsers such as Chrome and Safari will only allow opening files with extensions they already understand.

After some searching I discovered that the Mercury Browser allows you to download files with any extension and upload them to Dropbox. It does not however allow viewing of arbitrary files, nor does Dropbox. Dropbox does allow you to view text files but will not allow you to rename a file so that it has the extension txt. I then remembered that Documents by Readdle allows you to rename files in Dropbox, and discovered that its built-in browser (Mobile Safari for all purposes) allows downloading files.

So there you go, I accessed my GMail account using Documents, downloaded the file with pem extension, renamed it to txt and was able to copy its contents to the ServerAuditor app. You don’t really have to rename the file since Documents will gladly show you its contents despite the pem extension. Did I mention that it also has SFTP support and allows you to edit files on the server?

Logging to Wireshark’s Lua console


A Lua script can log to the Lua Console of Wireshark by using inbuilt utility functions. For instance warn(“hello world”), prints that text to the console prefixed with date and time information and the text WARN. The console needs to be open for the information to appear. It can be opened from Lua sub-menu under Tools.

Operator precedence


Programmers should use parentheses more often. The following C language snippets are mind-blowing examples of when operator precedence is not obvious and can bite you.

x & 0x01 == 0</code>

== is evaluated first and then &.

a + b ^ c + d
  • is evaluated first and then ^.

SEI CERT C Coding Standard actually have rules against depending on operator precedence, for instance EXP00-C.

Wireshark and Lua bitwise operations


Lua has shipped a bitwise library since version 5.2. Wireshark Lua implementation has had the same bitwise operations, but the functions are accessed using table name bit instead of bit32.

If you are not familiar with writing dissectors for Wireshark in Lua I recommend reading this post first.