<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
        <title>phunehehe.net</title>
        <description>phunehehe.net - Hoàng Xuân Phú</description>
        <link>https://phunehehe.net</link>
        <link>https://phunehehe.net</link>
        <lastBuildDate>2021-08-19T02:56:44+00:00</lastBuildDate>
        <pubDate>2021-08-19T02:56:44+00:00</pubDate>
        <ttl>1800</ttl>


        <item>
                <title>Singapore</title>
                <description>&lt;p&gt;This post is &lt;em&gt;still&lt;/em&gt; a work-in-progress. A few friends have asked for recommendations of places to visit and things to do in Singapore. So here is a list of my favourite things that I think are easy to overlook.&lt;/p&gt;

&lt;p&gt;The Pinnacle@Duxton&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;50 storey rooftop park / garden&lt;/li&gt;
  &lt;li&gt;Beautiful for sunset&lt;/li&gt;
  &lt;li&gt;6 SGD entrance fee (require an MRT card)&lt;/li&gt;
  &lt;li&gt;No food and drink (water is OK)&lt;/li&gt;
  &lt;li&gt;Stay as long as you want, but there’s no toilet :)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ah Mah Homemade Cake&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Hot cakes!&lt;/li&gt;
  &lt;li&gt;Perhaps try to share the cake, as a portion is too big for a snack&lt;/li&gt;
  &lt;li&gt;Try to go to a busy location to see the cake being baked before your eyes. In my experience the store at Plaza Singapura was consistently good, but the one time I tried at Changi Airport was mediocre because the cake was not hot anymore.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Chir Chir&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Surprisingly good Korean fusion chicken (just look at the pictures!)&lt;/li&gt;
  &lt;li&gt;My favourite is the roasted garlic chicken&lt;/li&gt;
  &lt;li&gt;I have only been to the stores at 313@Somerset and Bugis Junction&lt;/li&gt;
  &lt;li&gt;Be careful of ordering too much as the portion is very fulfilling. I usually just order the garlic chicken for 2 people.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Gardens by the Bay&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The 2 domes are totally worth 28 SGD&lt;/li&gt;
  &lt;li&gt;Nice surrounding area for sightseeing. Can spend a whole day strolling.&lt;/li&gt;
  &lt;li&gt;Be careful of the heat. Maybe use the domes to hide.&lt;/li&gt;
  &lt;li&gt;If visiting during the weekend, try to be at the Marina Barrage about an hour before sunset. There are usually lots of kite flyers, and the view is amazing.&lt;/li&gt;
  &lt;li&gt;Don’t miss the Garden Rhapsody light show&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Popiah &amp;amp; Rojak Place&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;A small stall at an unremarkable food court https://goo.gl/maps/6RUmuvj7rFD2&lt;/li&gt;
  &lt;li&gt;It’s not in the middle of entertainment so a bit inconvenient just for food, but maybe give it a try if you are in the area. The quality is better and the price is lower than other places I’ve tried.&lt;/li&gt;
  &lt;li&gt;Popiah tends to run out fast. I usually tried to be there at about 18:30 and sometimes still couldn’t get popiah. Not sure if they are open for lunch.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ying Jang Thai Food&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;My favourite place for phad thai / glass noodles / green curry / pineapple fried rice https://goo.gl/maps/evWMgh1sJp82 (second floor)&lt;/li&gt;
  &lt;li&gt;The cook is Thai so it’s automagically authentic :)&lt;/li&gt;
  &lt;li&gt;The food court is mostly to serve lunch during the week, though many stalls (including this one) open for dinner too. They close at 19:00 or so.&lt;/li&gt;
  &lt;li&gt;The food court also has a diverse selection. I also like the spinach soup stall.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Singtel Cafeteria&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;A hidden food court https://goo.gl/maps/p5mqr4a5VsK2&lt;/li&gt;
  &lt;li&gt;It’s open to the public. Singtel staff gets a discount, but even without the discount prices are still awesome. I think it’s only open for lunch during the week.&lt;/li&gt;
  &lt;li&gt;I like the porridge stall, the western food stall, and the salad stall&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;iSteaks	20 SGD steak at great quality
indo chicken
the soup spoon
https://www.esplanade.com/festivals-and-series/beautiful-sunday/2019&lt;/p&gt;
</description>
                <link>https://phunehehe.net/singapore/</link>
                <guid>https://phunehehe.net/singapore</guid>
                <pubDate>2019-02-26T00:00:00+00:00</pubDate>
        </item>

        <item>
                <title>Restoring Original Android Firmware on Xperia ZR</title>
                <description>&lt;p&gt;Recently I decided to try out Android Pay and found that my new phone doesn’t
have NFC, and that the app refused to work on my old phone because it ran
CyanogenMod. Fortunately after a little research I found restoring isn’t that
hard.&lt;/p&gt;

&lt;h2 id=&quot;safetynet-api&quot;&gt;SafetyNet API&lt;/h2&gt;

&lt;p&gt;Android Pay complained that the device has an unlocked bootloader, was rooted
and ran a custom ROM. The &lt;a href=&quot;https://developer.android.com/training/safetynet/attestation.html#possible-results&quot;&gt;documentation&lt;/a&gt; of the SafetyNet Attestation API
suggests this means the app is looking for the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ctsProfileMatch&lt;/code&gt; check as
opposed to the more forgiving &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;basicIntegrity&lt;/code&gt; check. Most notably the former
doesn’t allow a “device with custom ROM (not rooted)”. I wouldn’t miss the root
access or the unlocked bootloader at all, but not being able to use a custom
ROM is sad.&lt;/p&gt;

&lt;h2 id=&quot;restoring&quot;&gt;Restoring&lt;/h2&gt;

&lt;p&gt;The restoration isn’t complicated once I figured out how to do it, but the
amount of information to wade through is overwhelming. To navigate the
gazillion articles on the internet about this potentially risky topic, I
started from XDA Developers.&lt;/p&gt;

&lt;p&gt;As per Android Pay’s complaint I need to do 2 things:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Relock the bootloader&lt;/li&gt;
  &lt;li&gt;Reinstall an original version of the OS (and conveniently lose root access
  during the process)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After getting Flashtool and the firmware file (see below), just run Flashtool
and follow the UI.&lt;/p&gt;

&lt;h2 id=&quot;flashtool&quot;&gt;Flashtool&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://www.xda-developers.com/tag/flashtool/&quot;&gt;Flashtool&lt;/a&gt; can be used for both tasks. It’s opensource and supports Linux.
Confusingly there are 2 releases available for download as of now, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0.9.18.6&lt;/code&gt;
and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0.9.23.2&lt;/code&gt;. Through trial and error I found that each works with different
firmwares, presumably depending on how the firmware files are created.&lt;/p&gt;

&lt;h2 id=&quot;original-firmware&quot;&gt;“Original” Firmware&lt;/h2&gt;

&lt;p&gt;Next I need the firmware. There are plenty of posts on XDA Developers that show
up in search results for “xperia zr stock rom”. I didn’t make a backup of a
certain partition before installing CyanogenMod so I can’t have a completely
original experience, in that I won’t be able to download OTA updates.&lt;/p&gt;

&lt;p&gt;While trying I made the mistake of not checking and used an older version of
Android that Android Pay doesn’t support. Flashtool also has a &lt;a href=&quot;http://www.flashtool.net/firmwares.php&quot;&gt;list&lt;/a&gt; of
firmwares but the ones available for ZR are also old. I ended up using an
Android 5.1.1 Lollipop &lt;a href=&quot;https://forum.xda-developers.com/xperia-zr/general/stock-rom-xperia-zr-c5503-10-7-0-222-t3199674&quot;&gt;build&lt;/a&gt; which works with Flashtool &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0.9.23.2&lt;/code&gt;.&lt;/p&gt;

</description>
                <link>https://phunehehe.net/xperia-android/</link>
                <guid>https://phunehehe.net/xperia-android</guid>
                <pubDate>2017-05-10T00:00:00+00:00</pubDate>
        </item>

        <item>
                <title>So you want a better FS?</title>
                <description>&lt;p&gt;Recently having strange performance spikes with the loopback image I have been
using since forever, I bit the bullet and gave &lt;a href=&quot;https://btrfs.wiki.kernel.org/&quot;&gt;Btrfs&lt;/a&gt; a try.&lt;/p&gt;

&lt;p&gt;First let’s address the elephant in the room: “Is Btrfs stable yet”? The wiki
has your &lt;a href=&quot;https://btrfs.wiki.kernel.org/index.php/FAQ#Is_btrfs_stable.3F&quot;&gt;answer&lt;/a&gt;. I’ll give you mine: If it’s stable enough for kernel
developers to use on their workstations for 4 years, it’s stable enough for me.&lt;/p&gt;

&lt;h2 id=&quot;the-setup&quot;&gt;The Setup&lt;/h2&gt;

&lt;p&gt;I had a big Ext4 partition spanning most of the drive, and a loopback image in
it for encryption purposes&lt;sup id=&quot;fnref:1&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:1&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;1&lt;/a&gt;&lt;/sup&gt;. Most of my stuff is in the loopback image.&lt;/p&gt;

&lt;p&gt;Anyway, the loopback image works fine, but when some application uses a lot of
disk IO, disk access would freeze for a few seconds (then unfreeze for a few
seconds, then freeze again). &lt;a href=&quot;https://nixos.org/nix/&quot;&gt;Nix&lt;/a&gt; and VirtualBox tend to trigger this a
lot.&lt;/p&gt;

&lt;p&gt;It would have been nice to figure out the exact component that causes the
spikes, but I figured having a filesystem on top of &lt;a href=&quot;https://en.wikipedia.org/wiki/Linux_Unified_Key_Setup&quot;&gt;LUKS&lt;/a&gt; on top of another
filesystem didn’t help. Time to simplify the stack.&lt;/p&gt;

&lt;h2 id=&quot;the-steps&quot;&gt;The Steps&lt;/h2&gt;

&lt;p&gt;These aren’t intended to be a walkthrough, just the general picture. Some links
are included, though you can easily find details elsewhere.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Update the kernel. You aren’t going to enjoy improvements to Btrfs if you
  use a few year old kernel. Use the latest stable kernel for your
  distribution. For Ubuntu it means installing the newest &lt;a href=&quot;https://wiki.ubuntu.com/Kernel/LTSEnablementStack&quot;&gt;hardware enablement
  stack&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;Shrink the main partition. Because this cannot be done offline you need to
  boot into a live USB or something. In my case shrinking a 1TB partition
  (300GB used) to 500GB took a few hours.&lt;/li&gt;
  &lt;li&gt;Put &lt;a href=&quot;https://en.wikipedia.org/wiki/Logical_Volume_Manager_(Linux)&quot;&gt;LVM&lt;/a&gt; in the unused space to make this easier in the future.&lt;/li&gt;
  &lt;li&gt;Add LUKS&lt;/li&gt;
  &lt;li&gt;Add Btrfs (more below)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;the-better-fs&quot;&gt;The Better FS&lt;/h2&gt;

&lt;p&gt;Better how? Well I don’t care that much about the filesystem, I just wanted to
see if getting rid of the loopback device also gets rid of the performance
spikes, and it did.&lt;/p&gt;

&lt;p&gt;However I went through the documentation to make sure I didn’t miss anything
obvious, and here are some interesting options I decided to change from the
default values:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;autodefrag&lt;/code&gt;: The &lt;a href=&quot;https://btrfs.wiki.kernel.org/index.php/Gotchas#Fragmentation&quot;&gt;Gotchas page&lt;/a&gt; mentions potential problems with
  fragmentation, to which this option is a nice solution. It’s not enabled by
  default though&lt;sup id=&quot;fnref:2&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:2&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;2&lt;/a&gt;&lt;/sup&gt;, so you’ll have to explicitly enable it.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;commit=3600&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;noflushoncommit&lt;/code&gt;: By default Btrfs “commit” data to disk
  every 30 seconds. This additional safety measure makes sure you don’t lose
  more than that much of data when the worst happens. On my laptop it doesn’t
  really matter, so I decide to trust the other safety measures.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;compress&lt;/code&gt;: Transparent compression, why not!&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;noatime&lt;/code&gt;: Same as always, there is no need to keep access time updated
  because I don’t use applications like Mutt.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;p&gt;After going through Google+ and Hacker News (which stops accepting comments
after 2 weeks) I will now try using Diaspora as the commenting platform. I
guess requiring a D* account is nothing worse than a G+ or HN account. So
&lt;a href=&quot;https://joindiaspora.com/posts/8080373&quot;&gt;comment there&lt;/a&gt; maybe. &lt;a href=&quot;https://news.ycombinator.com/item?id=12884719&quot;&gt;Hacker News&lt;/a&gt; is good for 2 weeks too.&lt;/p&gt;

&lt;hr /&gt;

&lt;div class=&quot;footnotes&quot; role=&quot;doc-endnotes&quot;&gt;
  &lt;ol&gt;
    &lt;li id=&quot;fn:1&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;The encryption is also an interesting topic but it’s perhaps another story. &lt;a href=&quot;#fnref:1&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:2&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;Seemingly due to performance concerns e.g. if you run a database, but you
  &lt;a href=&quot;https://mariadb.com/blog/what-best-linux-filesystem-mariadb&quot;&gt;shouldn’t&lt;/a&gt; run a database on a COW filesystem anyway. &lt;a href=&quot;#fnref:2&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;
</description>
                <link>https://phunehehe.net/btrfs/</link>
                <guid>https://phunehehe.net/btrfs</guid>
                <pubDate>2016-11-06T00:00:00+00:00</pubDate>
        </item>

        <item>
                <title>DigitalOcean doesn't allow SMTP connections via IPv6</title>
                <description>&lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt;: as &lt;a href=&quot;https://news.ycombinator.com/item?id=11372121&quot;&gt;pointed out by p1mrx&lt;/a&gt;, this is caused by DigitalOcean’s
blocking some mail related IPv6 traffic to avoid abuse, similar to what’s
described in &lt;a href=&quot;https://warrenguy.me/blog/ipv6-digital-ocean-crippled&quot;&gt;IPv6 on Digital Ocean is crippled&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;del&gt;TLDR: Gmail appears to support IPv6 for SMTP by broadcasting an IPv6 address
for its IMAP and SMTP services. However, whatever behind the IPv6 address
doesn’t accept SMTP connections.&lt;/del&gt;&lt;/p&gt;

&lt;p&gt;According to &lt;a href=&quot;https://support.google.com/mail/troubleshooter/1668960&quot;&gt;Set up Gmail with Outlook, Apple Mail, or other mail clients&lt;/a&gt;
you should use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;smtp.gmail.com&lt;/code&gt; when sending mails, via port 465 or 587.&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;smtp.gmail.com&lt;/code&gt; supports IPv6 (yay!):&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ host smtp.gmail.com
smtp.gmail.com is an alias for gmail-smtp-msa.l.google.com.
gmail-smtp-msa.l.google.com has address 74.125.68.108
gmail-smtp-msa.l.google.com has address 74.125.68.109
gmail-smtp-msa.l.google.com has IPv6 address 2404:6800:4003:c02::6c
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;But it doesn’t have the ports we need open:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ nmap -6 -Pn 2404:6800:4003:c02::6c

Starting Nmap 6.40 ( http://nmap.org ) at 2016-03-26 13:49 UTC
Nmap scan report for sc-in-x6c.1e100.net (2404:6800:4003:c02::6c)
Host is up (0.0024s latency).
Not shown: 999 filtered ports
PORT    STATE SERVICE
993/tcp open  imaps

Nmap done: 1 IP address (1 host up) scanned in 8.20 seconds
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;But its IPv4 counterpart does:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ nmap -Pn 74.125.68.108

Starting Nmap 6.40 ( http://nmap.org ) at 2016-03-26 13:43 UTC
Nmap scan report for sc-in-f108.1e100.net (74.125.68.108)
Host is up (0.0018s latency).
Not shown: 995 filtered ports
PORT    STATE SERVICE
25/tcp  open  smtp
465/tcp open  smtps
587/tcp open  submission
993/tcp open  imaps
995/tcp open  pop3s

Nmap done: 1 IP address (1 host up) scanned in 4.55 seconds
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Poor IPv6 :(&lt;/p&gt;

&lt;p&gt;This hurts. Normally, if something doesn’t support IPv6, the network stack is
smart enough to fall back to IPv4. A simple way to work around this is to
disable IPv6 support in the network stack, but that hurts IPv6 adoption. Guess
I’ll find a hack to tell my programs not to use IPv6 when talking to
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;smtp.gmail.com&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I sent this in a feedback form (click the gear in Gmail, then “Send feedback”).
Hopefully that’ll amount to something.&lt;/p&gt;

&lt;p&gt;Questions or comments can go to &lt;a href=&quot;https://news.ycombinator.com/item?id=11369140&quot;&gt;Hacker News&lt;/a&gt;.&lt;/p&gt;

</description>
                <link>https://phunehehe.net/gmail-smtp-ipv6/</link>
                <guid>https://phunehehe.net/gmail-smtp-ipv6</guid>
                <pubDate>2016-03-26T00:00:00+00:00</pubDate>
        </item>

        <item>
                <title>Running Linux with a bare window manager</title>
                <description>&lt;p&gt;The &lt;a href=&quot;http://unix.stackexchange.com/q/1500/250&quot;&gt;most efficient way&lt;/a&gt; to run GUI applications is to run a &lt;a href=&quot;https://en.wikipedia.org/wiki/Display_server&quot;&gt;display
server&lt;/a&gt; and a &lt;a href=&quot;https://en.wikipedia.org/wiki/Window_manager&quot;&gt;window manager&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Despite efforts like &lt;a href=&quot;https://wayland.freedesktop.org/&quot;&gt;Wayland&lt;/a&gt; and &lt;a href=&quot;https://en.wikipedia.org/wiki/Mir_(software)&quot;&gt;Mir&lt;/a&gt;, &lt;a href=&quot;https://en.wikipedia.org/wiki/X.Org_Server&quot;&gt;X.Org&lt;/a&gt; is still the de
facto display server. It is enabled by default almost everywhere so you don’t
need to do anything about it.&lt;/p&gt;

&lt;p&gt;You just need to choose a window manager. &lt;a href=&quot;http://www.compiz.org/&quot;&gt;Compiz&lt;/a&gt; comes by default with
Ubuntu so it’s a good choice if you don’t want to install new stuff yet.
&lt;a href=&quot;http://openbox.org/wiki/Main_Page&quot;&gt;Openbox&lt;/a&gt; is also a sane choice. &lt;a href=&quot;http://xmonad.org/&quot;&gt;Xmonad&lt;/a&gt; is my favorite, so I’m going
to use it as the example here.&lt;sup id=&quot;fnref:1&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:1&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;1&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;

&lt;p&gt;First you need to add a login session by creating the file
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/usr/share/xsessions/custom.desktop&lt;/code&gt; with this content:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;[Desktop Entry]
Name=Xsession
Exec=/etc/X11/Xsession
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Make sure the file is readable by everyone or the login manager won’t be able
to load it.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;chmod&lt;/span&gt; +r /usr/share/xsessions/custom.desktop
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;When a user logs in using this custom session, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/etc/X11/Xsession&lt;/code&gt; will be
executed. It will (among other things) checks for a file name &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.xsession&lt;/code&gt; in
the user’s home directory and execute the file if it’s there. We are going to
create that file now:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;#!/usr/bin/env bash&lt;/span&gt;
compton &amp;amp;
dropbox &amp;amp;
&lt;span class=&quot;nb&quot;&gt;exec &lt;/span&gt;xmonad
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/chjj/compton&quot;&gt;Compton&lt;/a&gt; is a “compositor”. Basically it provides window transparency
which I like. You won’t need it in a heavy window manager like Compiz. You do
need it for Openbox though.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://dropbox.com/&quot;&gt;Dropbox&lt;/a&gt; is another program that I want to start together with my login
session. Of course, you don’t have to add it, and you should add anything else
that you want to start automatically here.&lt;/p&gt;

&lt;p&gt;Once you’re done, log out and you should see your entry “Xsession” in the list
of sessions in the login screen. Just use that from now on :)&lt;/p&gt;

&lt;div class=&quot;footnotes&quot; role=&quot;doc-endnotes&quot;&gt;
  &lt;ol&gt;
    &lt;li id=&quot;fn:1&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;This post was adapted from an &lt;a href=&quot;https://web.archive.org/web/20130306061222/http://phunehehe.is-great.org/&quot;&gt;archive.org snapshot&lt;/a&gt; of my old blog
  which was free and is now dead (yeah, free hosting). &lt;a href=&quot;#fnref:1&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;
</description>
                <link>https://phunehehe.net/linux-bare-window-manager/</link>
                <guid>https://phunehehe.net/linux-bare-window-manager</guid>
                <pubDate>2016-03-20T00:00:00+00:00</pubDate>
        </item>

        <item>
                <title>Malaysia GrabCar Etiquette</title>
                <description>&lt;p&gt;Recently I had a chance to come back to Malaysia for a few days and was
introduced to a few “rules” when using GrabCar, a taxi-like service that some
refer to as “anti-taxi”.&lt;/p&gt;

&lt;h2 id=&quot;the-strange-rules&quot;&gt;The Strange Rules&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Avoid booking the start or end of your trip near taxi stands.&lt;/li&gt;
  &lt;li&gt;If possible, put your luggage in the backseat instead of the trunk.&lt;/li&gt;
  &lt;li&gt;One of the guests should take the front seat.&lt;/li&gt;
  &lt;li&gt;Offer to pay before reaching your destination.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;As you might have guessed, these are to avoid revealing to taxi drivers that
you are using an alternative to their service. There have been cases where
GrabCar drivers get bullied or their cars get damaged, simply because they
provide competition.&lt;/p&gt;

&lt;h2 id=&quot;is-grabcar-legal&quot;&gt;Is GrabCar Legal?&lt;/h2&gt;

&lt;p&gt;A cursory search suggests that this is not clear-cut, but frankly I don’t care.&lt;/p&gt;

&lt;p&gt;Taxi drivers in Malaysia like to bully their customers. Rain, traffic jam, time
of day etc. are reasons for you to pay extra. You never know whether they are
going the “short” way or the “quick” way. And if you call in to complain, the
best you’ll get is an apology.&lt;sup id=&quot;fnref:1&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:1&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;1&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;

&lt;p&gt;GrabCar’s rate is determined when you make the booking. This eliminates the
need to worry about the taxi problems above. Even better, the rate is actually
cheaper than taxi. Personally I also enjoy the fact that GrabCar drivers are
more friendly.&lt;/p&gt;

&lt;p&gt;All in all, GrabCar is a better service in every way I can think of. Let the
competition happen.&lt;/p&gt;

&lt;h2 id=&quot;is-it-dangerous-for-grabcar-drivers&quot;&gt;Is It Dangerous For GrabCar Drivers?&lt;/h2&gt;

&lt;p&gt;Probably not. They know how do deal with this.&lt;/p&gt;

&lt;p&gt;According to a driver, the company provides insurance covering all the damage
and then more. There is also a kind of performance bonus which offsets the
amount taxi drivers get from haggling. Overall he seems pretty happy about his
better company.&lt;/p&gt;

&lt;p&gt;Questions or comments can go to &lt;a href=&quot;https://plus.google.com/+PhuHoangXuan/posts/gEhk2xJSmr5&quot;&gt;Google+&lt;/a&gt; :)&lt;/p&gt;

&lt;p&gt;talking about “GrabCar drivers” versus “taxi drivers” in general. It goes
  without saying that there are good and not so good people in any group.&lt;/p&gt;

&lt;div class=&quot;footnotes&quot; role=&quot;doc-endnotes&quot;&gt;
  &lt;ol&gt;
    &lt;li id=&quot;fn:1&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;Of course all in this post is very anecdotal and I’m somewhat guilty for &lt;a href=&quot;#fnref:1&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;
</description>
                <link>https://phunehehe.net/malaysia-grabcar-etiquette/</link>
                <guid>https://phunehehe.net/malaysia-grabcar-etiquette</guid>
                <pubDate>2015-12-19T00:00:00+00:00</pubDate>
        </item>

        <item>
                <title>OpenSSL Ciphers for Forward Secrecy</title>
                <description>&lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt;: current Nginx (1.10.1) and OpenSSL (1.0.2h) have good defaults.
None of this is needed anymore \o/&lt;/p&gt;

&lt;p&gt;In a search to ensure forward secrecy on all servers I manage, I needed to
figure out a list of ciphers I want to use. There are numerous articles on the
web that tells you what to use, but they are either vague about what really to
use, or give you a long list of things you don’t know or care about. After
quite some reading and experimenting I finally got a grasp of it, and the end
result is not as scary as what those articles say.&lt;/p&gt;

&lt;p&gt;There is also a tldr at the end for the lazy ;)&lt;/p&gt;

&lt;h2 id=&quot;forward-secrecy-and-cipher-suites&quot;&gt;Forward Secrecy and Cipher Suites&lt;/h2&gt;

&lt;p&gt;Forward secrecy means that in the event of a breach, a key stolen from either
side cannot be used to decrypt conversations that happened in the past.&lt;/p&gt;

&lt;p&gt;A cipher suite is a combination of a key exchange algorithm, an authentication
algorithm, an encryption algorithm and a MAC (message authentication code)
algorithm.&lt;/p&gt;

&lt;p&gt;In order to achieve forward secrecy, the connection needs to be protected by a
cipher suite that uses the DH key exchange algorithm, or its faster (but no
less secure) variant ECDH.&lt;/p&gt;

&lt;h2 id=&quot;meet-openssl&quot;&gt;Meet OpenSSL&lt;/h2&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;man openssl&lt;/code&gt; does not tell you how to list all the cipher suites using DH and
ECDH. The &lt;a href=&quot;https://www.openssl.org/docs/apps/ciphers.html&quot;&gt;documentation about ciphers&lt;/a&gt; does, to some extent, but for some
reason DH is sometimes called DHE and EDH, while ECDH is called ECDHE and ECDH
interchangeably. Ironically I didn’t even know that I was looking for DH and
ECDH. The blog posts I found imply that I can search using the command &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;openssl
ciphers -v &amp;lt;cipher_string&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;[sarcasm] Neat, now I just need to find out what my cipher string is…
[\sarcasm]&lt;/p&gt;

&lt;p&gt;After spending some time searching around I found the magic word: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;openssl
ciphers -v DH&lt;/code&gt;. This shows all cipher suites using DH.&lt;/p&gt;

&lt;h2 id=&quot;building-the-best-cipher-string&quot;&gt;Building the Best Cipher String&lt;/h2&gt;

&lt;p&gt;A list of cipher suites using DH and ECDH can be retrieved with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;openssl
ciphers -v 'ECDH DH'&lt;/code&gt;. Note that I deliberately put ECDH first, because it is
faster.&lt;/p&gt;

&lt;p&gt;That’s not it yet, because the list contains cipher suites that don’t have
authentication. You want to exclude those: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;openssl ciphers -v 'ECDH DH
!aNULL'&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;It also contains suites that use weak encryption algorithms. Fortunately and
conveniently there is a group containing suites using strong encryption
algorithm. You need to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;and&lt;/code&gt; it with your list: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;openssl ciphers -v 'HIGH+ECDH
HIGH+DH !aNULL'&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Finally, add other suites (that don’t support forward secrecy) so that you can
cater for old sucker clients:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;openssl ciphers &lt;span class=&quot;nt&quot;&gt;-v&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'HIGH+ECDH HIGH+DH HIGH !aNULL'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;tldr&quot;&gt;TLDR&lt;/h2&gt;

&lt;p&gt;Use this in Nginx:&lt;/p&gt;

&lt;div class=&quot;language-nginx highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;ssl_ciphers&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'HIGH+ECDH&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;HIGH+DH&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;HIGH&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;!aNULL'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This post is written with the help of:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.ssllabs.com/ssltest/analyze.html?d=phunehehe.net&quot;&gt;Qualys SSL Labs Server Test&lt;/a&gt;: If you haven’t analyze your site with
this tool, do it now. Thank me later.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://wiki.mozilla.org/Security/Server_Side_TLS&quot;&gt;Security/Server Side TLS - MozillaWiki&lt;/a&gt;: The article has a lot of
details regarding SSL and TLS, including how to configure Apache, Nginx and
other servers.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Questions or comments can go to &lt;a href=&quot;https://news.ycombinator.com/item?id=7593567&quot;&gt;Hacker News&lt;/a&gt; :)&lt;/p&gt;

</description>
                <link>https://phunehehe.net/openssl-ciphers-forward-secrecy/</link>
                <guid>https://phunehehe.net/openssl-ciphers-forward-secrecy</guid>
                <pubDate>2014-04-15T00:00:00+00:00</pubDate>
        </item>

        <item>
                <title>fooCam: Useful Enough to Be Copied</title>
                <description>&lt;p&gt;In August 2013, I started working on &lt;a href=&quot;https://github.com/phunehehe/fooCam&quot;&gt;fooCam&lt;/a&gt;. It’s a little app that
scratches my own itch. I quickly got the app to do everything I wanted it to
do, slapped the &lt;a href=&quot;/foss-license/&quot;&gt;MPL&lt;/a&gt; on it and submitted it to &lt;a href=&quot;https://f-droid.org/repository/browse/?fdid=net.phunehehe.foocam&quot;&gt;F-Droid&lt;/a&gt;. Without any
intention to monetize, I did not want to spend $25 to submit the app to Google
Play Store. All went well until today, GitHub user @programmin1 &lt;a href=&quot;https://github.com/phunehehe/fooCam/commit/9b93001648eb8e486653cd47e95577c3393c6ebc#commitcomment-5610911&quot;&gt;informed
me&lt;/a&gt; that the app is already on Google Play Store.&lt;/p&gt;

&lt;h2 id=&quot;clearing-the-doubts-about-opensource&quot;&gt;Clearing the Doubts about Opensource&lt;/h2&gt;

&lt;p&gt;My first reaction was to start calling names. Somebody changed the name and
icon of &lt;em&gt;my&lt;/em&gt; app and make it look like it’s theirs! They even set a price of
one dollar for the &lt;em&gt;free&lt;/em&gt; app! However, I soon realized that they are only able
to do that because I made it opensource in the first place. Was that a wrong
choice?&lt;/p&gt;

&lt;p&gt;After letting it sink in for a while, I came back to the same conclusion I had
before. The freedom to use the software is the whole point of free software. It
would be shameful of me to call myself an advocate of free software and not
understand this. I should feel happy now that the app I wrote for myself is
also useful enough for somebody to “steal” it.&lt;/p&gt;

&lt;p&gt;I’m not completely happy, however, so I decided I would contact the developer.&lt;/p&gt;

&lt;h2 id=&quot;getting-even&quot;&gt;Getting Even&lt;/h2&gt;

&lt;p&gt;I figured out the only problem I have with TheFoxute (the developer that
published my app) is that they should have given me credit and showed respect
for the license. Consulting the &lt;a href=&quot;http://www.mozilla.org/MPL/2.0/FAQ.html&quot;&gt;MPL FAQ&lt;/a&gt; I sent them this email:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Hello TheFoxute,&lt;/p&gt;

  &lt;p&gt;I have noticed that this app is built from my project &lt;a href=&quot;https://github.com/phunehehe/fooCam&quot;&gt;fooCam&lt;/a&gt;, available
under the terms of the &lt;a href=&quot;https://www.mozilla.org/MPL/2.0/&quot;&gt;Mozilla Public License&lt;/a&gt;. It is an opensource project
and you are welcome to use it. However, a few things seem to be missing and I
hope that you will rectify them in a timely fashion. According to the license,
you need to:&lt;/p&gt;

  &lt;ol&gt;
    &lt;li&gt;Disclose the source code. If you have not made any change to the source
will be enough.&lt;/li&gt;
    &lt;li&gt;If you have made changes to the source code, you need to release the
changes under the same license.&lt;/li&gt;
  &lt;/ol&gt;

  &lt;p&gt;Looking forward to hear back from you.&lt;/p&gt;

  &lt;p&gt;Phu&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;At least this gives me the good feeling of knowing that I have done the right
thing. I do hope that this is a misunderstanding and that TheFoxute will
respond to my requests. I really don’t want to be involved in legal stuff.&lt;/p&gt;

&lt;p&gt;Update: when I checked again on March 15, the app has been removed from Google
Play Store. Success! Kind of. I didn’t hear back from the developer.&lt;/p&gt;

&lt;h2 id=&quot;some-notes-about-google-play-store&quot;&gt;Some Notes about Google Play Store&lt;/h2&gt;

&lt;p&gt;Anyone can submit an app using any package name, for example
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;net.phunehehe.foocam&lt;/code&gt;, provided that it’s the first app to use that package
name. There is no way to claim parts of a package name, such as
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;net.phunehehe&lt;/code&gt;, to avoid “package name squatters”.&lt;/p&gt;

&lt;p&gt;You cannot leave a review after uninstalling an app. I can see that it makes
sense in some cases, but I feel like I should be able to review an app that I
have &lt;em&gt;just&lt;/em&gt; uninstalled. The fact that this is a paid app just makes it even
more inconvenient. I can’t install the app again to review and then refund a
second time.&lt;/p&gt;

&lt;p&gt;Questions or comments can go to &lt;a href=&quot;https://plus.google.com/+PhuHoangXuan/posts/BDSPsD9ryqz&quot;&gt;Google+&lt;/a&gt; :)&lt;/p&gt;

</description>
                <link>https://phunehehe.net/foocam-useful-enough-copied/</link>
                <guid>https://phunehehe.net/foocam-useful-enough-copied</guid>
                <pubDate>2014-03-09T00:00:00+00:00</pubDate>
        </item>

        <item>
                <title>Checking Amanda Backups</title>
                <description>&lt;p&gt;Recently I was taken aback to find that my &lt;a href=&quot;http://www.amanda.org/&quot;&gt;Amanda&lt;/a&gt; backups didn’t contain
files. Not even a single file! All that I had backed up were empty directories.
Luckily it was part of a check and I didn’t lose anything. The incident,
however, reminded me of the biggest problem with backups: you don’t want to
realize that your backups are broken when you need to restore something. That
motivated me to write a script that simulates what I will do when I need to get
a backed up version of something. Writing the script taught me a few things
about threading in Python, which was totally unexpected, but exciting.&lt;/p&gt;

&lt;h2 id=&quot;naive-solution&quot;&gt;Naive Solution&lt;/h2&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;amrecover&lt;/code&gt; is the utility that handles recovery of Amanda backups.
Unfortunately &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;amrecover&lt;/code&gt; is geared toward interactive use, and doesn’t provide
an easy way to automate. Nevertheless, the following worked:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;# List the files available for recovery in the &quot;disk&quot; /etc for localhost&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'
    sethost localhost
    setdisk /etc
    ls
'&lt;/span&gt; | amrecover daily
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;But here’s the problem: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;amrecover&lt;/code&gt;’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ls&lt;/code&gt; command does not traverse into
subdirectories, so the above won’t show &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/etc/amanda/amanda.conf&lt;/code&gt;, for example.
Looking through man pages and exercising google-fu didn’t help. “Fine, I’ll
walk the subdirectories myself”, but to do that I need something to hold the
directories and files. And because Bash is not exactly good at data structures,
it was time to switch to Python.&lt;/p&gt;

&lt;h2 id=&quot;same-in-python&quot;&gt;Same In Python&lt;/h2&gt;

&lt;p&gt;I had used Python to execute external programs before. To do what I wanted to
do, I would tell my Python script to execute &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;amrecover&lt;/code&gt;, store the files in a
list, then run &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;amrecover&lt;/code&gt; again for each subdirectories. So, for a start:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;# Same thing as the Bash script above
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Popen&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'amrecover'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'daily'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;stdin&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;PIPE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;stdout&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;PIPE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;stdin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'sethost localhost&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;stdin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'setdisk /etc&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;stdin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'ls&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;output&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;error&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;communicate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;output&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;error&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;getting-to-subdirectories&quot;&gt;Getting To Subdirectories&lt;/h2&gt;

&lt;p&gt;It was fairly easy to parse the output to list subdirectories and files:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;get_file_list&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dir_path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;files&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Popen&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'amrecover'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'daily'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;stdin&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;PIPE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;stdout&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;PIPE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;stdin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'sethost localhost&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;stdin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'setdisk /etc&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;stdin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'cd %s'&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dir_path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;stdin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'ls&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;output&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;communicate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;line&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;output&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;# Omitted: parse the output to get the_path
&lt;/span&gt;        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;the_path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;endswith&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sep&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;# Doh, a recursive call
&lt;/span&gt;            &lt;span class=&quot;n&quot;&gt;files&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;get_file_list&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;the_path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;# We found a file!
&lt;/span&gt;            &lt;span class=&quot;n&quot;&gt;files&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;the_path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;files&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;I tested and tested and tested. The code worked, and it worked consistently.
The only problem was that it seemed be slower than it should be. My guess was
that it called &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;amrecover&lt;/code&gt; multiple times, one for each subdirectory. That’s
not very efficient. If only I can read the output and add more input at will.
Too bad &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Popen.communicate&lt;/code&gt; won’t let me do that, because it waits until the
subprocess finishes.&lt;/p&gt;

&lt;h2 id=&quot;asynchronism&quot;&gt;Asynchronism&lt;/h2&gt;

&lt;p&gt;There are a few tricky things regarding reading from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;stdout&lt;/code&gt; and writing to
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;stdin&lt;/code&gt; of a subprocess at runtime:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;There is no way to find out whether there is anything in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;stdout&lt;/code&gt; worth
reading. You don’t want to wait forever to read nothing.&lt;/li&gt;
  &lt;li&gt;You need the subprocess to die eventually, either by closing &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;stdin&lt;/code&gt; or by
sending an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;exit&lt;/code&gt; command.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A timeout should be able to eliminate both problems, so I wanted to do this:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;# Made-up code, won't work
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;files&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Popen&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'amrecover'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'daily'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;stdin&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;PIPE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;stdout&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;PIPE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;try&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;line&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;read_line_with_timeout&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;stdout&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;timeout&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;# Omitted: parse line to get the_path
&lt;/span&gt;        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;the_path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;endswith&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sep&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;stdin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'cd %s'&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;the_path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;stdin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'ls&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;# We found a file!
&lt;/span&gt;            &lt;span class=&quot;n&quot;&gt;files&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;the_path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;except&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Timeout&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;pass&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;But that &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;read_line_with_timeout&lt;/code&gt; ability is nowhere to be found. I also tried
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fcntl&lt;/code&gt; but it didn’t help because I do want the reading code to block until it
has read everything there is to read.&lt;/p&gt;

&lt;p&gt;In the end I gave up in finding a solution that works without threads, and
decided to try a multi-thread method that looked clean described in this
&lt;a href=&quot;http://stackoverflow.com/a/4896288/168034&quot;&gt;StackOverflow answer&lt;/a&gt;. The idea is that you will use a thread to read the
subprocess’s output and put it in a &lt;a href=&quot;http://docs.python.org/2/library/queue.html&quot;&gt;Queue&lt;/a&gt;. The main thread will then use
the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;get&lt;/code&gt; method of the queue, which has a timeout.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;read_pipe_to_lines&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;stdout&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lines&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;# This is a blocking read, it waits until it receives something
&lt;/span&gt;        &lt;span class=&quot;n&quot;&gt;line&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;stdout&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;readline&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;lines&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;put&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;line&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;lines&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Queue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;read_thread&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Thread&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;target&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;read_pipe_to_lines&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;stdout&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lines&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;read_thread&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;daemon&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;True&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;read_thread&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;start&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;try&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;line&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lines&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;# Omitted: do things with line
&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;except&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Empty&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'no more line to read'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;fake-it-to-make-it&quot;&gt;Fake It To Make It&lt;/h1&gt;

&lt;p&gt;After finishing the lengthy multi-thread implementation, I looked back and
found that the code lacks a quality that I always look for: intuition. It
doesn’t work the way a human will work with the shell. A human will type a
command, wait for it to finish and decide what command to use next. The problem
is that it’s hard for my program to know when one command finishes. A human can
look at the prompt, the reappearance of the prompt means that the previous
command has finished. However, the prompt is neither in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;stdout&lt;/code&gt; nor in
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;stderr&lt;/code&gt;. If that can be detected somehow, I can write a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;read_until_prompt&lt;/code&gt;
function that doesn’t need a timeout and doesn’t use another thread.&lt;/p&gt;

&lt;p&gt;But I can fake it, hah! By trying to execute a useless command and detecting
its output, I can use it as a delimiter. The only annoyance is that now the
read function needs access to both &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;stdin&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;stdout&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;read_all&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;in_stream&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;out_stream&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;# Add some junk input to get a delimiter
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;INVALID_DIR&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'intentionally-invalid'&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;INVALID_RES&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'Invalid directory - %s'&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;INVALID_DIR&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;enter_line&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;in_stream&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'cd %s'&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;INVALID_DIR&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;# Real reading here
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;lines&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;line&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;out_stream&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;readline&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;strip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;line&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;INVALID_RES&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lines&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;lines&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;line&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And the rest is just &lt;a href=&quot;https://github.com/phunehehe/check-amanda&quot;&gt;straightforward Python&lt;/a&gt;. In the end all the
“optimizations” did not solve the performance problem with very large volumes.
I changed to random the subdirectory to traverse instead of traversing
everything. I lost the number-of-files statistics, but the script is fast
enough to be practical.&lt;/p&gt;

&lt;p&gt;I can finally submit to Hacker News. Your comments can go &lt;a href=&quot;https://news.ycombinator.com/item?id=6658727&quot;&gt;there&lt;/a&gt; :)&lt;/p&gt;

</description>
                <link>https://phunehehe.net/checking-amanda-backups/</link>
                <guid>https://phunehehe.net/checking-amanda-backups</guid>
                <pubDate>2013-11-02T00:00:00+00:00</pubDate>
        </item>

        <item>
                <title>Docker vs Chef and Vagrant</title>
                <description>&lt;p&gt;&lt;a href=&quot;https://www.docker.io/&quot;&gt;Docker&lt;/a&gt; seems to be the new hotness in the devops world. It runs
applications in isolated containers, providing the benefits of virtualization
without the hassle of virtual machines. Today is a Cogini Hackday, and I chose
to dive into Docker. This is still a very young project, but it has the
potential to change the way we do software development and deployment. I’m
going to compare Docker with Cogini’s current best practice :)&lt;/p&gt;

&lt;h2 id=&quot;chef-and-vagrant&quot;&gt;Chef and Vagrant&lt;/h2&gt;

&lt;p&gt;At Cogini we use &lt;a href=&quot;http://www.vagrantup.com/&quot;&gt;Vagrant&lt;/a&gt; and &lt;a href=&quot;http://www.opscode.com/chef/&quot;&gt;Chef&lt;/a&gt; extensively for both development
and deployment. We maintain &lt;a href=&quot;https://github.com/phunehehe/chef-cookbooks&quot;&gt;cookbooks&lt;/a&gt; that can be used in Vagrant
machines, development, staging and production servers.&lt;/p&gt;

&lt;p&gt;Developers and designers can clone their project and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;vagrant up&lt;/code&gt;, skipping the
hours (and sometimes days) needed to set up the right development environment
for the project.&lt;/p&gt;

&lt;p&gt;Sysadmins can clone a project on a server and provision with Chef, avoiding
human errors like “Oh I forgot to set up the cron job”. The cookbooks also
serve as deployment notes.&lt;/p&gt;

&lt;p&gt;The Chef+Vagrant workflow is roughly as follow:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Identify project components (data stores, programming languages, libraries,
development tools etc.)&lt;/li&gt;
  &lt;li&gt;Write Chef cookbooks that combine all components into a ready-to-use
Vagrant machine&lt;/li&gt;
  &lt;li&gt;Get the source code and provision your own Vagrant machine&lt;/li&gt;
  &lt;li&gt;Perform development tasks, modifying the cookbooks as needed&lt;/li&gt;
  &lt;li&gt;Deploy by cloning/updating source code and (re)provision&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Whatever can be done with Docker, I wish to keep the nice productivity
enhancements that Chef and Vagrant give us.&lt;/p&gt;

&lt;h2 id=&quot;meet-docker&quot;&gt;Meet Docker&lt;/h2&gt;

&lt;p&gt;When I first saw Docker, it was hard to resist the obvious thought “I already
have Chef and Vagrant” but I was inspired to see a &lt;a href=&quot;https://news.ycombinator.com/item?id=6291549&quot;&gt;comment&lt;/a&gt; of the Vagrant
creator on Docker. I mean this guy Mitchell who created Vagrant which is
awesome is saying that Docker is awesome, so it must be pretty good right?
Here is what I found interesting in Docker, initially:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Because it doesn’t involve virtual machines, startup time and resource usage
is much better than Vagrant.&lt;/li&gt;
  &lt;li&gt;Because it eliminates the need to start from an empty server, you no longer
have to spend time writing, testing and debugging Chef cookbooks.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With a view to compare with the existing workflow, I tried to come up with a
Docker workflow and here is what I figured out after following the &lt;a href=&quot;http://docs.docker.io/en/latest/examples/&quot;&gt;examples&lt;/a&gt;:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Identify project components (data stores, programming languages, libraries,
development tools etc.)&lt;/li&gt;
  &lt;li&gt;Prepare a Docker image with all components&lt;/li&gt;
  &lt;li&gt;Get the Docker image and start doing development tasks, creating new images
as configurations change&lt;/li&gt;
  &lt;li&gt;Deploy by getting an image and starting a container from it&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Does Chef fit in here? I think I’d still use Chef to set up the images, just so
that I have an audit trail of changes to the image. Or maybe I can set up the
images manually, track the changes elsewhere and forget about Chef.&lt;/p&gt;

&lt;h2 id=&quot;workflow-comparison&quot;&gt;Workflow Comparison&lt;/h2&gt;

&lt;p&gt;Where Docker is better:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;No need for provisioning. Having to wait for 5-15 minutes before you con
start/continue working is not too bad, but annoying and unbearable at
times.&lt;/li&gt;
  &lt;li&gt;Snapshots for free. Every time you use &lt;a href=&quot;http://docs.docker.io/en/latest/commandline/command/run/&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;run&lt;/code&gt;&lt;/a&gt; on an image a new
container is created. Each container is essentially a snapshot of the
application state that includes all configurations and data so it’s easy to
roll back.&lt;/li&gt;
  &lt;li&gt;A new deployment model. Right now it’s not really ready, but it full of
potential. More on this below.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Where Chef+Vagrant is better:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Keep source code and deployment information (cookbooks) in the same place.
It’s easy to overlook this, but I have found it incredibly useful to have
easily accessible deployment notes without having to hunt down someone who
&lt;em&gt;may&lt;/em&gt; know the details.&lt;/li&gt;
  &lt;li&gt;Stable and standardized tools. As of this writing some pretty useful
functionalities are still missing from Docker (for example, the ability to
&lt;a href=&quot;https://github.com/dotcloud/docker/issues/905&quot;&gt;copy files&lt;/a&gt; from the Docker host to a container). Even when Vagrant was
version 0.x everything was almost perfectly usable. I guess being similar
to the conventional VPS model helped.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;interesting-potential&quot;&gt;Interesting Potential&lt;/h2&gt;

&lt;p&gt;For obvious reasons I won’t attempt to use Docker in a production environment
yet, but I can already imagine what might happen.&lt;/p&gt;

&lt;p&gt;Docker will do to VPS what VPS did to dedicated servers. When people realize
they can do everything they need on a cheap and flexible VPS, many will choose
that instead of dedicated hardware. Then many people choose to use &lt;a href=&quot;https://www.heroku.com/&quot;&gt;Heroku&lt;/a&gt;
so that they don’t have to manage their own VPS. It remains to be seen how
Heroku will compete with the opensource &lt;a href=&quot;https://flynn.io/&quot;&gt;Flynn&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Separation of each container also sounds nice. Maybe the next trend will be one
container for each service, instead of one VPS for each app. And then each of
those services can be scaled at will, not affecting others. So you can start
with one Docker host running multiple services each in its own container. Then
when you need, add another Docker host and have more containers running the
services needing a boost. Of course I’m assuming you design your app to scale
out ;)&lt;/p&gt;

&lt;p&gt;Questions or comments can go to &lt;a href=&quot;https://plus.google.com/112644450727344747165/posts/RWhmXqgnxSL&quot;&gt;Google+&lt;/a&gt; :)&lt;/p&gt;

</description>
                <link>https://phunehehe.net/docker-vs-chef-vagrant/</link>
                <guid>https://phunehehe.net/docker-vs-chef-vagrant</guid>
                <pubDate>2013-09-27T00:00:00+00:00</pubDate>
        </item>

        <item>
                <title>On Being Perfect</title>
                <description>&lt;p&gt;A long long time ago…&lt;/p&gt;

&lt;p&gt;Actually not that long ago, a friend and I were talked about perfection. During
the half-joke half-serious discussion we came across the term “perfectly
stupid”, which seemed to be one of the floweriest insults we knew at the time
(we were secondary school kids at time, by the way). Since then I have heard of
many jokes aiming at people’s lack of brilliance, though I haven’t heard any
that I would call “perfect”. The word “perfect” is just that far away for me.&lt;/p&gt;

&lt;p&gt;Then my friend suddenly thought about reversing the words, so we had “stupidly
perfect” and start to wonder, which of the two combination carried more insult.&lt;/p&gt;

&lt;h2 id=&quot;stupidly-perfect&quot;&gt;Stupidly Perfect&lt;/h2&gt;

&lt;p&gt;It’s easy to imagine something that is close to being “perfectly stupid”. Just
about any joke involving blondes will try to say something about
intelligence.&lt;sup id=&quot;fnref:1&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:1&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;1&lt;/a&gt;&lt;/sup&gt; But how about “stupidly perfect”? It turned out, there isn’t
a lack of things that belong in this category. They are just a tiny bit harder
to see. Here are some examples:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Putting plastic film on your phone to “protect” its surfaces: so you will be
using subpar surfaces instead, which is easier to get scratches, doesn’t feel
as good, makes your device looks dirty. And finally when you decide to take
the plastic off, the phone is already too old and you want another one.&lt;sup id=&quot;fnref:2&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:2&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;2&lt;/a&gt;&lt;/sup&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/Premature_optimization#When_to_optimize&quot;&gt;Premature optimization&lt;/a&gt;: trying to make a program “faster” by using
optimization techniques too early in the development process without proper
testing, thus delaying features, introducing bugs and probably actually
hurting performance.&lt;/li&gt;
  &lt;li&gt;Making a product that “everyone wants to use”: using least common
denominators, resulting in a product with a lot of features, but all of which
are mediocre so nobody wants to use it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here’s the common theme: if someone is trying to do everything in the best way
possible, ey will miss the important items and/or the important timing. In the
end, ey may create something that would be great when ey started, but because
things have changed, the result won’t benefit anyone. The problem may have
solved itself, someone else may have dominated the market, or the person simply
runs out of energy and gives up.&lt;/p&gt;

&lt;h2 id=&quot;perfectionism-as-an-excuse&quot;&gt;Perfectionism As An Excuse&lt;/h2&gt;

&lt;p&gt;If you are like me, you like to tell yourself “I want this to be perfect”. So
you stop at everything that is not perfect &lt;em&gt;enough&lt;/em&gt; and tweak it. The thing
will most likely be perfect for a while until you get bored of it. Then you
will be too lazy to commit to the same level of perfection, but too proud to
make your spiritual child imperfect.&lt;/p&gt;

&lt;p&gt;The cure: get over it. There is no such thing as perfection, and perfectionism
is just an excuse for procrastination. You’ve gotta do what you’ve gotta do.
Here are a few clues:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Make a todo list. Sort the items by priorities. Chew the list from top to
bottom. I can’t stress this enough. If you don’t have a todo list for your
project, it’s not even a proper project, let alone perfection.&lt;sup id=&quot;fnref:3&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:3&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;3&lt;/a&gt;&lt;/sup&gt;&lt;/li&gt;
  &lt;li&gt;Keep your items big/smalls enough. If an item takes more than half a day you
will never start doing it. If an item takes less then half an hour to do you
will be wasting time putting it in the list. Hint: todo lists don’t have to
be perfect ;)&lt;/li&gt;
  &lt;li&gt;Be ready to delay/drop items down below in the list. It’s not going to feel
good, one way to go about it is to tell yourself about the more important
items that you have finished. After all, you have a limit of energy, and it’s
better to drop the less important stuff.&lt;/li&gt;
  &lt;li&gt;Look out for trade-offs that you are making. Fact: you are going to make
trade-offs, whether you know it or not. The trade-offs that you don’t
recognize will hurt you. The concious trade-offs will help you beat yourself.
The canonical response to “Never compromise!” is “Never say never!”.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Questions or comments can go to &lt;a href=&quot;https://plus.google.com/112644450727344747165/posts/jbVKqb4UgTS&quot;&gt;Google+&lt;/a&gt; :)&lt;/p&gt;

&lt;div class=&quot;footnotes&quot; role=&quot;doc-endnotes&quot;&gt;
  &lt;ol&gt;
    &lt;li id=&quot;fn:1&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;For the record I don’t think making jokes of blondes is nice. &lt;a href=&quot;#fnref:1&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:2&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;I know quite a few people who would disagree but hey, let’s agree to
  disagree. &lt;a href=&quot;#fnref:2&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:3&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;&lt;a href=&quot;https://workflowy.com/?ref=8c27b3e&quot;&gt;WorkFlowy&lt;/a&gt; (affiliate link) seems to be the perfect online todo list
  for me. If you don’t know what to use yet, give it a try! &lt;a href=&quot;#fnref:3&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;
</description>
                <link>https://phunehehe.net/perfectionism/</link>
                <guid>https://phunehehe.net/perfectionism</guid>
                <pubDate>2013-09-03T00:00:00+00:00</pubDate>
        </item>

        <item>
                <title>Powerline Revisited</title>
                <description>&lt;p&gt;After &lt;a href=&quot;/powerline&quot;&gt;incorporating Powerline&lt;/a&gt; into my dotfiles I got a very good looking
prompt for Bash and Zsh, plus a nice status line for Tmux and Vim. I quickly
noticed some performance problems, but they didn’t seem serious and I
considered that an acceptable trade-off for features.&lt;/p&gt;

&lt;p&gt;Two weeks into Powerline, I still felt the &lt;a href=&quot;/powerline#the-ugly&quot;&gt;ugly spots&lt;/a&gt; that I pointed out:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;High prompt generation time&lt;/li&gt;
  &lt;li&gt;Unhandled &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Ctrl+c&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;argparse&lt;/code&gt; needs to be installed for Python older than 2.7&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Unfortunately I did find more bad news.&lt;/p&gt;

&lt;h2 id=&quot;more-performance-problems&quot;&gt;More Performance Problems&lt;/h2&gt;

&lt;p&gt;Resource usage is not a problem on my hefty laptop, but it really takes toll on
e.g. a VPS with 512 MB of RAM.  Waiting for a few seconds to see the prompt was
a normal sight on my Raspberry Pi. On remote servers I could occasionally
overwhelm the whole system just by starting Tmux.&lt;sup id=&quot;fnref:1&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:1&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;1&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;

&lt;p&gt;The first time that happened I suspected something else, tried to figure out
what caused all the thrashing, and was surprised to see a lot of Powerline
processes. Apparently Powerline had started some task in the background, and
started a second task when the first hadn’t finished yet.  Consequently the
system slowed down even more, and the third and forth tasks were started
shortly afterwards, none of which stands a chance to finish.&lt;sup id=&quot;fnref:4&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:4&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;2&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;

&lt;p&gt;The “fix” for the overwhelming problem required me to ultimately remove the
informational section from Tmux’s status line. I didn’t find a reasonable way
to improve general performance.&lt;/p&gt;

&lt;p&gt;But that wasn’t a fix. Without the informational section, Powerline’s role in
my Tmux is just eye candy. I suppose I can do that with a little RTFM, maybe
stealing the styles from Powerline along the way if I need to.&lt;/p&gt;

&lt;h2 id=&quot;on-ease-of-integration&quot;&gt;On Ease of Integration&lt;/h2&gt;

&lt;p&gt;Let me get this right: Powerline is super simple to use. The documentation is
also crystal clear and very detailed. With my &lt;a href=&quot;https://github.com/phunehehe/terminal-dotfiles&quot;&gt;dotfiles&lt;/a&gt;, it becomes a part
of my other configurations, and using it is just a matter of one
copy-and-paste. The problem is not with Powerline, but rather with the
assortment of systems that I work with.&lt;/p&gt;

&lt;p&gt;The requirement of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;argparse&lt;/code&gt; is the first sad thing. I support quite a few
servers running Ubuntu 10.04 and Centos 5 and they don’t come with Python 2.7.
On the one hand, I can see that Powerline is a thriving project that wish to
use the best technology available. One the other hand, Ubuntu 10.04 and Centos
5 haven’t reached their end of life yet, and thus it makes sense for me to
support them.&lt;/p&gt;

&lt;p&gt;The second sad thing is with Arch Linux. I use &lt;a href=&quot;http://archlinuxarm.org/&quot;&gt;Arch Linux ARM&lt;/a&gt; on my
Raspberry Pi. Arch Linux comes with Python 3 so it doesn’t need &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;argparse&lt;/code&gt;.
However, Vim in Arch Linux isn’t built with Python support, so I can’t use
Powerline there. I could still can try to install another version of Vim or
build one myself, but that leads to the next problem.&lt;/p&gt;

&lt;p&gt;I don’t feel comfortable using a set of dotfiles that is more complicated than
useful. The many issues with Powerline aren’t impossible to resolve, but they
keep reminding me what I have done to my dotfiles:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;I &lt;a href=&quot;https://powerline.readthedocs.org/en/latest/installation/linux.html?highlight=fontconfig#fontconfig&quot;&gt;included&lt;/a&gt; some modified fonts with special Unicode glyphs&lt;/li&gt;
  &lt;li&gt;I have a nice prompt, but if I copy something from my terminal that contains
the prompt to someone else, they see garbage instead&lt;/li&gt;
  &lt;li&gt;I occasionally need to install a Python package using admin permissions&lt;/li&gt;
  &lt;li&gt;I might have to install a custom-built version of Vim&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In retrospect, almost every time I “fixed” something in my Powerline setup, I
also added something into my dotfiles, that I don’t consider good for dotfiles.
That’s a step in the wrong direction.&lt;/p&gt;

&lt;h2 id=&quot;peace-of-mind&quot;&gt;Peace of Mind&lt;/h2&gt;

&lt;p&gt;So I decided to write my own prompts and status lines again, learning from the
way Powerline works. The result is very pleasing and well worth the time.&lt;/p&gt;

&lt;p&gt;Here are the features added to my Bash/Zsh prompt, compared to my previous
prompt:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Use the same code for both Bash and Zsh&lt;/li&gt;
  &lt;li&gt;Be smart when printing current working directory&lt;sup id=&quot;fnref:2&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:2&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;3&lt;/a&gt;&lt;/sup&gt;&lt;/li&gt;
  &lt;li&gt;Show the exit code of the previous command, but only if it’s non-zero&lt;/li&gt;
  &lt;li&gt;Use hand-picked colors&lt;sup id=&quot;fnref:3&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:3&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;4&lt;/a&gt;&lt;/sup&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For Tmux, I make it exactly what it should be: a color theme.&lt;/p&gt;

&lt;p&gt;As for Vim, I should do the same thing as I did to Tmux, but now I’m feeling
that the default status line is pretty enough. Yes that’s right I don’t even
revert to vim-powerline, now that I have realized it’s the contents that should
get the emphasis, not the status line.&lt;/p&gt;

&lt;p&gt;Questions or comments can go to &lt;a href=&quot;https://plus.google.com/112644450727344747165/posts/fRvXhhzzu1R&quot;&gt;Google+&lt;/a&gt; :)&lt;/p&gt;

&lt;div class=&quot;footnotes&quot; role=&quot;doc-endnotes&quot;&gt;
  &lt;ol&gt;
    &lt;li id=&quot;fn:1&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;And I use Tmux all the time, so this is a big deal. &lt;a href=&quot;#fnref:1&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:4&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;I’m almost sure there is a name for this situation, but what is it? &lt;a href=&quot;#fnref:4&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:2&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;Print at most 3 slashes, so &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/home/phunehehe&lt;/code&gt; becomes &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/home/phunehehe&lt;/code&gt;,
  but &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/home/phunehehe/.config/autostart&lt;/code&gt; becomes
  &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;phunehehe/.config/autostart&lt;/code&gt;. &lt;a href=&quot;#fnref:2&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:3&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;Many thanks to &lt;a href=&quot;http://www.calmar.ws/vim/256-xterm-24bit-rgb-color-chart.html&quot;&gt;256 xterm colors and their equivalent RGB&lt;/a&gt;. &lt;a href=&quot;#fnref:3&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;
</description>
                <link>https://phunehehe.net/powerline-revisited/</link>
                <guid>https://phunehehe.net/powerline-revisited</guid>
                <pubDate>2013-08-24T00:00:00+00:00</pubDate>
        </item>

        <item>
                <title>Best Sorting Algorithm</title>
                <description>&lt;p&gt;Today while doing some reading I came across some comparison of
&lt;a href=&quot;http://en.wikipedia.org/wiki/Quicksort&quot;&gt;quicksort&lt;/a&gt; and &lt;a href=&quot;http://en.wikipedia.org/wiki/Merge_sort&quot;&gt;merge
sort&lt;/a&gt;. Then a question struck me: what
is the “best” sorting algorithm? I know I had thought of that question time and
again, but I have never got down to figure it out. Well, until today.&lt;/p&gt;

&lt;p&gt;Wikipedia has a &lt;a href=&quot;http://en.wikipedia.org/wiki/Sorting_algorithm#Comparison_of_algorithms&quot;&gt;table comparing a bunch of
algorithms&lt;/a&gt;,
that can be sorted by each property (best case, average case, worst case,
memory usage and stability). However, I find that a bit of work is needed to
figure out the “best”.&lt;/p&gt;

&lt;h2 id=&quot;set-up&quot;&gt;Set Up&lt;/h2&gt;

&lt;p&gt;The method is simple: among the many algorithms, find the ones that has the
best value for the best case, plus the best value for the average case, plus
the best value for the worst case and so on. The best values are as follow:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Best case: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Average cases: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n log n&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Worst case: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n log n&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Memory usage: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Stability: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Yes&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;results&quot;&gt;Results&lt;/h2&gt;

&lt;p&gt;And… there is no algorithms that comes up with all the best values! Okay
that’s to be expected, otherwise sorting algorithms would be too boring. People
need to make trade-offs.&lt;/p&gt;

&lt;p&gt;UPDATE (2015/09/13): Adrian Mejia &lt;a href=&quot;https://plus.google.com/u/0/+PhuHoangXuan/posts/NpdN9vr3asD&quot;&gt;pointed out&lt;/a&gt; that the table has since
been updated, and now &lt;a href=&quot;https://en.wikipedia.org/wiki/Block_sort&quot;&gt;block sort&lt;/a&gt; is the clear winner!!!&lt;/p&gt;

&lt;p&gt;If you can trade stability,
&lt;a href=&quot;http://en.wikipedia.org/wiki/Smoothsort&quot;&gt;smoothsort&lt;/a&gt; is the winner. If you can
trade memory usage, try &lt;a href=&quot;http://en.wikipedia.org/wiki/Timsort&quot;&gt;timsort&lt;/a&gt; or
&lt;a href=&quot;http://en.wikipedia.org/wiki/Tree_sort&quot;&gt;tree sort&lt;/a&gt;. If you need both stability
and memory efficiency, you will have to give up on the average and worse case:
use &lt;a href=&quot;http://en.wikipedia.org/wiki/Insertion_sort&quot;&gt;insertion sort&lt;/a&gt;, &lt;a href=&quot;http://en.wikipedia.org/wiki/Gnome_sort&quot;&gt;gnome
sort&lt;/a&gt;, &lt;a href=&quot;http://en.wikipedia.org/wiki/Cocktail_sort&quot;&gt;cocktail
sort&lt;/a&gt; or &lt;a href=&quot;http://en.wikipedia.org/wiki/Bubble_sort&quot;&gt;bubble
sort&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Why isn’t quicksort here? Or merge sort? Not sure, but my guess is that it’s
some implementation details.&lt;/p&gt;

&lt;p&gt;Questions or comments can go to
&lt;a href=&quot;https://plus.google.com/u/0/112644450727344747165/posts/NpdN9vr3asD&quot;&gt;Google+&lt;/a&gt; :)&lt;/p&gt;

</description>
                <link>https://phunehehe.net/best-sorting-algorithm/</link>
                <guid>https://phunehehe.net/best-sorting-algorithm</guid>
                <pubDate>2013-06-30T00:00:00+00:00</pubDate>
        </item>

        <item>
                <title>Powerline: Power-up for Your Terminal</title>
                <description>&lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt;: &lt;a href=&quot;/powerline-revisited&quot;&gt;Powerline Revisited&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A while ago I came across &lt;a href=&quot;https://github.com/Lokaltog/vim-powerline&quot;&gt;Powerline for Vim&lt;/a&gt;, which is a plugin that shows
a pretty status line in Vim. Needless to say, the default status line is awful,
and I am too lazy to set up my own status line. Even if I did, my status line
would probably not look as good as this. I grabbed vim-powerline feeling
thankful, like every time I grab a Vim plugin.&lt;/p&gt;

&lt;p&gt;I did notice, however, that Powerline for Vim has a big deprecation warning in
the home page, pointing to &lt;a href=&quot;https://github.com/Lokaltog/powerline&quot;&gt;Powerline&lt;/a&gt; as the replacement. Unfortunately,
the new Powerline required Python 2.7, and I’d need to install something
system-wide using Pip. Meh, that’s against my idea of having per-user
configurations. Users should be able to configure their applications without
having to obtain administrative access.&lt;/p&gt;

&lt;p&gt;Recently, having some free time, I decided to hack Powerline eliminate the need
to install it system-wide.&lt;/p&gt;

&lt;h2 id=&quot;the-hack&quot;&gt;The Hack&lt;/h2&gt;

&lt;p&gt;It turned out, for Tmux and Vim no fix was needed.  For Bash and Zsh the fix
involves only a few lines of changes. I don’t really care about other things
(yet?), so it was time to get my changes merged upstream. The process was
simple: create a GitHub &lt;a href=&quot;https://github.com/Lokaltog/powerline/issues/527&quot;&gt;issue&lt;/a&gt;, then submit a &lt;a href=&quot;https://github.com/Lokaltog/powerline/pull/528&quot;&gt;pull request&lt;/a&gt;, but I did
learn a few things:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Bash &lt;em&gt;sometimes&lt;/em&gt; will assign &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-bash&lt;/code&gt; to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$0&lt;/code&gt;, so &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$BASH_SOURCE&lt;/code&gt; is a more
  reliable way to find the script file being executed.&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Zsh’s history expansion has modifiers that can be used to expand paths,
  convert lowercase to uppercase, quote, unquote and more. For example in Zsh&lt;/p&gt;

    &lt;div class=&quot;language-zsh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$0&lt;/span&gt;:A:h:h:h:h/scripts/powerline
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;

    &lt;p&gt;is roughly equivalent to this piece in Bash:&lt;/p&gt;

    &lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;dirname&lt;/span&gt;
    &lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;dirname&lt;/span&gt;
        &lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;dirname&lt;/span&gt;
            &lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;dirname&lt;/span&gt; &lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;realpath&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$BASH_SOURCE&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;)))))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;

    &lt;p&gt;(eat that, Bash).&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The default prompt doesn’t show the number of background tasks, so I added
&lt;a href=&quot;https://github.com/Lokaltog/powerline/pull/596&quot;&gt;that&lt;/a&gt;. I also make the prompt left-only, as Bash does not support prompt on
the right.&lt;/p&gt;

&lt;p&gt;As usual, all settings, tweaks and hacks can be found in my
&lt;a href=&quot;https://github.com/phunehehe/terminal-dotfiles&quot;&gt;dotfiles&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;the-ugly&quot;&gt;The Ugly&lt;/h2&gt;

&lt;p&gt;Now the pull request is still being reviewed, but Powerline is already powering
a lot of the applications I use: Bash, Tmux, Vim and Zsh. The style looks
great, but there are still caveats:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Prompt generation time is too high. It’s still under an acceptable limit but
I can notice the delay before the prompt is printed. This becomes clear when
I hold down the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Enter&lt;/code&gt; key. I guess this is a case of sacrificing
performance for features.&lt;/li&gt;
  &lt;li&gt;Signals aren’t being handled correctly. Hitting &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Ctrl+c&lt;/code&gt; repeatedly would
cause an exception. There is already an &lt;a href=&quot;https://github.com/Lokaltog/powerline/issues/509&quot;&gt;issue&lt;/a&gt; for this. Hopefully it
will be resolved soon, or maybe I’ll find some time to hack it.&lt;/li&gt;
  &lt;li&gt;On some older machines that don’t have Python 2.7, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;argparse&lt;/code&gt; needs to be
installed system-wide via Pip. I hate this, but at least it’s still better
than installing some random thing from the Internet. Again, a fun hack
waiting in store.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Questions or comments can go to &lt;a href=&quot;https://plus.google.com/112644450727344747165/posts/dDEms991kXi&quot;&gt;Google+&lt;/a&gt; :)&lt;/p&gt;

</description>
                <link>https://phunehehe.net/powerline/</link>
                <guid>https://phunehehe.net/powerline</guid>
                <pubDate>2013-06-04T00:00:00+00:00</pubDate>
        </item>

        <item>
                <title>Good Laziness, Bad Laziness</title>
                <description>&lt;p&gt;People say that it’s good for a sysadmin to be lazy. Fair enough, a lazy
sysadmin has more incentive to automate things. The same can be said about
programmers, or IT workers in general. After a while everyone starts to go
around saying that ey is proud to be a lazy person. Employers start to look at
laziness as a desirable trait.&lt;/p&gt;

&lt;p&gt;However, let’s not forget that being a lazy in the normal sense is not always a
good thing. I differentiate between three types of laziness:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;One that encourage people to either automate the task, or to find and solve
the root of the problem, so that the task is no longer necessary&lt;/li&gt;
  &lt;li&gt;One that discourage people from doing something, because the reward is not
worth the trouble&lt;/li&gt;
  &lt;li&gt;One that lead people to get others to do the particular task&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;(1) is obviously a good thing. I think (2) is also a good thing: you shouldn’t
have to do what you don’t have to do, if it’s not bringing you satisfaction.
Maybe someone will say that (2) is neutral, that’s not wrong either.&lt;/p&gt;

&lt;p&gt;But (3) is just selfishness. People want the result, but don’t want to spend
the effort, so they try to push the effort to others. I hate those people.&lt;/p&gt;

&lt;p&gt;Or maybe I’m just making this up and there is only one kind of laziness and the
three are just different ways people react.&lt;/p&gt;
</description>
                <link>https://phunehehe.net/good-lazy-bad-lazy/</link>
                <guid>https://phunehehe.net/good-lazy-bad-lazy</guid>
                <pubDate>2013-04-05T00:00:00+00:00</pubDate>
        </item>

        <item>
                <title>Checking for Multiple URLs in Nagios</title>
                <description>&lt;p&gt;The default HTTP check in Nagios only checks for one URL, which is the IP
address of the host. In a world where everyone is using name-based virtual
hosts this is not very useful. Moreover, in some cases you may need to check
different URLs of the same site to ensure that it’s working. This post will
show you how to do that.&lt;/p&gt;

&lt;p&gt;There are a few things that need to be glued together. You need (1) a script
that takes a list of URLs, checks them and returns status codes as appropriate,
(2) a Nagios command that uses the script, (3) a host definition that uses the
command for checking.&lt;/p&gt;

&lt;h2 id=&quot;the-script&quot;&gt;The Script&lt;/h2&gt;

&lt;p&gt;This script take a comma-delimited list of URLs, each has the form of
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;example.com/home/index&lt;/code&gt; (no &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;http://&lt;/code&gt; is needed or supported). Normally I
would make each URL a separate parameter, but Nagios doesn’t support argument
list so I’d live with this.&lt;/p&gt;

&lt;p&gt;The host is considered “up” if &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;check_http&lt;/code&gt; on all URLs returns “OK”, otherwise
the first failure (warning or critical) will be the status of the host.&lt;/p&gt;

&lt;p&gt;Save the script in a place you like, for example &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/etc/nagios3/check_urls&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;#!/bin/bash&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;# Split URLs by comma&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;urls&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;//,/ &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;for &lt;/span&gt;url &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$urls&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;do
    &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;hostname&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;%%/*&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[[&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$url&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;/&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;]]&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;then&lt;/span&gt;
        &lt;span class=&quot;c&quot;&gt;# Domain plus path, like example.com/path&lt;/span&gt;
        &lt;span class=&quot;nv&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;/&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;#*/&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;
        &lt;span class=&quot;c&quot;&gt;# Just domain, like example.com&lt;/span&gt;
        &lt;span class=&quot;nv&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;/
    &lt;span class=&quot;k&quot;&gt;fi
    &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;/usr/lib/nagios/plugins/check_http &lt;span class=&quot;nt&quot;&gt;--hostname&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$hostname&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;--url&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$path&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;status&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$?&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[[&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$status&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-ne&lt;/span&gt; 0 &lt;span class=&quot;o&quot;&gt;]]&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;then&lt;/span&gt;
        &lt;span class=&quot;c&quot;&gt;# First warning is the final result&lt;/span&gt;
        &lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$url&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;: &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$result&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;
        &lt;span class=&quot;nb&quot;&gt;exit&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$status&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;fi
done

&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;All URLs OK: &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$urls&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;the-command&quot;&gt;The Command&lt;/h2&gt;

&lt;p&gt;Command definition can go anywhere that Nagios reads, for example
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/etc/nagios3/conf.d/commands.cfg&lt;/code&gt;.  Remember to change the path to
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;check_urls&lt;/code&gt; if you save it in another place.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;define command {
    command_name check_urls
    command_line /etc/nagios3/check_urls $_HOSTURLS$
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;the-host&quot;&gt;The Host&lt;/h2&gt;

&lt;p&gt;Again, this definition can go anywhere that Nagios reads, for example
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/etc/nagios3/conf.d/hosts.cfg&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;define host {
    host_name     example-host
    alias         My Example
    address       123.123.123.123
    check_command check_urls
    _urls         my-blog.com,my-api.com/check
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;See the funny &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;_urls&lt;/code&gt; bit? It’s a &lt;a href=&quot;http://nagios.sourceforge.net/docs/3_0/customobjectvars.html&quot;&gt;custom macro&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Questions or comments can go to &lt;a href=&quot;https://plus.google.com/112644450727344747165/posts/FTWQCufzTKG&quot;&gt;Google+&lt;/a&gt; :)&lt;/p&gt;

</description>
                <link>https://phunehehe.net/check-multiple-urls-nagios/</link>
                <guid>https://phunehehe.net/check-multiple-urls-nagios</guid>
                <pubDate>2013-03-24T00:00:00+00:00</pubDate>
        </item>

        <item>
                <title>Choosing an Opensource License</title>
                <description>&lt;p&gt;First of all I’m not a lawyer :) I am merely recording how I have chosen the
&lt;a href=&quot;https://en.wikipedia.org/wiki/Mozilla_Public_License&quot;&gt;Mozilla Public License (MPL)&lt;/a&gt; as my favorite opensource license.&lt;sup id=&quot;fnref:4&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:4&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;1&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;

&lt;p&gt;I am starting a toy project that is to be pushed to GitHub as I work on it. So
I register an account (yeah I haven’t got a GitHub account until now) and poke
around. Having been familiar Google Code for a while, I look for a place to
pick a license for my project&lt;sup id=&quot;fnref:1&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:1&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;2&lt;/a&gt;&lt;/sup&gt;. That option is nowhere to be found.  Instead
the &lt;a href=&quot;https://help.github.com/articles/github-terms-of-service/&quot;&gt;Terms of Service&lt;/a&gt; basically says that I’m on my own with licenses. It’s
probably a good time to learn about them.&lt;/p&gt;

&lt;p&gt;Being a Gentoo user who has happened to read about &lt;a href=&quot;https://wiki.gentoo.org/wiki/GLEP:23&quot;&gt;handling licenses&lt;/a&gt;, I
immediately think of these two lists:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://opensource.org/licenses/alphabetical&quot;&gt;OSI-approved “open source” licenses&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://www.gnu.org/licenses/license-list.html&quot;&gt;FSF-approved “free software” licenses&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are just too many. Luckily I found on the website of the Open Source
Initiative, &lt;a href=&quot;https://opensource.org/licenses/category&quot;&gt;Licenses that are popular and widely used or with strong
communities&lt;/a&gt;. That’s a list short enough to drill down.&lt;/p&gt;

&lt;p&gt;To speed up the process, I decide on the characteristics of the license of my
dream, then filter the list. I want a license that:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Requires those who benefit from my code to contribute back if modifications
are made.&lt;/li&gt;
  &lt;li&gt;Does not force the same license on everything that uses the code like the
famous GPL.&lt;sup id=&quot;fnref:2&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:2&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;3&lt;/a&gt;&lt;/sup&gt;&lt;/li&gt;
  &lt;li&gt;Is preferably compatible with most if not all other opensource licenses,
including the GPL.&lt;/li&gt;
  &lt;li&gt;Is easy to read and understand (added after reading the terms of the LGPL).&lt;/li&gt;
  &lt;li&gt;Has anything else a license should give me: I shall have credit for my
work, people don’t sue me, blah blah blah.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For each license in the list, I go to Wikipedia to find out the easy details
and read the full text of the interesting ones:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;del&gt;Apache License&lt;/del&gt;: Too permissive&lt;/li&gt;
  &lt;li&gt;&lt;del&gt;BSD Licenses&lt;/del&gt;: Too permissive&lt;/li&gt;
  &lt;li&gt;&lt;del&gt;GNU General Public License (GPL)&lt;/del&gt;: Too restrictive&lt;/li&gt;
  &lt;li&gt;&lt;del&gt;GNU Lesser General Public License (LGPL)&lt;/del&gt;: Too complicated. I
  think it takes both a lawyer and a good software engineer to understand this
  text. When I try to read it I understand why it was previously named “Library
  General Public License”. I don’t want to take this route.&lt;/li&gt;
  &lt;li&gt;&lt;del&gt;MIT license&lt;/del&gt;: Too permissive&lt;/li&gt;
  &lt;li&gt;Mozilla Public License (MPL)&lt;/li&gt;
  &lt;li&gt;Common Development and Distribution License (CDDL)&lt;/li&gt;
  &lt;li&gt;Eclipse Public License (EPL)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So here comes the little comparison of the 3 short-listed candidates:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;I don’t like the fact that the CDDL comes from Sun, which is dead. I think
  I’m being paranoid, but I’m uncomfortable to hear that I won’t receive
  updates for the license.&lt;sup id=&quot;fnref:3&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:3&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;4&lt;/a&gt;&lt;/sup&gt;&lt;/li&gt;
  &lt;li&gt;I can’t seem to grasp the implications the EPL placed on patents and the US
  copyright law’s definition of &lt;a href=&quot;https://en.wikipedia.org/wiki/Derivative_work&quot;&gt;derivative works&lt;/a&gt; (too long isn’t it?).&lt;/li&gt;
  &lt;li&gt;Both the CDDL and the EPL have some controversy associated with them. I
  lost the links though :(&lt;/li&gt;
  &lt;li&gt;Both the CDDL and the EPL are GPL-incompatible. The MPL comes with a thing
  called the &lt;a href=&quot;https://en.wikipedia.org/wiki/Multi-licensing#License_compatibility&quot;&gt;tri-license&lt;/a&gt;, which sounds crazy at first, but I have found
  that I like it. It allows people to use it as GPL if they so wish.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So there you go, MPL all the things!&lt;/p&gt;

&lt;div class=&quot;footnotes&quot; role=&quot;doc-endnotes&quot;&gt;
  &lt;ol&gt;
    &lt;li id=&quot;fn:4&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;This post was recovered from an &lt;a href=&quot;https://web.archive.org/web/20130306061222/http://phunehehe.is-great.org/&quot;&gt;archive.org snapshot&lt;/a&gt; of my old blog
  which was free and is now dead (yeah, free hosting). &lt;a href=&quot;#fnref:4&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:1&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;Google Code had a place where you can choose the license for your
  project. I have a link to that, but it’s broken now because Google Code
  is dead apparently. &lt;a href=&quot;#fnref:1&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:2&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;I later found that these two requirements essentially mean &lt;a href=&quot;https://en.wikipedia.org/wiki/Copyleft#Strong_and_weak_copyleft&quot;&gt;weak
  copyleft&lt;/a&gt;. &lt;a href=&quot;#fnref:2&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:3&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;This later sort of rings true when an update is made to the MPL (2.0)
  that greatly improved it. &lt;a href=&quot;#fnref:3&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;
</description>
                <link>https://phunehehe.net/foss-license/</link>
                <guid>https://phunehehe.net/foss-license</guid>
                <pubDate>2011-02-21T00:00:00+00:00</pubDate>
        </item>

        <item>
                <title>File sharing with Python's built-in HTTP server</title>
                <description>&lt;p&gt;Every once in a while you need to copy files from one computer to
another. Across different operating systems, a &lt;a href=&quot;https://en.wikipedia.org/wiki/Sneakernet&quot;&gt;sneakernet&lt;/a&gt; (read:
copying files using a USB flash drive) seems to be the best option
because most (if not all) computers can handle a USB. However, the
process may become cumbersome because:&lt;sup id=&quot;fnref:1&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:1&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;1&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;You need to copy from the first computer to the USB, then from the
USB to the second computer (then delete the copy in the USB).&lt;/li&gt;
  &lt;li&gt;If what you are trying to transfer is bigger than your USB drive
you’ll have to split and join.&lt;/li&gt;
  &lt;li&gt;You might forget some files on the first trip and have to repeat
the whole process.&lt;/li&gt;
  &lt;li&gt;You don’t have a portable USB disk drive :(&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Enter Python, where the batteries are included! Here are the steps to
share your files with Python’s built-in &lt;a href=&quot;https://docs.python.org/2/library/simplehttpserver.html&quot;&gt;SimpleHTTPServer&lt;/a&gt;:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Install Python on the first computer (the one with the files to
share). This is mainly for &lt;a href=&quot;https://www.python.org/downloads/windows/&quot;&gt;Windows&lt;/a&gt; because most Linux
distributions as well as Mac OS X include Python. Yeah!&lt;/li&gt;
  &lt;li&gt;Put the two computers into the
same network. For example, by connecting them using a LAN cable and
setting their IP addresses to 192.168.1.1 and 192.168.1.2
respectively.&lt;/li&gt;
  &lt;li&gt;On the first computer (with IP address 192.168.1.1), open up a
command prompt, navigate to the folder where the files are
kept. Execute the command &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;python -m SimpleHTTPServer&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Now on the second computer open up a web browser (any web browser:
Firefox, Chromium, even IE) and visit and download your files at
http://192.168.1.1:8000&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Bonus: &lt;a href=&quot;https://gist.github.com/willurd/5720255&quot;&gt;Big list of http static server one-liners&lt;/a&gt; :)&lt;/p&gt;

&lt;div class=&quot;footnotes&quot; role=&quot;doc-endnotes&quot;&gt;
  &lt;ol&gt;
    &lt;li id=&quot;fn:1&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;This post was recovered from an &lt;a href=&quot;https://web.archive.org/web/20130306061222/http://phunehehe.is-great.org/&quot;&gt;archive.org snapshot&lt;/a&gt; of my
  old blog which was free and is now dead (yeah, free hosting). &lt;a href=&quot;#fnref:1&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;
</description>
                <link>https://phunehehe.net/file-sharing-sneakernets/</link>
                <guid>https://phunehehe.net/file-sharing-sneakernets</guid>
                <pubDate>2011-01-03T00:00:00+00:00</pubDate>
        </item>


</channel>
</rss>
