Procházet zdrojové kódy

Add active terminal post

Thomas Dy před 10 roky
rodič
revize
a1dc60d834

+ 106 - 0
output/2015/index.html

@@ -0,0 +1,106 @@
+<!DOCTYPE html>
+<html prefix="og: http://ogp.me/ns# article: http://ogp.me/ns/article# " vocab="http://ogp.me/ns" lang="en">
+<head>
+    <meta charset="utf-8">
+    <meta name="viewport" content="width=device-width">
+    <title>Posts for year 2015 | Pleasant Programmer</title>
+
+    
+        <link href="../assets/css/rst.css" rel="stylesheet" type="text/css">
+        <link href="../assets/css/code.css" rel="stylesheet" type="text/css">
+        <link href="../assets/css/theme.css" rel="stylesheet" type="text/css">
+            <link href="../assets/css/custom.css" rel="stylesheet" type="text/css">
+
+    
+            <link rel="alternate" type="application/rss+xml" title="RSS" href="../rss.xml">
+
+      <link rel="canonical" href="http://pleasantprogrammer.com/2015/index.html">
+
+
+
+
+    <script type="text/javascript" src="//use.typekit.net/iwm5axp.js"></script>
+    <script type="text/javascript">try{Typekit.load();}catch(e){}</script>
+
+    
+        <!--[if lt IE 9]><script src="../assets/js/html5.js"></script><![endif]-->
+
+    
+
+
+
+
+</head>
+<body>
+<a href="#content" class="sr-only sr-only-focusable">Skip to main content</a>
+    
+    <header id="header" role="banner">
+        <div class="thomas">
+            <img src="../assets/img/thomas.gif" alt="DJ THOMAS IN DA HAUS">
+            <img src="../assets/img/thomas.png" alt="Pleasant Programmer">
+        </div>
+        
+    <h1 id="brand"><a href="http://pleasantprogrammer.com/" title="Pleasant Programmer" rel="home">
+
+        <span id="blog-title">Pleasant Programmer</span>
+    </a></h1>
+
+        
+
+        
+    <nav id="menu" role="navigation">
+    <ul>
+            <li class="twitter"><a href="http://twitter.com/pleasantprog">@pleasantprog</a></li>
+                <li><a href="../archive.html">Archives</a></li>
+                <li><a href="../categories/index.html">Tags</a></li>
+                <li><a href="../rss.xml">RSS</a></li>
+    
+    
+    </ul>
+    </nav>
+
+    </header>
+    
+
+    <div id="container">
+         <main id="content" role="main">
+            
+<article class="listpage">
+    <header>
+        <h1>Posts for year 2015</h1>
+    </header>
+    <ul class="postlist">
+        <li>
+<a href="../posts/is-my-terminal-window-active.html" class="listtitle">Is My Terminal Window Active?</a> <time class="listdate" datetime="2015-06-07T16:20:45+08:00" title="2015-06-07 16:20">2015-06-07 16:20</time>
+</li>
+    </ul>
+</article>
+
+         </main>
+         
+        <footer id="footer" role="contentinfo">
+            <p><a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/deed.en_US"><img alt="CC-BY-SA" style="border-width:0" src="http://i.creativecommons.org/l/by-sa/3.0/80x15.png"></a> © 2015 Thomas Dy - Powered by <a href="http://getnikola.com">Nikola</a></p>
+            
+        </footer>
+
+    </div>
+    
+    
+    
+    
+
+    <script src="../assets/js/konami.js"></script>
+    <script src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
+    <script>
+        var easter_egg = new Konami();
+        easter_egg.code = function() {
+            $(".thomas").toggleClass("whoa");
+            $("body").scrollTop(0);
+        }
+        easter_egg.load();
+
+        // love you, thomas!
+        // yours, @_phi + @meggykawsek
+    </script>
+</body>
+</html>

+ 3 - 0
output/archive.html

@@ -71,6 +71,9 @@
     </header>
     <ul class="postlist">
         <li>
+<a href="2015/index.html">2015</a>
+        </li>
+<li>
 <a href="2013/index.html">2013</a>
     </li>
 </ul>

+ 1 - 1
output/categories/lets-debug.xml

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<?xml-stylesheet type="text/xsl" href="../assets/xml/rss.xsl" media="all"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Pleasant Programmer (lets-debug)</title><link>http://pleasantprogrammer.com/</link><description></description><atom:link rel="self" href="http://pleasantprogrammer.com/categories/lets-debug.xml" type="application/rss+xml"></atom:link><language>en</language><lastBuildDate>Sat, 17 Jan 2015 15:33:15 GMT</lastBuildDate><generator>http://getnikola.com/</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>GTFS Editor</title><link>http://pleasantprogrammer.com/posts/gtfs-editor.html</link><dc:creator>Thomas Dy</dc:creator><description>&lt;div&gt;&lt;p&gt;Link: &lt;a href="https://github.com/conveyal/gtfs-editor"&gt;https://github.com/conveyal/gtfs-editor&lt;/a&gt;&lt;/p&gt;
+<?xml-stylesheet type="text/xsl" href="../assets/xml/rss.xsl" media="all"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Pleasant Programmer (lets-debug)</title><link>http://pleasantprogrammer.com/</link><description></description><atom:link href="http://pleasantprogrammer.com/categories/lets-debug.xml" type="application/rss+xml" rel="self"></atom:link><language>en</language><lastBuildDate>Sun, 07 Jun 2015 08:05:41 GMT</lastBuildDate><generator>http://getnikola.com/</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>GTFS Editor</title><link>http://pleasantprogrammer.com/posts/gtfs-editor.html</link><dc:creator>Thomas Dy</dc:creator><description>&lt;div&gt;&lt;p&gt;Link: &lt;a href="https://github.com/conveyal/gtfs-editor"&gt;https://github.com/conveyal/gtfs-editor&lt;/a&gt;&lt;/p&gt;
 &lt;p&gt;&lt;strong&gt;TL;DR&lt;/strong&gt; they really meant under development&lt;/p&gt;
 &lt;p&gt;When I first saw the source of GTFS Editor, I was ecstatic. They used &lt;a href="http://playframework.com/"&gt;Play framework&lt;/a&gt;!!! Not only that, they're targeting PostgreSQL as the main database. Those are our favorite tools for building webapps at By Implication. I was a bit sad though, when I saw it was on the 1.x release of Play though. I did have some experience with that release, but not as much compared to 2.x.&lt;/p&gt;
 &lt;p&gt;Getting it to actually run though, wasn't very pleasant. The initial setup was easy enough. Get &lt;a href="http://www.playframework.com/download"&gt;Play 1.2.5&lt;/a&gt;, install Postgres with PostGIS, clone the repo and create backing database in Postgres. Some minor additional steps you need are to create the PostGIS extension on the database. The schema is automatically generated and applied by Play so that should be all that's necessary. Wonderful. Then, run play, open a browser, go to &lt;a href="http://localhost:9000"&gt;http://localhost:9000&lt;/a&gt;, compilation error. Fantastic.&lt;/p&gt;

+ 1 - 1
output/categories/philippine-transit-app.xml

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<?xml-stylesheet type="text/xsl" href="../assets/xml/rss.xsl" media="all"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Pleasant Programmer (philippine-transit-app)</title><link>http://pleasantprogrammer.com/</link><description></description><atom:link rel="self" href="http://pleasantprogrammer.com/categories/philippine-transit-app.xml" type="application/rss+xml"></atom:link><language>en</language><lastBuildDate>Sat, 17 Jan 2015 15:33:15 GMT</lastBuildDate><generator>http://getnikola.com/</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>Geocoding Services</title><link>http://pleasantprogrammer.com/posts/geocoding-services.html</link><dc:creator>Thomas Dy</dc:creator><description>&lt;div&gt;&lt;p&gt;A key component for any routing service is being able to do geocoding. Most people who are looking for routes most probably don't know exactly where their start and end points are on the map. Even then, manually looking for a location on a map is a time-consuming task.&lt;/p&gt;
+<?xml-stylesheet type="text/xsl" href="../assets/xml/rss.xsl" media="all"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Pleasant Programmer (philippine-transit-app)</title><link>http://pleasantprogrammer.com/</link><description></description><atom:link href="http://pleasantprogrammer.com/categories/philippine-transit-app.xml" type="application/rss+xml" rel="self"></atom:link><language>en</language><lastBuildDate>Sun, 07 Jun 2015 08:05:40 GMT</lastBuildDate><generator>http://getnikola.com/</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>Geocoding Services</title><link>http://pleasantprogrammer.com/posts/geocoding-services.html</link><dc:creator>Thomas Dy</dc:creator><description>&lt;div&gt;&lt;p&gt;A key component for any routing service is being able to do geocoding. Most people who are looking for routes most probably don't know exactly where their start and end points are on the map. Even then, manually looking for a location on a map is a time-consuming task.&lt;/p&gt;
 &lt;p&gt;The gold standard for doing geocoding right now is Google Maps. It's hard to find a better location search experience. If they actually provided routing for jeeps here in the Philippines, I imagine there wouldn't be &lt;em&gt;that&lt;/em&gt; much you could do for the competition.&lt;/p&gt;
 &lt;p&gt;When the competition started though, I took it as a challenge to avoid Google Maps as much as possible. I wanted to see how much is currently possible with other options such as OpenStreetMap. In fact, OSM does have a geocoding service called &lt;a href="http://nominatim.openstreetmap.org"&gt;Nominatim&lt;/a&gt;.&lt;/p&gt;
 &lt;p&gt;Sadly, for a mapping app, what you want to do is not simply just geocoding. With geocoding, you take an address and turn it into coordinates. When you want to search for a place in a mapping app, you take part of an address, infer the rest of it, and give the user options to choose from.&lt;/p&gt;

+ 3 - 0
output/categories/programming.html

@@ -77,6 +77,9 @@
     </header>
     <ul class="postlist">
         <li>
+<a href="../posts/is-my-terminal-window-active.html" class="listtitle">Is My Terminal Window Active?</a> <time class="listdate" datetime="2015-06-07T16:20:45+08:00" title="2015-06-07 16:20">2015-06-07 16:20</time>
+</li>
+        <li>
 <a href="../posts/geocoding-services.html" class="listtitle">Geocoding Services</a> <time class="listdate" datetime="2013-09-25T12:26:59+08:00" title="2013-09-25 12:26">2013-09-25 12:26</time>
 </li>
         <li>

+ 16 - 13
output/categories/programming.xml

@@ -1,5 +1,19 @@
 <?xml version="1.0" encoding="utf-8"?>
-<?xml-stylesheet type="text/xsl" href="../assets/xml/rss.xsl" media="all"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Pleasant Programmer (programming)</title><link>http://pleasantprogrammer.com/</link><description></description><atom:link rel="self" href="http://pleasantprogrammer.com/categories/programming.xml" type="application/rss+xml"></atom:link><language>en</language><lastBuildDate>Sat, 17 Jan 2015 15:33:15 GMT</lastBuildDate><generator>http://getnikola.com/</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>Geocoding Services</title><link>http://pleasantprogrammer.com/posts/geocoding-services.html</link><dc:creator>Thomas Dy</dc:creator><description>&lt;div&gt;&lt;p&gt;A key component for any routing service is being able to do geocoding. Most people who are looking for routes most probably don't know exactly where their start and end points are on the map. Even then, manually looking for a location on a map is a time-consuming task.&lt;/p&gt;
+<?xml-stylesheet type="text/xsl" href="../assets/xml/rss.xsl" media="all"?><rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>Pleasant Programmer (programming)</title><link>http://pleasantprogrammer.com/</link><description></description><atom:link href="http://pleasantprogrammer.com/categories/programming.xml" rel="self" type="application/rss+xml"></atom:link><language>en</language><lastBuildDate>Sun, 07 Jun 2015 08:22:42 GMT</lastBuildDate><generator>http://getnikola.com/</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>Is My Terminal Window Active?</title><link>http://pleasantprogrammer.com/posts/is-my-terminal-window-active.html</link><dc:creator>Thomas Dy</dc:creator><description>&lt;div&gt;&lt;p&gt;I've been working in OSX for almost 3 years now, but I recently switched back to Linux because of all the problems people encountered with Yosemite. There are some things I missed from OSX though. One of which is &lt;a href="https://github.com/marzocchi/zsh-notify"&gt;zsh-notify&lt;/a&gt;. It's a zsh plugin that alerts you if your long-running task is complete, and whether it failed or not.&lt;/p&gt;
+&lt;p&gt;It's pretty convenient when you're compiling something and then go on to browse reddit while waiting. Usually, I spend too much time just reading and forget about the compilation entirely. With the plugin, I get the notification and maybe go back to work.&lt;/p&gt;
+&lt;p&gt;One nice feature it has is that if you're currently looking at the terminal window of the job that just finished, it won't notify you. It only notifies on windows that aren't currently in focus. To do this, it has to actually talk to Terminal.app or iTerm2 to see if the window and tab are active.&lt;/p&gt;
+&lt;p&gt;This is alright in OSX since those 2 are the generally most used terminal emulators. On Linux though, everyone has their own favorite terminal. Given that, I figured I could probably rely on talking to X to see if the window is active instead of each single terminal emulator. X can't tell if the tab is active though, but I don't use tabs in my current setup so it should still be good.&lt;/p&gt;
+&lt;h3&gt;xdotool&lt;/h3&gt;
+&lt;p&gt;&lt;a href="http://superuser.com/questions/382616/detecting-currently-active-window"&gt;Preliminary research&lt;/a&gt; reveals that we can easily get what the active window is with xdotool. &lt;code&gt;xdotool getactivewindow&lt;/code&gt; gives us the X window id of the active one. Now all we need is a way to get the window id of the terminal we're in.&lt;/p&gt;
+&lt;h3&gt;First Attempt: $WINDOWID&lt;/h3&gt;
+&lt;p&gt;Apparently, xterm and similar terminal emulators define an environment variable called &lt;code&gt;$WINDOWID&lt;/code&gt; with the window id of the terminal. Obviously, this is too good to be true. In xterm and konsole the &lt;code&gt;$WINDOWID&lt;/code&gt; was correct, but in VTE-based terminal emulators, &lt;code&gt;$WINDOWID&lt;/code&gt; had the wrong value. In terminology, it didn't define &lt;code&gt;$WINDOWID&lt;/code&gt; altogether. So &lt;code&gt;$WINDOWID&lt;/code&gt; wasn't going to work.&lt;/p&gt;
+&lt;h3&gt;Second Attempt: xdotool search $MAGIC&lt;/h3&gt;
+&lt;p&gt;My second idea was that you can use zsh to change the window title to a magic number and then just check if the active window is the same one as the window with the magic number. This sort of worked for most terminals, except konsole which does whatever it wants with the window title. There's also the problem of some zsh configs automatically settings the window title to the current command.&lt;/p&gt;
+&lt;p&gt;In hindsight, I could probably have just done &lt;code&gt;xdotool search --name xdotool&lt;/code&gt; since in most cases, when you run the search, zsh or konsole will set the window name to the current command. Maybe that's another option I can explore some day.&lt;/p&gt;
+&lt;h3&gt;Third Attempt: $PPID&lt;/h3&gt;
+&lt;p&gt;My third idea was another environment variable called &lt;code&gt;$PPID&lt;/code&gt;, which is the process id of the parent of the shell. As it happens, the parent is the window containing the zsh instance. This is actually pretty consistent across most terminals. The only problem was if you launched zsh from another shell since your new zsh's parent will now be another zsh instance instead of an X window.&lt;/p&gt;
+&lt;p&gt;At first glance, launching zsh within zsh doesn't seem like something most people would do, but this is what happens when you run screen or tmux. To work around this, we can actually just save the original &lt;code&gt;$PPID&lt;/code&gt; in a different variable and use that instead.&lt;/p&gt;
+&lt;p&gt;Now that we have the PID of the window from zsh, we can once again use xdotool to get the PID of the current active window with &lt;code&gt;xdotool getactivewindow getwindowpid&lt;/code&gt;. We just simply compare that with our &lt;code&gt;$PPID&lt;/code&gt; and we can tell if we're in an active window or not. Overall, this approach worked surprisingly well so that's the final solution I went with.&lt;/p&gt;&lt;/div&gt;</description><category>programming</category><guid>http://pleasantprogrammer.com/posts/is-my-terminal-window-active.html</guid><pubDate>Sun, 07 Jun 2015 08:20:45 GMT</pubDate></item><item><title>Geocoding Services</title><link>http://pleasantprogrammer.com/posts/geocoding-services.html</link><dc:creator>Thomas Dy</dc:creator><description>&lt;div&gt;&lt;p&gt;A key component for any routing service is being able to do geocoding. Most people who are looking for routes most probably don't know exactly where their start and end points are on the map. Even then, manually looking for a location on a map is a time-consuming task.&lt;/p&gt;
 &lt;p&gt;The gold standard for doing geocoding right now is Google Maps. It's hard to find a better location search experience. If they actually provided routing for jeeps here in the Philippines, I imagine there wouldn't be &lt;em&gt;that&lt;/em&gt; much you could do for the competition.&lt;/p&gt;
 &lt;p&gt;When the competition started though, I took it as a challenge to avoid Google Maps as much as possible. I wanted to see how much is currently possible with other options such as OpenStreetMap. In fact, OSM does have a geocoding service called &lt;a href="http://nominatim.openstreetmap.org"&gt;Nominatim&lt;/a&gt;.&lt;/p&gt;
 &lt;p&gt;Sadly, for a mapping app, what you want to do is not simply just geocoding. With geocoding, you take an address and turn it into coordinates. When you want to search for a place in a mapping app, you take part of an address, infer the rest of it, and give the user options to choose from.&lt;/p&gt;
@@ -307,15 +321,4 @@ Caused by: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
 &lt;p&gt;&lt;img alt="UP Katipunan Route" src="http://pleasantprogrammer.com/galleries/transit/upkatipunan.jpg"&gt;&lt;/p&gt;
 &lt;p&gt;From what they said during the launch, most of the route data was collected by getting a person to ride a jeep with a smartphone. That would explain why the coordinates aren't that exact. Even then, it would have been nice if they at least cleaned up the data by moving the stops to the road. They would have had to go over them to name the stops anyway.&lt;/p&gt;
 &lt;h4&gt;Conclusion&lt;/h4&gt;
-&lt;p&gt;Overall though, I really like OpenTripPlanner. It handles most of the hard parts of the challenge. It provides a REST API for doing routing with the GTFS + OSM data. There's also a lot of potential for additional open source work. A lot can be done to improve the default webapp. Adding a default location searcher would greatly improve usability. Adding in the route viewing features of OneBusAway would also be nice. Alternatively, you could even write your own client that just interfaces with the API.&lt;/p&gt;&lt;/div&gt;</description><category>philippine-transit-app</category><category>programming</category><guid>http://pleasantprogrammer.com/posts/open-trip-planner.html</guid><pubDate>Tue, 09 Jul 2013 15:16:12 GMT</pubDate></item><item><title>One Bus (or maybe Jeep) Away</title><link>http://pleasantprogrammer.com/posts/one-bus-or-maybe-jeep-away.html</link><dc:creator>Thomas Dy</dc:creator><description>&lt;div&gt;&lt;p&gt;Link: &lt;a href="http://onebusaway.org/"&gt;http://onebusaway.org/&lt;/a&gt;&lt;/p&gt;
-&lt;p&gt;&lt;strong&gt;TL;DR&lt;/strong&gt; no routing; useless in Philippines&lt;/p&gt;
-&lt;p&gt;OneBusAway is a transit information app. It provides data on what bus stops are near you, which buses pass by. You can also get schedules and the route of a particular bus given the number. It can also provide realtime updates like how many minutes until the next bus arrives. It does not, however, provide routing. There is no support for providing directions to get from point A to point B.&lt;/p&gt;
-&lt;p&gt;It's comparable to what you get in some bus stops abroad. You'd get a vicinity map and a list of buses passing through the stop. You might also get the times when the next buses will pass. It's useful for locals who already know how to get around, and want to avoid waiting for the bus. But it's not particularly good for people who want to know how to get around the city.&lt;/p&gt;
-&lt;p&gt;OneBusAway is quite comprehensive in its platform support though. There is a webapp, apps for iOS, Android and Windows Phone, as well as SMS and Voice support. This would all be nice but we don't have the necessary infrastructure yet in the Philippines. We don't have bus or jeepney stops. We also wouldn't have realtime data to make the app particularly useful.&lt;/p&gt;
-&lt;p&gt;You can try it out for yourself by following their &lt;a href="https://github.com/OneBusAway/onebusaway-application-modules/wiki/OneBusAway-Quickstart-Guide"&gt;Quickstart Guide&lt;/a&gt;. One caveat is you will have to add &lt;code&gt;-P tripEntriesFactory.throwExceptionOnInvalidStopToShapeMappingException=false&lt;/code&gt; when building the bundle. This has to do with the OneBusAway having difficulty matching the &lt;a href="https://github.com/OneBusAway/onebusaway-application-modules/wiki/Stop-to-Shape-Matching"&gt;stops to the shape data&lt;/a&gt;.&lt;/p&gt;
-&lt;p&gt;Here's some screenshots of the app with the Philippine data. Notice how you only see the stops but there isn't a line for the route. This is a problem with our GTFS data. Also, at some points it's hard to tell where the jeep is going to pass since there isn't any indication of order either. This is more of a OneBusAway problem. It usually expects there to be shape data available.&lt;/p&gt;
-&lt;p&gt;&lt;a href="http://pleasantprogrammer.com/galleries/transit/onebusaway1.png"&gt;&lt;img alt="OneBusAway" src="http://pleasantprogrammer.com/galleries/transit/onebusaway1.png" title="All the stops along Katipunan Avenue are named Katipunan Avenue."&gt;&lt;/a&gt;&lt;/p&gt;
-&lt;p&gt;It doesn't really handle too many routes passing through a stop. The list just overflows past the bubble. You can still actually read it by panning the map. It's just a bit weird though.&lt;/p&gt;
-&lt;p&gt;If you also noticed, there are usually 2 of each route. This is how the jeepney data was modeled as jeep routes might be different going one way and going back. This isn't the case for all jeeps though, so it might also be an implementation issue with the GTFS editor.&lt;/p&gt;
-&lt;p&gt;&lt;a href="http://pleasantprogrammer.com/galleries/transit/onebusaway2.png"&gt;&lt;img alt="OneBusAway" src="http://pleasantprogrammer.com/galleries/transit/onebusaway2.png"&gt;&lt;/a&gt;&lt;/p&gt;
-&lt;p&gt;&lt;a href="http://pleasantprogrammer.com/galleries/transit/onebusaway3.png"&gt;&lt;img alt="OneBusAway" src="http://pleasantprogrammer.com/galleries/transit/onebusaway3.png"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</description><category>philippine-transit-app</category><category>programming</category><guid>http://pleasantprogrammer.com/posts/one-bus-or-maybe-jeep-away.html</guid><pubDate>Mon, 08 Jul 2013 17:53:59 GMT</pubDate></item></channel></rss>
+&lt;p&gt;Overall though, I really like OpenTripPlanner. It handles most of the hard parts of the challenge. It provides a REST API for doing routing with the GTFS + OSM data. There's also a lot of potential for additional open source work. A lot can be done to improve the default webapp. Adding a default location searcher would greatly improve usability. Adding in the route viewing features of OneBusAway would also be nice. Alternatively, you could even write your own client that just interfaces with the API.&lt;/p&gt;&lt;/div&gt;</description><category>philippine-transit-app</category><category>programming</category><guid>http://pleasantprogrammer.com/posts/open-trip-planner.html</guid><pubDate>Tue, 09 Jul 2013 15:16:12 GMT</pubDate></item></channel></rss>

+ 1 - 1
output/categories/sysadmin.xml

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<?xml-stylesheet type="text/xsl" href="../assets/xml/rss.xsl" media="all"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Pleasant Programmer (sysadmin)</title><link>http://pleasantprogrammer.com/</link><description></description><atom:link rel="self" href="http://pleasantprogrammer.com/categories/sysadmin.xml" type="application/rss+xml"></atom:link><language>en</language><lastBuildDate>Sat, 17 Jan 2015 15:33:15 GMT</lastBuildDate><generator>http://getnikola.com/</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>Removing PLDTMyDSLBiz from the ZyXEL P-2612HNU</title><link>http://pleasantprogrammer.com/posts/removing-pldtmydslbiz-from-the-zyxel-p-2612hnu.html</link><dc:creator>Thomas Dy</dc:creator><description>&lt;div&gt;&lt;p&gt;I've always thought that people were just too lazy to change their SSIDs when I see "PLDTMyDSLBizCafeJapan". It became apparent when we got our own PLDT line that it was because the bundled router/modem &lt;em&gt;does not&lt;/em&gt; allow you to remove the prefix.&lt;/p&gt;
+<?xml-stylesheet type="text/xsl" href="../assets/xml/rss.xsl" media="all"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Pleasant Programmer (sysadmin)</title><link>http://pleasantprogrammer.com/</link><description></description><atom:link href="http://pleasantprogrammer.com/categories/sysadmin.xml" type="application/rss+xml" rel="self"></atom:link><language>en</language><lastBuildDate>Sun, 07 Jun 2015 08:05:41 GMT</lastBuildDate><generator>http://getnikola.com/</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>Removing PLDTMyDSLBiz from the ZyXEL P-2612HNU</title><link>http://pleasantprogrammer.com/posts/removing-pldtmydslbiz-from-the-zyxel-p-2612hnu.html</link><dc:creator>Thomas Dy</dc:creator><description>&lt;div&gt;&lt;p&gt;I've always thought that people were just too lazy to change their SSIDs when I see "PLDTMyDSLBizCafeJapan". It became apparent when we got our own PLDT line that it was because the bundled router/modem &lt;em&gt;does not&lt;/em&gt; allow you to remove the prefix.&lt;/p&gt;
 &lt;p&gt;This is not the kind of thing you expect as a business customer. Even for home customers, I feel it's still a bit dishonest. I'd be fine if it was just the default SSID, but forcing people to have it as part of their SSID is like advertising that your company (I mean PLDT) is a douche.&lt;/p&gt;
 &lt;p&gt;Of course, we couldn't just leave the SSID prefix there, so we tried a number of things to get rid of it. There are articles for removing it from the &lt;a href="http://www.phandroidinternet.com/2013/06/how-to-remove-on-wifi-name-or-ssid-on.html"&gt;Prolink H5004N&lt;/a&gt; or the &lt;a href="http://www.symbianize.com/showthread.php?t=730091"&gt;ZyXEL P-660HN-T1A&lt;/a&gt; but not for the one we got which was the ZyXEL P-2612HNU-F1F.&lt;/p&gt;
 &lt;p&gt;We did still try the firebug/inspector tricks, but it seems that there is a server-side check that adds in the "PLDTMyDSLBiz". We tried a number of things, but the one that ultimately worked (and we had a good laugh about) was to backup the configuration, edit the dumped file and restore it.&lt;/p&gt;

+ 1 - 1
output/categories/systemd.xml

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<?xml-stylesheet type="text/xsl" href="../assets/xml/rss.xsl" media="all"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Pleasant Programmer (systemd)</title><link>http://pleasantprogrammer.com/</link><description></description><atom:link rel="self" href="http://pleasantprogrammer.com/categories/systemd.xml" type="application/rss+xml"></atom:link><language>en</language><lastBuildDate>Sat, 17 Jan 2015 15:33:15 GMT</lastBuildDate><generator>http://getnikola.com/</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>Console Keymap Switching</title><link>http://pleasantprogrammer.com/posts/console-keymap-switching.html</link><dc:creator>Thomas Dy</dc:creator><description>&lt;div&gt;&lt;p&gt;At the office, we have some people who use DVORAK. Normally, this isn't a problem. To each his own after all. It does become a bit problematic though, when we're dealing with the servers around the office.&lt;/p&gt;
+<?xml-stylesheet type="text/xsl" href="../assets/xml/rss.xsl" media="all"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Pleasant Programmer (systemd)</title><link>http://pleasantprogrammer.com/</link><description></description><atom:link href="http://pleasantprogrammer.com/categories/systemd.xml" type="application/rss+xml" rel="self"></atom:link><language>en</language><lastBuildDate>Sun, 07 Jun 2015 08:05:41 GMT</lastBuildDate><generator>http://getnikola.com/</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>Console Keymap Switching</title><link>http://pleasantprogrammer.com/posts/console-keymap-switching.html</link><dc:creator>Thomas Dy</dc:creator><description>&lt;div&gt;&lt;p&gt;At the office, we have some people who use DVORAK. Normally, this isn't a problem. To each his own after all. It does become a bit problematic though, when we're dealing with the servers around the office.&lt;/p&gt;
 &lt;p&gt;We normally leave the servers on QWERTY. After all, most people start off as QWERTY typists and migrate to something else. That said, it's apparently difficult to stay fluent in both. People tend to forget how to type in QWERTY once they learn DVORAK or something else. While it is true that they can just look a the keyboard while typing, my coworkers would prefer it to just be in DVORAK.&lt;/p&gt;
 &lt;p&gt;For the console, they'd typically do &lt;code&gt;sudo loadkeys dvorak&lt;/code&gt; after logging in. The problem with this is, after they logout, the keymapping is still on DVORAK. This has been quite annoying for a few times since I can't even login to change the keymap. What I wanted was something like you get in the graphical login screens where you can pick your keymap before logging in. Apparently, there isn't a readily available thing for the console.&lt;/p&gt;
 &lt;p&gt;I googled around for solutions and came across &lt;a href="http://superuser.com/questions/548234/how-can-i-easily-toggle-between-dvorak-and-qwerty-keyboard-layouts-from-a-linux"&gt;a nice idea&lt;/a&gt;. You could alias &lt;code&gt;asdf&lt;/code&gt; to load the DVORAK mapping and &lt;code&gt;aoeu&lt;/code&gt; (the equivalent to asdf in DVORAK) to load the QWERTY mapping. This actually makes sense since you don't really have to know where the letters are. The only problem is, you once again have to be logged in to change the key mappings.&lt;/p&gt;

+ 1 - 1
output/galleries/rss.xml

@@ -1,2 +1,2 @@
 <?xml version="1.0" encoding="utf-8"?>
-<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>galleries</title><link>http://pleasantprogrammer.com/galleries/rss.xml</link><description></description><language>en</language><lastBuildDate>Sat, 17 Jan 2015 15:33:14 GMT</lastBuildDate><generator>http://getnikola.com/</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs></channel></rss>
+<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>galleries</title><link>http://pleasantprogrammer.com/galleries/rss.xml</link><description></description><language>en</language><lastBuildDate>Sun, 07 Jun 2015 08:05:40 GMT</lastBuildDate><generator>http://getnikola.com/</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs></channel></rss>

+ 8 - 8
output/galleries/transit/index.html

@@ -76,28 +76,28 @@
     <h1>transit</h1>
     <ul class="thumbnails">
             <li>
-<a href="gtfs_preview.jpg" class="thumbnail image-reference" title="Gtfs preview">
-                <img src="gtfs_preview.thumbnail.jpg" alt="Gtfs preview"></a>
-            </li>
-<li>
 <a href="onebusaway1.png" class="thumbnail image-reference" title="Onebusaway1">
                 <img src="onebusaway1.thumbnail.png" alt="Onebusaway1"></a>
             </li>
 <li>
+<a href="gtfs_preview.jpg" class="thumbnail image-reference" title="Gtfs preview">
+                <img src="gtfs_preview.thumbnail.jpg" alt="Gtfs preview"></a>
+            </li>
+<li>
 <a href="onebusaway2.png" class="thumbnail image-reference" title="Onebusaway2">
                 <img src="onebusaway2.thumbnail.png" alt="Onebusaway2"></a>
             </li>
 <li>
-<a href="otp2.png" class="thumbnail image-reference" title="Otp2">
-                <img src="otp2.thumbnail.png" alt="Otp2"></a>
+<a href="otp1.png" class="thumbnail image-reference" title="Otp1">
+                <img src="otp1.thumbnail.png" alt="Otp1"></a>
             </li>
 <li>
 <a href="onebusaway3.png" class="thumbnail image-reference" title="Onebusaway3">
                 <img src="onebusaway3.thumbnail.png" alt="Onebusaway3"></a>
             </li>
 <li>
-<a href="otp1.png" class="thumbnail image-reference" title="Otp1">
-                <img src="otp1.thumbnail.png" alt="Otp1"></a>
+<a href="otp2.png" class="thumbnail image-reference" title="Otp2">
+                <img src="otp2.thumbnail.png" alt="Otp2"></a>
             </li>
 <li>
 <a href="otproundabout.png" class="thumbnail image-reference" title="Otproundabout">

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 0 - 0
output/galleries/transit/rss.xml


+ 29 - 0
output/index-2.html

@@ -68,6 +68,35 @@
          <main id="content" role="main">
             
 <div class="postindex">
+    <article class="h-entry post-text">
+    <header>
+        <h1 class="p-name entry-title">
+            <a href="posts/highways-in-otp.html" class="u-url">Highways in OTP</a>
+        </h1>
+    </header>
+    <div class="e-content entry-content">
+    <div>
+<p>One of the weird things that happens with OTP is sometimes it gives absurdly roundabout routes. Here is OTP's suggested route for walking from UP to Ateneo:</p>
+<p><img alt="Roundabout route from UP to Ateneo" src="galleries/transit/otproundabout.png"></p>
+<p>This is just so hilariously wrong. It's much simpler to just walk along Katipunan Avenue.</p>
+<p>OTP couldn't possibly be that dumb though, so there must be something we're doing wrong. If you notice, Katipunan Avenue is colored red compared to the other streets. OTP seems to be avoiding any path that goes along Katipunan Avenue. The problem might have something to do with the "road type" designated to Katipunan.</p>
+<p>Apparently, by default OTP will consider roads of type <code>trunk</code> to be non-walkable and non-bikable. This is documented in the <a href="http://wiki.openstreetmap.org/wiki/OpenTripPlanner">OpenStreetMap wiki</a> and the <a href="https://github.com/openplans/OpenTripPlanner/wiki/GraphBuilder#permissions-and-bicycle-safety">OTP wiki</a> as well. There are actually multiple ways to go about this then. The first solution that came to mind was to just edit the original OSM XML file.</p>
+<pre class="code literal-block">sed -i .bak s/trunk/primary/g manila.osm
+</pre>
+
+
+<p>And rebuild the graph. It doesn't really matter much because the OSM data isn't used to render the maps. It's just used to build the routing data. This is actually what I did for <a href="http://maps.pleasantprogrammer.com">maps.pleasantprogrammer.com</a>.</p>
+<p>It's also possible to set the default way properties in OTP. Instead of disallowing walking and biking on <code>highway=trunk</code> we could allow that. This is not much better than the <code>sed</code> solution though. It's better since you keep the weighting done by OTP, but you're still saying that all trunks are walkable which might not be the case.</p>
+<p>The most correct way to actually fix this is to go through each of the trunks and specifying <code>foot=yes</code> and <code>bicycle=yes</code> for those trunks that are actually walkable. You could either do this locally with the dumped data, or contribute it directly to OSM. I'm not sure on the particulars with updating OSM though.</p>
+</div>
+    </div>
+    <small class="dateline">Posted: <time class="published dt-published" datetime="2013-07-24T23:15:57+08:00" title="2013-07-24 23:15">2013-07-24 23:15</time></small>
+        | <small class="commentline">
+        
+    <a href="posts/highways-in-otp.html#disqus_thread" data-disqus-identifier="cache/posts/highways-in-otp.html">Comments</a>
+
+</small>
+    </article>
     <article class="h-entry post-text">
     <header>
         <h1 class="p-name entry-title">

+ 32 - 29
output/index.html

@@ -67,6 +67,38 @@
          <main id="content" role="main">
             
 <div class="postindex">
+    <article class="h-entry post-text">
+    <header>
+        <h1 class="p-name entry-title">
+            <a href="posts/is-my-terminal-window-active.html" class="u-url">Is My Terminal Window Active?</a>
+        </h1>
+    </header>
+    <div class="e-content entry-content">
+    <div>
+<p>I've been working in OSX for almost 3 years now, but I recently switched back to Linux because of all the problems people encountered with Yosemite. There are some things I missed from OSX though. One of which is <a href="https://github.com/marzocchi/zsh-notify">zsh-notify</a>. It's a zsh plugin that alerts you if your long-running task is complete, and whether it failed or not.</p>
+<p>It's pretty convenient when you're compiling something and then go on to browse reddit while waiting. Usually, I spend too much time just reading and forget about the compilation entirely. With the plugin, I get the notification and maybe go back to work.</p>
+<p>One nice feature it has is that if you're currently looking at the terminal window of the job that just finished, it won't notify you. It only notifies on windows that aren't currently in focus. To do this, it has to actually talk to Terminal.app or iTerm2 to see if the window and tab are active.</p>
+<p>This is alright in OSX since those 2 are the generally most used terminal emulators. On Linux though, everyone has their own favorite terminal. Given that, I figured I could probably rely on talking to X to see if the window is active instead of each single terminal emulator. X can't tell if the tab is active though, but I don't use tabs in my current setup so it should still be good.</p>
+<h3>xdotool</h3>
+<p><a href="http://superuser.com/questions/382616/detecting-currently-active-window">Preliminary research</a> reveals that we can easily get what the active window is with xdotool. <code>xdotool getactivewindow</code> gives us the X window id of the active one. Now all we need is a way to get the window id of the terminal we're in.</p>
+<h3>First Attempt: $WINDOWID</h3>
+<p>Apparently, xterm and similar terminal emulators define an environment variable called <code>$WINDOWID</code> with the window id of the terminal. Obviously, this is too good to be true. In xterm and konsole the <code>$WINDOWID</code> was correct, but in VTE-based terminal emulators, <code>$WINDOWID</code> had the wrong value. In terminology, it didn't define <code>$WINDOWID</code> altogether. So <code>$WINDOWID</code> wasn't going to work.</p>
+<h3>Second Attempt: xdotool search $MAGIC</h3>
+<p>My second idea was that you can use zsh to change the window title to a magic number and then just check if the active window is the same one as the window with the magic number. This sort of worked for most terminals, except konsole which does whatever it wants with the window title. There's also the problem of some zsh configs automatically settings the window title to the current command.</p>
+<p>In hindsight, I could probably have just done <code>xdotool search --name xdotool</code> since in most cases, when you run the search, zsh or konsole will set the window name to the current command. Maybe that's another option I can explore some day.</p>
+<h3>Third Attempt: $PPID</h3>
+<p>My third idea was another environment variable called <code>$PPID</code>, which is the process id of the parent of the shell. As it happens, the parent is the window containing the zsh instance. This is actually pretty consistent across most terminals. The only problem was if you launched zsh from another shell since your new zsh's parent will now be another zsh instance instead of an X window.</p>
+<p>At first glance, launching zsh within zsh doesn't seem like something most people would do, but this is what happens when you run screen or tmux. To work around this, we can actually just save the original <code>$PPID</code> in a different variable and use that instead.</p>
+<p>Now that we have the PID of the window from zsh, we can once again use xdotool to get the PID of the current active window with <code>xdotool getactivewindow getwindowpid</code>. We just simply compare that with our <code>$PPID</code> and we can tell if we're in an active window or not. Overall, this approach worked surprisingly well so that's the final solution I went with.</p>
+</div>
+    </div>
+    <small class="dateline">Posted: <time class="published dt-published" datetime="2015-06-07T16:20:45+08:00" title="2015-06-07 16:20">2015-06-07 16:20</time></small>
+        | <small class="commentline">
+        
+    <a href="posts/is-my-terminal-window-active.html#disqus_thread" data-disqus-identifier="cache/posts/is-my-terminal-window-active.html">Comments</a>
+
+</small>
+    </article>
     <article class="h-entry post-text">
     <header>
         <h1 class="p-name entry-title">
@@ -218,35 +250,6 @@ sed -i .bak <span class="s1">'/^72/ s/,600/,60/'</span> frequencies.txt
         
     <a href="posts/jeep-and-bus-schedules.html#disqus_thread" data-disqus-identifier="cache/posts/jeep-and-bus-schedules.html">Comments</a>
 
-</small>
-    </article>
-    <article class="h-entry post-text">
-    <header>
-        <h1 class="p-name entry-title">
-            <a href="posts/highways-in-otp.html" class="u-url">Highways in OTP</a>
-        </h1>
-    </header>
-    <div class="e-content entry-content">
-    <div>
-<p>One of the weird things that happens with OTP is sometimes it gives absurdly roundabout routes. Here is OTP's suggested route for walking from UP to Ateneo:</p>
-<p><img alt="Roundabout route from UP to Ateneo" src="galleries/transit/otproundabout.png"></p>
-<p>This is just so hilariously wrong. It's much simpler to just walk along Katipunan Avenue.</p>
-<p>OTP couldn't possibly be that dumb though, so there must be something we're doing wrong. If you notice, Katipunan Avenue is colored red compared to the other streets. OTP seems to be avoiding any path that goes along Katipunan Avenue. The problem might have something to do with the "road type" designated to Katipunan.</p>
-<p>Apparently, by default OTP will consider roads of type <code>trunk</code> to be non-walkable and non-bikable. This is documented in the <a href="http://wiki.openstreetmap.org/wiki/OpenTripPlanner">OpenStreetMap wiki</a> and the <a href="https://github.com/openplans/OpenTripPlanner/wiki/GraphBuilder#permissions-and-bicycle-safety">OTP wiki</a> as well. There are actually multiple ways to go about this then. The first solution that came to mind was to just edit the original OSM XML file.</p>
-<pre class="code literal-block">sed -i .bak s/trunk/primary/g manila.osm
-</pre>
-
-
-<p>And rebuild the graph. It doesn't really matter much because the OSM data isn't used to render the maps. It's just used to build the routing data. This is actually what I did for <a href="http://maps.pleasantprogrammer.com">maps.pleasantprogrammer.com</a>.</p>
-<p>It's also possible to set the default way properties in OTP. Instead of disallowing walking and biking on <code>highway=trunk</code> we could allow that. This is not much better than the <code>sed</code> solution though. It's better since you keep the weighting done by OTP, but you're still saying that all trunks are walkable which might not be the case.</p>
-<p>The most correct way to actually fix this is to go through each of the trunks and specifying <code>foot=yes</code> and <code>bicycle=yes</code> for those trunks that are actually walkable. You could either do this locally with the dumped data, or contribute it directly to OSM. I'm not sure on the particulars with updating OSM though.</p>
-</div>
-    </div>
-    <small class="dateline">Posted: <time class="published dt-published" datetime="2013-07-24T23:15:57+08:00" title="2013-07-24 23:15">2013-07-24 23:15</time></small>
-        | <small class="commentline">
-        
-    <a href="posts/highways-in-otp.html#disqus_thread" data-disqus-identifier="cache/posts/highways-in-otp.html">Comments</a>
-
 </small>
     </article>
 </div>

+ 193 - 0
output/posts/is-my-terminal-window-active.html

@@ -0,0 +1,193 @@
+<!DOCTYPE html>
+<html prefix="og: http://ogp.me/ns# article: http://ogp.me/ns/article# " vocab="http://ogp.me/ns" lang="en">
+<head>
+    <meta charset="utf-8">
+    <meta name="viewport" content="width=device-width">
+    <title>Is My Terminal Window Active? | Pleasant Programmer</title>
+
+    
+        <link href="../assets/css/rst.css" rel="stylesheet" type="text/css">
+        <link href="../assets/css/code.css" rel="stylesheet" type="text/css">
+        <link href="../assets/css/theme.css" rel="stylesheet" type="text/css">
+            <link href="../assets/css/custom.css" rel="stylesheet" type="text/css">
+
+    
+            <link rel="alternate" type="application/rss+xml" title="RSS" href="../rss.xml">
+
+      <link rel="canonical" href="http://pleasantprogrammer.com/posts/is-my-terminal-window-active.html">
+
+
+
+
+    <script type="text/javascript" src="//use.typekit.net/iwm5axp.js"></script>
+    <script type="text/javascript">try{Typekit.load();}catch(e){}</script>
+
+    
+        <!--[if lt IE 9]><script src="../assets/js/html5.js"></script><![endif]-->
+
+    
+
+
+    
+
+    <meta name="author" content="Thomas Dy">
+        <link rel="prev" href="removing-pldtmydslbiz-from-the-zyxel-p-2612hnu.html" title="Removing PLDTMyDSLBiz from the ZyXEL P-2612HNU" type="text/html">
+    
+    <meta property="og:site_name" content="Pleasant Programmer">
+    <meta property="og:title" content="Is My Terminal Window Active?">
+    <meta property="og:url" content="http://pleasantprogrammer.com/posts/is-my-terminal-window-active.html">
+    <meta property="og:description" content="I've been working in OSX for almost 3 years now, but I recently switched back to Linux because of all the problems people encountered with Yosemite. There are some things I missed from OSX though. One">
+    <meta property="og:type" content="article">
+    <meta property="article:published_time" content="2015-06-07T16:20:45+08:00">
+           <meta property="article:tag" content="programming">
+
+    
+
+    
+
+
+
+</head>
+<body>
+<a href="#content" class="sr-only sr-only-focusable">Skip to main content</a>
+    
+    <header id="header" role="banner">
+        <div class="thomas">
+            <img src="../assets/img/thomas.gif" alt="DJ THOMAS IN DA HAUS">
+            <img src="../assets/img/thomas.png" alt="Pleasant Programmer">
+        </div>
+        
+    <h1 id="brand"><a href="http://pleasantprogrammer.com/" title="Pleasant Programmer" rel="home">
+
+        <span id="blog-title">Pleasant Programmer</span>
+    </a></h1>
+
+        
+
+        
+    <nav id="menu" role="navigation">
+    <ul>
+            <li class="twitter"><a href="http://twitter.com/pleasantprog">@pleasantprog</a></li>
+                <li><a href="../archive.html">Archives</a></li>
+                <li><a href="../categories/index.html">Tags</a></li>
+                <li><a href="../rss.xml">RSS</a></li>
+    
+    
+    </ul>
+    </nav>
+
+    </header>
+    
+
+    <div id="container">
+         <main id="content" role="main">
+            
+<article class="post-text h-entry hentry postpage" itemscope="itemscope" itemtype="http://schema.org/Article">
+    
+    <header>
+        
+    <h1 class="p-name entry-title" itemprop="headline name"><a href="#" class="u-url">Is My Terminal Window Active?</a></h1>
+
+        <small>
+        <span class="dateline">Posted: <a href="#" rel="bookmark"><time class="published dt-published" datetime="2015-06-07T16:20:45+08:00" itemprop="datePublished" title="2015-06-07 16:20">2015-06-07 16:20</time></a></span>
+        |
+        More posts about
+        
+           <a class="tag p-category" href="../categories/programming.html" rel="tag">programming</a>
+
+        </small>
+        
+
+    </header>
+
+    <div class="e-content entry-content" itemprop="articleBody text">
+    <div>
+<p>I've been working in OSX for almost 3 years now, but I recently switched back to Linux because of all the problems people encountered with Yosemite. There are some things I missed from OSX though. One of which is <a href="https://github.com/marzocchi/zsh-notify">zsh-notify</a>. It's a zsh plugin that alerts you if your long-running task is complete, and whether it failed or not.</p>
+<p>It's pretty convenient when you're compiling something and then go on to browse reddit while waiting. Usually, I spend too much time just reading and forget about the compilation entirely. With the plugin, I get the notification and maybe go back to work.</p>
+<p>One nice feature it has is that if you're currently looking at the terminal window of the job that just finished, it won't notify you. It only notifies on windows that aren't currently in focus. To do this, it has to actually talk to Terminal.app or iTerm2 to see if the window and tab are active.</p>
+<p>This is alright in OSX since those 2 are the generally most used terminal emulators. On Linux though, everyone has their own favorite terminal. Given that, I figured I could probably rely on talking to X to see if the window is active instead of each single terminal emulator. X can't tell if the tab is active though, but I don't use tabs in my current setup so it should still be good.</p>
+<h3>xdotool</h3>
+<p><a href="http://superuser.com/questions/382616/detecting-currently-active-window">Preliminary research</a> reveals that we can easily get what the active window is with xdotool. <code>xdotool getactivewindow</code> gives us the X window id of the active one. Now all we need is a way to get the window id of the terminal we're in.</p>
+<h3>First Attempt: $WINDOWID</h3>
+<p>Apparently, xterm and similar terminal emulators define an environment variable called <code>$WINDOWID</code> with the window id of the terminal. Obviously, this is too good to be true. In xterm and konsole the <code>$WINDOWID</code> was correct, but in VTE-based terminal emulators, <code>$WINDOWID</code> had the wrong value. In terminology, it didn't define <code>$WINDOWID</code> altogether. So <code>$WINDOWID</code> wasn't going to work.</p>
+<h3>Second Attempt: xdotool search $MAGIC</h3>
+<p>My second idea was that you can use zsh to change the window title to a magic number and then just check if the active window is the same one as the window with the magic number. This sort of worked for most terminals, except konsole which does whatever it wants with the window title. There's also the problem of some zsh configs automatically settings the window title to the current command.</p>
+<p>In hindsight, I could probably have just done <code>xdotool search --name xdotool</code> since in most cases, when you run the search, zsh or konsole will set the window name to the current command. Maybe that's another option I can explore some day.</p>
+<h3>Third Attempt: $PPID</h3>
+<p>My third idea was another environment variable called <code>$PPID</code>, which is the process id of the parent of the shell. As it happens, the parent is the window containing the zsh instance. This is actually pretty consistent across most terminals. The only problem was if you launched zsh from another shell since your new zsh's parent will now be another zsh instance instead of an X window.</p>
+<p>At first glance, launching zsh within zsh doesn't seem like something most people would do, but this is what happens when you run screen or tmux. To work around this, we can actually just save the original <code>$PPID</code> in a different variable and use that instead.</p>
+<p>Now that we have the PID of the window from zsh, we can once again use xdotool to get the PID of the current active window with <code>xdotool getactivewindow getwindowpid</code>. We just simply compare that with our <code>$PPID</code> and we can tell if we're in an active window or not. Overall, this approach worked surprisingly well so that's the final solution I went with.</p>
+</div>
+    </div>
+    <aside class="postpromonav">
+    <nav>
+    
+        <ul class="pager clearfix">
+            <li class="previous">
+                <a href="removing-pldtmydslbiz-from-the-zyxel-p-2612hnu.html" rel="prev" title="Removing PLDTMyDSLBiz from the ZyXEL P-2612HNU">← Previous post</a>
+            </li>
+        </ul>
+
+    </nav>
+    </aside>
+        <section class="comments">
+        
+        
+        <div id="disqus_thread"></div>
+        <script>
+        var disqus_shortname ="pleasantprog",
+            disqus_url="http://pleasantprogrammer.com/posts/is-my-terminal-window-active.html",
+        disqus_title="Is My Terminal Window Active?",
+        disqus_identifier="cache/posts/is-my-terminal-window-active.html",
+        disqus_config = function () {
+            this.language = "en";
+        };
+        (function() {
+            var dsq = document.createElement('script'); dsq.async = true;
+            dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
+            (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
+        })();
+    </script>
+    <noscript>Please enable JavaScript to view the <a href="//disqus.com/?ref_noscript" rel="nofollow">comments powered by Disqus.</a>
+</noscript>
+    <a href="//disqus.com" class="dsq-brlink" rel="nofollow">Comments powered by <span class="logo-disqus">Disqus</span></a>
+
+
+        </section>
+    
+
+</article>
+
+        
+       <script>var disqus_shortname="pleasantprog";(function(){var a=document.createElement("script");a.async=true;a.src="//"+disqus_shortname+".disqus.com/count.js";(document.getElementsByTagName("head")[0]||document.getElementsByTagName("body")[0]).appendChild(a)}());</script>
+
+
+
+         </main>
+         
+        <footer id="footer" role="contentinfo">
+            <p><a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/deed.en_US"><img alt="CC-BY-SA" style="border-width:0" src="http://i.creativecommons.org/l/by-sa/3.0/80x15.png"></a> © 2015 Thomas Dy - Powered by <a href="http://getnikola.com">Nikola</a></p>
+            
+        </footer>
+
+    </div>
+    
+    
+    
+    
+
+    <script src="../assets/js/konami.js"></script>
+    <script src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
+    <script>
+        var easter_egg = new Konami();
+        easter_egg.code = function() {
+            $(".thomas").toggleClass("whoa");
+            $("body").scrollTop(0);
+        }
+        easter_egg.load();
+
+        // love you, thomas!
+        // yours, @_phi + @meggykawsek
+    </script>
+</body>
+</html>

+ 40 - 0
output/posts/is-my-terminal-window-active.md

@@ -0,0 +1,40 @@
+<!--
+.. title: Is My Terminal Window Active?
+.. slug: is-my-terminal-window-active
+.. date: 2015-06-07 16:20:45 UTC+08:00
+.. tags: programming
+.. category:
+.. link:
+.. description:
+.. type: text
+-->
+
+I've been working in OSX for almost 3 years now, but I recently switched back to Linux because of all the problems people encountered with Yosemite. There are some things I missed from OSX though. One of which is [zsh-notify](https://github.com/marzocchi/zsh-notify). It's a zsh plugin that alerts you if your long-running task is complete, and whether it failed or not.
+
+It's pretty convenient when you're compiling something and then go on to browse reddit while waiting. Usually, I spend too much time just reading and forget about the compilation entirely. With the plugin, I get the notification and maybe go back to work.
+
+One nice feature it has is that if you're currently looking at the terminal window of the job that just finished, it won't notify you. It only notifies on windows that aren't currently in focus. To do this, it has to actually talk to Terminal.app or iTerm2 to see if the window and tab are active.
+
+This is alright in OSX since those 2 are the generally most used terminal emulators. On Linux though, everyone has their own favorite terminal. Given that, I figured I could probably rely on talking to X to see if the window is active instead of each single terminal emulator. X can't tell if the tab is active though, but I don't use tabs in my current setup so it should still be good.
+
+## xdotool
+
+[Preliminary research](http://superuser.com/questions/382616/detecting-currently-active-window) reveals that we can easily get what the active window is with xdotool. `xdotool getactivewindow` gives us the X window id of the active one. Now all we need is a way to get the window id of the terminal we're in.
+
+## First Attempt: $WINDOWID
+
+Apparently, xterm and similar terminal emulators define an environment variable called `$WINDOWID` with the window id of the terminal. Obviously, this is too good to be true. In xterm and konsole the `$WINDOWID` was correct, but in VTE-based terminal emulators, `$WINDOWID` had the wrong value. In terminology, it didn't define `$WINDOWID` altogether. So `$WINDOWID` wasn't going to work.
+
+## Second Attempt: xdotool search $MAGIC
+
+My second idea was that you can use zsh to change the window title to a magic number and then just check if the active window is the same one as the window with the magic number. This sort of worked for most terminals, except konsole which does whatever it wants with the window title. There's also the problem of some zsh configs automatically settings the window title to the current command.
+
+In hindsight, I could probably have just done `xdotool search --name xdotool` since in most cases, when you run the search, zsh or konsole will set the window name to the current command. Maybe that's another option I can explore some day.
+
+## Third Attempt: $PPID
+
+My third idea was another environment variable called `$PPID`, which is the process id of the parent of the shell. As it happens, the parent is the window containing the zsh instance. This is actually pretty consistent across most terminals. The only problem was if you launched zsh from another shell since your new zsh's parent will now be another zsh instance instead of an X window.
+
+At first glance, launching zsh within zsh doesn't seem like something most people would do, but this is what happens when you run screen or tmux. To work around this, we can actually just save the original `$PPID` in a different variable and use that instead.
+
+Now that we have the PID of the window from zsh, we can once again use xdotool to get the PID of the current active window with `xdotool getactivewindow getwindowpid`. We just simply compare that with our `$PPID` and we can tell if we're in an active window or not. Overall, this approach worked surprisingly well so that's the final solution I went with.

+ 4 - 0
output/posts/removing-pldtmydslbiz-from-the-zyxel-p-2612hnu.html

@@ -32,6 +32,7 @@
 
     <meta name="author" content="Thomas Dy">
         <link rel="prev" href="console-keymap-switching.html" title="Console Keymap Switching" type="text/html">
+        <link rel="next" href="is-my-terminal-window-active.html" title="Is My Terminal Window Active?" type="text/html">
     
     <meta property="og:site_name" content="Pleasant Programmer">
     <meta property="og:title" content="Removing PLDTMyDSLBiz from the ZyXEL P-2612HNU">
@@ -117,6 +118,9 @@
             <li class="previous">
                 <a href="console-keymap-switching.html" rel="prev" title="Console Keymap Switching">← Previous post</a>
             </li>
+            <li class="next">
+                <a href="is-my-terminal-window-active.html" rel="next" title="Is My Terminal Window Active?">Next post →</a>
+            </li>
         </ul>
 
     </nav>

+ 16 - 178
output/rss.xml

@@ -1,5 +1,19 @@
 <?xml version="1.0" encoding="utf-8"?>
-<?xml-stylesheet type="text/xsl" href="assets/xml/rss.xsl" media="all"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Pleasant Programmer</title><link>http://pleasantprogrammer.com/</link><description></description><atom:link rel="self" href="http://pleasantprogrammer.com/rss.xml" type="application/rss+xml"></atom:link><language>en</language><lastBuildDate>Sat, 17 Jan 2015 15:33:15 GMT</lastBuildDate><generator>http://getnikola.com/</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>Removing PLDTMyDSLBiz from the ZyXEL P-2612HNU</title><link>http://pleasantprogrammer.com/posts/removing-pldtmydslbiz-from-the-zyxel-p-2612hnu.html</link><dc:creator>Thomas Dy</dc:creator><description>&lt;div&gt;&lt;p&gt;I've always thought that people were just too lazy to change their SSIDs when I see "PLDTMyDSLBizCafeJapan". It became apparent when we got our own PLDT line that it was because the bundled router/modem &lt;em&gt;does not&lt;/em&gt; allow you to remove the prefix.&lt;/p&gt;
+<?xml-stylesheet type="text/xsl" href="assets/xml/rss.xsl" media="all"?><rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>Pleasant Programmer</title><link>http://pleasantprogrammer.com/</link><description></description><atom:link href="http://pleasantprogrammer.com/rss.xml" rel="self" type="application/rss+xml"></atom:link><language>en</language><lastBuildDate>Sun, 07 Jun 2015 08:22:42 GMT</lastBuildDate><generator>http://getnikola.com/</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>Is My Terminal Window Active?</title><link>http://pleasantprogrammer.com/posts/is-my-terminal-window-active.html</link><dc:creator>Thomas Dy</dc:creator><description>&lt;div&gt;&lt;p&gt;I've been working in OSX for almost 3 years now, but I recently switched back to Linux because of all the problems people encountered with Yosemite. There are some things I missed from OSX though. One of which is &lt;a href="https://github.com/marzocchi/zsh-notify"&gt;zsh-notify&lt;/a&gt;. It's a zsh plugin that alerts you if your long-running task is complete, and whether it failed or not.&lt;/p&gt;
+&lt;p&gt;It's pretty convenient when you're compiling something and then go on to browse reddit while waiting. Usually, I spend too much time just reading and forget about the compilation entirely. With the plugin, I get the notification and maybe go back to work.&lt;/p&gt;
+&lt;p&gt;One nice feature it has is that if you're currently looking at the terminal window of the job that just finished, it won't notify you. It only notifies on windows that aren't currently in focus. To do this, it has to actually talk to Terminal.app or iTerm2 to see if the window and tab are active.&lt;/p&gt;
+&lt;p&gt;This is alright in OSX since those 2 are the generally most used terminal emulators. On Linux though, everyone has their own favorite terminal. Given that, I figured I could probably rely on talking to X to see if the window is active instead of each single terminal emulator. X can't tell if the tab is active though, but I don't use tabs in my current setup so it should still be good.&lt;/p&gt;
+&lt;h3&gt;xdotool&lt;/h3&gt;
+&lt;p&gt;&lt;a href="http://superuser.com/questions/382616/detecting-currently-active-window"&gt;Preliminary research&lt;/a&gt; reveals that we can easily get what the active window is with xdotool. &lt;code&gt;xdotool getactivewindow&lt;/code&gt; gives us the X window id of the active one. Now all we need is a way to get the window id of the terminal we're in.&lt;/p&gt;
+&lt;h3&gt;First Attempt: $WINDOWID&lt;/h3&gt;
+&lt;p&gt;Apparently, xterm and similar terminal emulators define an environment variable called &lt;code&gt;$WINDOWID&lt;/code&gt; with the window id of the terminal. Obviously, this is too good to be true. In xterm and konsole the &lt;code&gt;$WINDOWID&lt;/code&gt; was correct, but in VTE-based terminal emulators, &lt;code&gt;$WINDOWID&lt;/code&gt; had the wrong value. In terminology, it didn't define &lt;code&gt;$WINDOWID&lt;/code&gt; altogether. So &lt;code&gt;$WINDOWID&lt;/code&gt; wasn't going to work.&lt;/p&gt;
+&lt;h3&gt;Second Attempt: xdotool search $MAGIC&lt;/h3&gt;
+&lt;p&gt;My second idea was that you can use zsh to change the window title to a magic number and then just check if the active window is the same one as the window with the magic number. This sort of worked for most terminals, except konsole which does whatever it wants with the window title. There's also the problem of some zsh configs automatically settings the window title to the current command.&lt;/p&gt;
+&lt;p&gt;In hindsight, I could probably have just done &lt;code&gt;xdotool search --name xdotool&lt;/code&gt; since in most cases, when you run the search, zsh or konsole will set the window name to the current command. Maybe that's another option I can explore some day.&lt;/p&gt;
+&lt;h3&gt;Third Attempt: $PPID&lt;/h3&gt;
+&lt;p&gt;My third idea was another environment variable called &lt;code&gt;$PPID&lt;/code&gt;, which is the process id of the parent of the shell. As it happens, the parent is the window containing the zsh instance. This is actually pretty consistent across most terminals. The only problem was if you launched zsh from another shell since your new zsh's parent will now be another zsh instance instead of an X window.&lt;/p&gt;
+&lt;p&gt;At first glance, launching zsh within zsh doesn't seem like something most people would do, but this is what happens when you run screen or tmux. To work around this, we can actually just save the original &lt;code&gt;$PPID&lt;/code&gt; in a different variable and use that instead.&lt;/p&gt;
+&lt;p&gt;Now that we have the PID of the window from zsh, we can once again use xdotool to get the PID of the current active window with &lt;code&gt;xdotool getactivewindow getwindowpid&lt;/code&gt;. We just simply compare that with our &lt;code&gt;$PPID&lt;/code&gt; and we can tell if we're in an active window or not. Overall, this approach worked surprisingly well so that's the final solution I went with.&lt;/p&gt;&lt;/div&gt;</description><category>programming</category><guid>http://pleasantprogrammer.com/posts/is-my-terminal-window-active.html</guid><pubDate>Sun, 07 Jun 2015 08:20:45 GMT</pubDate></item><item><title>Removing PLDTMyDSLBiz from the ZyXEL P-2612HNU</title><link>http://pleasantprogrammer.com/posts/removing-pldtmydslbiz-from-the-zyxel-p-2612hnu.html</link><dc:creator>Thomas Dy</dc:creator><description>&lt;div&gt;&lt;p&gt;I've always thought that people were just too lazy to change their SSIDs when I see "PLDTMyDSLBizCafeJapan". It became apparent when we got our own PLDT line that it was because the bundled router/modem &lt;em&gt;does not&lt;/em&gt; allow you to remove the prefix.&lt;/p&gt;
 &lt;p&gt;This is not the kind of thing you expect as a business customer. Even for home customers, I feel it's still a bit dishonest. I'd be fine if it was just the default SSID, but forcing people to have it as part of their SSID is like advertising that your company (I mean PLDT) is a douche.&lt;/p&gt;
 &lt;p&gt;Of course, we couldn't just leave the SSID prefix there, so we tried a number of things to get rid of it. There are articles for removing it from the &lt;a href="http://www.phandroidinternet.com/2013/06/how-to-remove-on-wifi-name-or-ssid-on.html"&gt;Prolink H5004N&lt;/a&gt; or the &lt;a href="http://www.symbianize.com/showthread.php?t=730091"&gt;ZyXEL P-660HN-T1A&lt;/a&gt; but not for the one we got which was the ZyXEL P-2612HNU-F1F.&lt;/p&gt;
 &lt;p&gt;We did still try the firebug/inspector tricks, but it seems that there is a server-side check that adds in the "PLDTMyDSLBiz". We tried a number of things, but the one that ultimately worked (and we had a good laugh about) was to backup the configuration, edit the dumped file and restore it.&lt;/p&gt;
@@ -164,180 +178,4 @@ sed -i .bak &lt;span class="s1"&gt;'/^72/ s/,600/,60/'&lt;/span&gt; frequencies.
 &lt;p&gt;We also don't know if the jeeps or buses strictly follow the distance-based scheme. After all, if you can get on and off anywhere, you can't really measure distance that exactly. I assume they generally work off the notion of "zones" than actual distance travelled. In that sense, they work more similarly to the LRT which has fares based on how many stops you pass. For jeeps and buses, your fare is probably based more on how many "zones" you pass through.&lt;/p&gt;
 &lt;h4&gt;Conclusion&lt;/h4&gt;
 &lt;p&gt;Philip, a co-worker of mine at By Implication, had suggested that we might want to use a different model than what the GTFS proposes. I have to agree with him. At this point, the GTFS doesn't really fit with our system. But I do think that open data and standards are great. In fact, I applaud the developers who made proposals for the fare system, as those are great first steps towards making the GTFS a more universal standard.&lt;/p&gt;
-&lt;p&gt;Side note: I'd also actually really like to hear about the DOTC developers' experience with the project. It would be nice if they had a devblog.&lt;/p&gt;&lt;/div&gt;</description><category>philippine-transit-app</category><category>programming</category><guid>http://pleasantprogrammer.com/posts/fare-data.html</guid><pubDate>Sat, 13 Jul 2013 13:15:09 GMT</pubDate></item><item><title>GTFS Editor</title><link>http://pleasantprogrammer.com/posts/gtfs-editor.html</link><dc:creator>Thomas Dy</dc:creator><description>&lt;div&gt;&lt;p&gt;Link: &lt;a href="https://github.com/conveyal/gtfs-editor"&gt;https://github.com/conveyal/gtfs-editor&lt;/a&gt;&lt;/p&gt;
-&lt;p&gt;&lt;strong&gt;TL;DR&lt;/strong&gt; they really meant under development&lt;/p&gt;
-&lt;p&gt;When I first saw the source of GTFS Editor, I was ecstatic. They used &lt;a href="http://playframework.com/"&gt;Play framework&lt;/a&gt;!!! Not only that, they're targeting PostgreSQL as the main database. Those are our favorite tools for building webapps at By Implication. I was a bit sad though, when I saw it was on the 1.x release of Play though. I did have some experience with that release, but not as much compared to 2.x.&lt;/p&gt;
-&lt;p&gt;Getting it to actually run though, wasn't very pleasant. The initial setup was easy enough. Get &lt;a href="http://www.playframework.com/download"&gt;Play 1.2.5&lt;/a&gt;, install Postgres with PostGIS, clone the repo and create backing database in Postgres. Some minor additional steps you need are to create the PostGIS extension on the database. The schema is automatically generated and applied by Play so that should be all that's necessary. Wonderful. Then, run play, open a browser, go to &lt;a href="http://localhost:9000"&gt;http://localhost:9000&lt;/a&gt;, compilation error. Fantastic.&lt;/p&gt;
-&lt;p&gt;If you don't want to go through the technical details, you can just jump to the &lt;a href="http://pleasantprogrammer.com/posts/gtfs-editor.html#conclusion"&gt;conclusion&lt;/a&gt;.&lt;/p&gt;
-&lt;h3&gt;Let's Debug!&lt;/h3&gt;
-&lt;p&gt;I'll be splitting the next section up into 2 parts. In the first pass, I'll talk about what I did to just get the app to run but I won't try hard to fix any bugs. This generally is what I do when I try to get apps to run. I'll also be dropping enough information so that you can actually figure out what the real problem is. In the second pass, I'll explain what the problems were and how I fixed them.&lt;/p&gt;
-&lt;h4&gt;First Pass&lt;/h4&gt;
-&lt;p&gt;A thing to note about Play (and one of the reasons it's a lovely Java framework) is that you don't need to do manual compilation. Just edit some source files, refresh your browser and it will automatically do the compilation for you. One less argument for using PHP. It even shows you (in the browser!) the source and which line of code caused the compilation error. So that's what I saw, &lt;code&gt;Error: type Check already defined&lt;/code&gt;&lt;/p&gt;
-&lt;pre class="code literal-block"&gt;&lt;span class="nd"&gt;@Retention&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;RetentionPolicy&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;RUNTIME&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
-&lt;span class="nd"&gt;@Target&lt;/span&gt;&lt;span class="o"&gt;({&lt;/span&gt;&lt;span class="n"&gt;ElementType&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;METHOD&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ElementType&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;TYPE&lt;/span&gt;&lt;span class="o"&gt;})&lt;/span&gt;
-&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nd"&gt;@interface&lt;/span&gt; &lt;span class="n"&gt;Check&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="c1"&gt;// error here&lt;/span&gt;
-
-    &lt;span class="n"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="nf"&gt;value&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
-&lt;span class="o"&gt;}&lt;/span&gt;
-&lt;/pre&gt;
-
-
-&lt;p&gt;You also know that typical behavior among programmers where your program doesn't compile, but you keep trying to compile it anyway hoping that it will magically just work. That's what I did, and it actually ran. I couldn't really just let this pass, so I decided to try deleting &lt;code&gt;Check.java&lt;/code&gt;. I got another compilation error, &lt;code&gt;Error: type Secure already defined&lt;/code&gt;&lt;/p&gt;
-&lt;pre class="code literal-block"&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Secure&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="n"&gt;Controller&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="c1"&gt;// error here&lt;/span&gt;
-
-    &lt;span class="nd"&gt;@Before&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;unless&lt;/span&gt;&lt;span class="o"&gt;={&lt;/span&gt;&lt;span class="s"&gt;"login"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"authenticate"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"logout"&lt;/span&gt;&lt;span class="o"&gt;})&lt;/span&gt;
-
-    &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;checkAccess&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="kd"&gt;throws&lt;/span&gt; &lt;span class="n"&gt;Throwable&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
-&lt;/pre&gt;
-
-
-&lt;p&gt;At that point, I just decided to just debug it later. It works by just forcing it anyway. So I put &lt;code&gt;Check.java&lt;/code&gt; back in and proceeded to just refresh until it compiled and ran.&lt;/p&gt;
-&lt;p&gt;The next problem is a sort of common thing most webapp developers have to solve one way or another. How do you set up the initial admin account? Phrased a different way, how do I login to this thing? The first thing I tried was just add a user into the &lt;code&gt;account&lt;/code&gt; table directly. One problem though was how to set the password correctly. Plaintext obviously wouldn't work.&lt;/p&gt;
-&lt;p&gt;Another note regarding Play 1.x, it provides the &lt;a href="http://www.playframework.com/documentation/1.2.5/secure"&gt;secure module&lt;/a&gt; which handles logins and keeping state, you simply need to implement the method &lt;code&gt;boolean authenticate(String username, String password)&lt;/code&gt;. It leaves the actual process of verifying the login to the programmer. This can be exploited by just making the method return &lt;code&gt;true&lt;/code&gt; and then any login would work. No need to actually set the password. Excellent.&lt;/p&gt;
-&lt;p&gt;And we're logged in, just in time to encounter a runtime exception. This also works much like compilation errors in Play. It shows a page with the error and the relevant source lines. Now we get, &lt;code&gt;IndexOutOfBoundsException occured : Index: 0, Size: 0&lt;/code&gt;&lt;/p&gt;
-&lt;pre class="code literal-block"&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;session&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"agencyId"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
-
-    &lt;span class="n"&gt;Agency&lt;/span&gt; &lt;span class="n"&gt;agency&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;agencies&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// error here&lt;/span&gt;
-
-    &lt;span class="n"&gt;session&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;put&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"agencyId"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;agency&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
-    &lt;span class="n"&gt;session&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;put&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"agencyName"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;agency&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
-&lt;/pre&gt;
-
-
-&lt;p&gt;Apparently, we need to have an agency. That's generally simple enough. You just manually insert an agency into the &lt;code&gt;agency&lt;/code&gt; table. After that's done, we finally have a view of the actual application. It's very Bootstrap-y, but that's just fine. The workflow though, is not perfectly intuitive, but I'll talk about that some other day.&lt;/p&gt;
-&lt;p&gt;That's not the end of it though, we still have to fix these bugs. The developer obviously didn't have to put up with this when they were working, so what happened? Also, the log is showing some weird things,&lt;/p&gt;
-&lt;pre class="code literal-block"&gt;~        _            _
-~  _ __ | | __ _ _  _| |
-~ | '_ \| |/ _' | || |_|
-~ |  __/|_|\____|\__ (_)
-~ |_|            |__/
-~
-~ play! 1.2.5, http://www.playframework.org
-~
-~ Ctrl+C to stop
-~
-CompilerOracle: exclude jregex/Pretokenizer.next
-Listening for transport dt_socket at address: 8000
-23:32:14,943 INFO  ~ Starting /Users/thomas/Workspace/maps/gtfs-editor
-23:32:14,948 WARN  ~ Declaring modules in application.conf is deprecated. Use dependencies.yml instead (module.secure)
-23:32:14,948 INFO  ~ Module secure is available (/Users/thomas/.root/opt/play-1.2.5/modules/secure)
-23:32:15,830 WARN  ~ You're running Play! in DEV mode
-23:32:15,952 INFO  ~ Listening for HTTP on port 9000 (Waiting a first request to start) ...
-23:32:28,792 ERROR ~
-
-@6f02fa9dd
-Internal Server Error (500) for request GET /
-
-Compilation error (In /app/controllers/Check.java around line 10)
-The file /app/controllers/Check.java could not be compiled. Error raised is : The type Check is already defined
-
-play.exceptions.CompilationException: The type Check is already defined
-    at play.classloading.ApplicationCompiler$2.acceptResult(ApplicationCompiler.java:246)
-    at org.eclipse.jdt.internal.compiler.Compiler.handleInternalException(Compiler.java:672)
-    at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:516)
-    at play.classloading.ApplicationCompiler.compile(ApplicationCompiler.java:282)
-    at play.classloading.ApplicationClassloader.getAllClasses(ApplicationClassloader.java:426)
-    at play.Play.start(Play.java:516)
-    at play.Play.detectChanges(Play.java:630)
-    at play.Invoker$Invocation.init(Invoker.java:198)
-    at Invocation.HTTP Request(Play!)
-23:32:31,551 INFO  ~ Connected to jdbc:postgresql://127.0.0.1/gtfs_editor
-SLF4J: Class path contains multiple SLF4J bindings.
-SLF4J: Found binding in [jar:file:/Users/thomas/Workspace/maps/gtfs-editor/lib/slf4j-log4j12-1.6.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
-SLF4J: Found binding in [jar:file:/Users/thomas/.root/opt/play-1.2.5/framework/lib/slf4j-log4j12-1.6.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
-SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
-23:32:32,490 INFO  ~ Initializing HBSpatialExtension
-23:32:32,492 INFO  ~ Attempting to load Hibernate Spatial Provider org.hibernatespatial.postgis.DialectProvider
-23:32:32,494 INFO  ~ Checking for default configuration file.
-23:32:32,496 INFO  ~ No configuration file hibernate-spatial.cfg.xml on the classpath.
-23:32:34,077 INFO  ~ Application 'gtfs-editor' is now started !
-23:32:34,151 INFO  ~ Bootstrapping Database...
-23:32:34,297 DEBUG ~ select count(*) as col_0_0_ from Agency agency0_ limit ?
-play.exceptions.UnexpectedException: Unexpected Error
-    at play.vfs.VirtualFile.contentAsString(VirtualFile.java:180)
-    at play.templates.TemplateLoader.load(TemplateLoader.java:78)
-    at play.test.Fixtures.loadModels(Fixtures.java:174)
-    at jobs.BootstrapDatabase.doJob(BootstrapDatabase.java:57)
-    at play.jobs.Job.doJobWithResult(Job.java:50)
-    at play.jobs.Job.call(Job.java:146)
-    at play.jobs.Job.run(Job.java:132)
-    at play.jobs.JobsPlugin.afterApplicationStart(JobsPlugin.java:116)
-    at play.plugins.PluginCollection.afterApplicationStart(PluginCollection.java:531)
-    at play.Play.start(Play.java:547)
-    at play.Play.detectChanges(Play.java:630)
-    at play.Invoker$Invocation.init(Invoker.java:198)
-    at play.server.PlayHandler$NettyInvocation.init(PlayHandler.java:189)
-    at play.Invoker$Invocation.run(Invoker.java:276)
-    at play.server.PlayHandler$NettyInvocation.run(PlayHandler.java:229)
-    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)
-    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
-    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
-    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:98)
-    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:206)
-    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
-    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
-    at java.lang.Thread.run(Thread.java:680)
-Caused by: play.exceptions.UnexpectedException: Unexpected Error
-    at play.vfs.VirtualFile.inputstream(VirtualFile.java:111)
-    at play.vfs.VirtualFile.contentAsString(VirtualFile.java:178)
-    ... 22 more
-Caused by: java.io.FileNotFoundException: /Users/thomas/.root/opt/play-1.2.5/modules/docviewer/app/initial-agencies-data.yml (No such file or directory)
-    at java.io.FileInputStream.open(Native Method)
-    at java.io.FileInputStream.&amp;lt;init&amp;gt;(FileInputStream.java:120)
-    at play.vfs.VirtualFile.inputstream(VirtualFile.java:109)
-    ... 23 more
-23:32:34,316 ERROR ~ java.lang.RuntimeException: Cannot load fixture initial-agencies-data.yml: Unexpected Error
-23:32:40,989 DEBUG ~ select account0_.id as id15_, account0_.active as active15_, account0_.admin as admin15_, account0_.agency_id as agency9_15_, account0_.email as email15_, account0_.lastLogin as lastLogin15_, account0_.password as password15_, account0_.passwordChangeToken as password7_15_, account0_.username as username15_ from Account account0_ where account0_.username=? limit ?
-23:32:40,994 DEBUG ~ select count(*) as col_0_0_ from Account account0_ limit ?
-23:32:40,999 DEBUG ~ select nextval ('hibernate_sequence')
-23:32:41,051 DEBUG ~ insert into Account (active, admin, agency_id, email, lastLogin, password, passwordChangeToken, username, id) values (?, ?, ?, ?, ?, ?, ?, ?, ?)
-23:32:41,061 DEBUG ~ select agency0_.id as id24_, agency0_.color as color24_, agency0_.defaultLat as defaultLat24_, agency0_.defaultLon as defaultLon24_, agency0_.defaultRouteType_id as default12_24_, agency0_.gtfsAgencyId as gtfsAgen5_24_, agency0_.lang as lang24_, agency0_.name as name24_, agency0_.phone as phone24_, agency0_.systemMap as systemMap24_, agency0_.timezone as timezone24_, agency0_.url as url24_ from Agency agency0_ order by agency0_.name
-23:32:41,175 ERROR ~
-
-@6f02fa9dg
-Internal Server Error (500) for request GET /
-
-Execution exception (In /app/controllers/Application.java around line 57)
-IndexOutOfBoundsException occured : Index: 0, Size: 0
-
-play.exceptions.JavaExecutionException: Index: 0, Size: 0
-    at play.mvc.ActionInvoker.invoke(ActionInvoker.java:237)
-    at Invocation.HTTP Request(Play!)
-Caused by: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
-    at java.util.ArrayList.RangeCheck(ArrayList.java:547)
-    at java.util.ArrayList.get(ArrayList.java:322)
-    at controllers.Application.initSession(Application.java:57)
-    at play.mvc.ActionInvoker.invoke(ActionInvoker.java:510)
-    at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:484)
-    at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:479)
-    at play.mvc.ActionInvoker.handleBefores(ActionInvoker.java:328)
-    at play.mvc.ActionInvoker.invoke(ActionInvoker.java:142)
-    ... 1 more
-&lt;/pre&gt;
-
-
-&lt;p&gt;After &lt;code&gt;23:32:34&lt;/code&gt; is when I get the login page. &lt;code&gt;23:32:40&lt;/code&gt; is after I've logged in.&lt;/p&gt;
-&lt;h4&gt;Second Pass&lt;/h4&gt;
-&lt;p&gt;So how did you do? First, the error that &lt;code&gt;type Check already defined&lt;/code&gt; usually does mean that &lt;code&gt;Check&lt;/code&gt; was already defined elsewhere. Looking in the app folder though, there was nothing of the sort. It's the only one there that was &lt;code&gt;Check.java&lt;/code&gt;. But remember the secure module? Modules work by providing source files and Play just compiles them all together. Bingo, &lt;code&gt;Check.java&lt;/code&gt;. Doing a diff shows nothing was changed. So the solution really was just simply delete &lt;code&gt;Check.java&lt;/code&gt; and also &lt;code&gt;Secure.java&lt;/code&gt;. No more compilation errors!&lt;/p&gt;
-&lt;p&gt;The next question is, how do you get the initial user? There actually is some code that looks like it creates the default admin user,&lt;/p&gt;
-&lt;pre class="code literal-block"&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Security&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;isConnected&lt;/span&gt;&lt;span class="o"&gt;())&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
-    &lt;span class="o"&gt;...&lt;/span&gt;
-    &lt;span class="n"&gt;Account&lt;/span&gt; &lt;span class="n"&gt;account&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Account&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;find&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"username = ?"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Security&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;connected&lt;/span&gt;&lt;span class="o"&gt;()).&lt;/span&gt;&lt;span class="na"&gt;first&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
-    &lt;span class="o"&gt;...&lt;/span&gt;
-    &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;account&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;Account&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;count&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
-        &lt;span class="n"&gt;account&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;Account&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"admin"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"admin"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"admin@test.com"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
-        &lt;span class="n"&gt;account&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;save&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
-    &lt;span class="o"&gt;}&lt;/span&gt;
-    &lt;span class="o"&gt;...&lt;/span&gt;
-&lt;span class="o"&gt;}&lt;/span&gt;
-&lt;/pre&gt;
-
-
-&lt;p&gt;You can actually see this in action at &lt;code&gt;23:32:41,051&lt;/code&gt; in the log. So what's wrong with all of this? The account creation happened after I've already logged in. In fact, &lt;code&gt;Security.isConnected()&lt;/code&gt; checks whether the user is already logged in or not. How does this even make sense?&lt;/p&gt;
-&lt;p&gt;Lastly, we have the problem of the agencies. Just by looking at the log, you can safely say we're missing a file called &lt;code&gt;initial-agencies-data.yml&lt;/code&gt;. Ok, apparently it's a &lt;a href="http://www.playframework.com/documentation/1.2.5/test#fixtures"&gt;fixture&lt;/a&gt; like you would use for testing. It's easy enough to infer what the file's contents should be. We just copy it over from the GTFS data.&lt;/p&gt;
-&lt;p&gt;But then where do you put the file? If you look at the log, it says &lt;code&gt;/Users/thomas/.root/opt/play-1.2.5/modules/docviewer/app/initial-agencies-data.yml&lt;/code&gt; but that doesn't look right. That's in the Play distribution directory, probably not somewhere something app-specific should go into. Well, a fixture is used for testing, so maybe the &lt;code&gt;test/&lt;/code&gt; directory? No, that doesn't work either since we're not running a test.&lt;/p&gt;
-&lt;p&gt;What I ended up doing was just looking at the sources for &lt;code&gt;Fixtures.load&lt;/code&gt;. If you follow the stack trace, you end up finding &lt;code&gt;Play.javaPath&lt;/code&gt; which sort of works like PATH for Fixtures and some other things. So where can we put the file? &lt;code&gt;app/&lt;/code&gt; and &lt;code&gt;conf/&lt;/code&gt;. And with that, we're done.&lt;/p&gt;
-&lt;h4 id="conclusion"&gt;Conclusion&lt;/h4&gt;
-
-&lt;p&gt;GTFS Editor is very much in development. Just getting it to run was problematic. There also seem to be a lot of missing issues judging from the Github Issues page. If you want to try it out for yourself, I suggest you clone &lt;a href="https://github.com/thatsmydoing/gtfs-editor"&gt;my branch&lt;/a&gt; as I've fixed the issues discussed earlier. The default login is &lt;code&gt;admin:admin&lt;/code&gt;.&lt;/p&gt;
-&lt;p&gt;Even after getting it to run, it's still not quite usable. Not in the UX sense, but you really can't do much with it. There is no way to import the GTFS data into the webapp. There is something like import from TransitWand but even that is unclear to me. And even if we do get that running as well, we still don't have any data we can play around with. We would need database dumps from the already running tools for these to be of any use right now.&lt;/p&gt;&lt;/div&gt;</description><category>lets-debug</category><category>philippine-transit-app</category><category>programming</category><guid>http://pleasantprogrammer.com/posts/gtfs-editor.html</guid><pubDate>Wed, 10 Jul 2013 03:30:01 GMT</pubDate></item></channel></rss>
+&lt;p&gt;Side note: I'd also actually really like to hear about the DOTC developers' experience with the project. It would be nice if they had a devblog.&lt;/p&gt;&lt;/div&gt;</description><category>philippine-transit-app</category><category>programming</category><guid>http://pleasantprogrammer.com/posts/fare-data.html</guid><pubDate>Sat, 13 Jul 2013 13:15:09 GMT</pubDate></item></channel></rss>

+ 35 - 27
output/sitemap.xml

@@ -6,110 +6,118 @@
                         http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
  <url>
   <loc>http://pleasantprogrammer.com/2013/index.html</loc>
-  <lastmod>2015-01-17</lastmod>
+  <lastmod>2015-06-07</lastmod>
+ </url>
+ <url>
+  <loc>http://pleasantprogrammer.com/2015/index.html</loc>
+  <lastmod>2015-06-07</lastmod>
  </url>
  <url>
   <loc>http://pleasantprogrammer.com/archive.html</loc>
-  <lastmod>2015-01-17</lastmod>
+  <lastmod>2015-06-07</lastmod>
  </url>
  <url>
   <loc>http://pleasantprogrammer.com/categories/index.html</loc>
-  <lastmod>2015-01-17</lastmod>
+  <lastmod>2015-06-07</lastmod>
  </url>
  <url>
   <loc>http://pleasantprogrammer.com/categories/lets-debug.html</loc>
-  <lastmod>2015-01-17</lastmod>
+  <lastmod>2015-06-07</lastmod>
  </url>
  <url>
   <loc>http://pleasantprogrammer.com/categories/philippine-transit-app.html</loc>
-  <lastmod>2015-01-17</lastmod>
+  <lastmod>2015-06-07</lastmod>
  </url>
  <url>
   <loc>http://pleasantprogrammer.com/categories/programming.html</loc>
-  <lastmod>2015-01-17</lastmod>
+  <lastmod>2015-06-07</lastmod>
  </url>
  <url>
   <loc>http://pleasantprogrammer.com/categories/sysadmin.html</loc>
-  <lastmod>2015-01-17</lastmod>
+  <lastmod>2015-06-07</lastmod>
  </url>
  <url>
   <loc>http://pleasantprogrammer.com/categories/systemd.html</loc>
-  <lastmod>2015-01-17</lastmod>
+  <lastmod>2015-06-07</lastmod>
  </url>
  <url>
   <loc>http://pleasantprogrammer.com/galleries/index.html</loc>
-  <lastmod>2015-01-17</lastmod>
+  <lastmod>2015-06-07</lastmod>
  </url>
  <url>
   <loc>http://pleasantprogrammer.com/galleries/transit/index.html</loc>
-  <lastmod>2015-01-17</lastmod>
+  <lastmod>2015-06-07</lastmod>
  </url>
  <url>
   <loc>http://pleasantprogrammer.com/index-1.html</loc>
-  <lastmod>2015-01-17</lastmod>
+  <lastmod>2015-06-07</lastmod>
  </url>
  <url>
   <loc>http://pleasantprogrammer.com/index-2.html</loc>
-  <lastmod>2015-01-17</lastmod>
+  <lastmod>2015-06-07</lastmod>
  </url>
  <url>
   <loc>http://pleasantprogrammer.com/index.html</loc>
-  <lastmod>2015-01-17</lastmod>
+  <lastmod>2015-06-07</lastmod>
  </url>
  <url>
   <loc>http://pleasantprogrammer.com/posts/console-keymap-switching.html</loc>
-  <lastmod>2015-01-17</lastmod>
+  <lastmod>2015-06-07</lastmod>
  </url>
  <url>
   <loc>http://pleasantprogrammer.com/posts/elevation-data-in-otp.html</loc>
-  <lastmod>2015-01-17</lastmod>
+  <lastmod>2015-06-07</lastmod>
  </url>
  <url>
   <loc>http://pleasantprogrammer.com/posts/fare-data.html</loc>
-  <lastmod>2015-01-17</lastmod>
+  <lastmod>2015-06-07</lastmod>
  </url>
  <url>
   <loc>http://pleasantprogrammer.com/posts/geocoding-services.html</loc>
-  <lastmod>2015-01-17</lastmod>
+  <lastmod>2015-06-07</lastmod>
  </url>
  <url>
   <loc>http://pleasantprogrammer.com/posts/graphserver.html</loc>
-  <lastmod>2015-01-17</lastmod>
+  <lastmod>2015-06-07</lastmod>
  </url>
  <url>
   <loc>http://pleasantprogrammer.com/posts/gtfs-editor.html</loc>
-  <lastmod>2015-01-17</lastmod>
+  <lastmod>2015-06-07</lastmod>
  </url>
  <url>
   <loc>http://pleasantprogrammer.com/posts/highways-in-otp.html</loc>
-  <lastmod>2015-01-17</lastmod>
+  <lastmod>2015-06-07</lastmod>
+ </url>
+ <url>
+  <loc>http://pleasantprogrammer.com/posts/is-my-terminal-window-active.html</loc>
+  <lastmod>2015-06-07</lastmod>
  </url>
  <url>
   <loc>http://pleasantprogrammer.com/posts/jeep-and-bus-schedules.html</loc>
-  <lastmod>2015-01-17</lastmod>
+  <lastmod>2015-06-07</lastmod>
  </url>
  <url>
   <loc>http://pleasantprogrammer.com/posts/jeepney-and-bus-routes.html</loc>
-  <lastmod>2015-01-17</lastmod>
+  <lastmod>2015-06-07</lastmod>
  </url>
  <url>
   <loc>http://pleasantprogrammer.com/posts/one-bus-or-maybe-jeep-away.html</loc>
-  <lastmod>2015-01-17</lastmod>
+  <lastmod>2015-06-07</lastmod>
  </url>
  <url>
   <loc>http://pleasantprogrammer.com/posts/open-trip-planner.html</loc>
-  <lastmod>2015-01-17</lastmod>
+  <lastmod>2015-06-07</lastmod>
  </url>
  <url>
   <loc>http://pleasantprogrammer.com/posts/philippine-transit-app-challenge.html</loc>
-  <lastmod>2015-01-17</lastmod>
+  <lastmod>2015-06-07</lastmod>
  </url>
  <url>
   <loc>http://pleasantprogrammer.com/posts/removing-pldtmydslbiz-from-the-zyxel-p-2612hnu.html</loc>
-  <lastmod>2015-01-17</lastmod>
+  <lastmod>2015-06-07</lastmod>
  </url>
  <url>
   <loc>http://pleasantprogrammer.com/posts/transit-wand.html</loc>
-  <lastmod>2015-01-17</lastmod>
+  <lastmod>2015-06-07</lastmod>
  </url>
 </urlset>

+ 9 - 9
output/sitemapindex.xml

@@ -6,38 +6,38 @@
                         http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
  <sitemap>
   <loc>http://pleasantprogrammer.com/categories/lets-debug.xml</loc>
-  <lastmod>2015-01-17</lastmod>
+  <lastmod>2015-06-07</lastmod>
  </sitemap>
  <sitemap>
   <loc>http://pleasantprogrammer.com/categories/philippine-transit-app.xml</loc>
-  <lastmod>2015-01-17</lastmod>
+  <lastmod>2015-06-07</lastmod>
  </sitemap>
  <sitemap>
   <loc>http://pleasantprogrammer.com/categories/programming.xml</loc>
-  <lastmod>2015-01-17</lastmod>
+  <lastmod>2015-06-07</lastmod>
  </sitemap>
  <sitemap>
   <loc>http://pleasantprogrammer.com/categories/sysadmin.xml</loc>
-  <lastmod>2015-01-17</lastmod>
+  <lastmod>2015-06-07</lastmod>
  </sitemap>
  <sitemap>
   <loc>http://pleasantprogrammer.com/categories/systemd.xml</loc>
-  <lastmod>2015-01-17</lastmod>
+  <lastmod>2015-06-07</lastmod>
  </sitemap>
  <sitemap>
   <loc>http://pleasantprogrammer.com/galleries/rss.xml</loc>
-  <lastmod>2015-01-17</lastmod>
+  <lastmod>2015-06-07</lastmod>
  </sitemap>
  <sitemap>
   <loc>http://pleasantprogrammer.com/galleries/transit/rss.xml</loc>
-  <lastmod>2015-01-17</lastmod>
+  <lastmod>2015-06-07</lastmod>
  </sitemap>
  <sitemap>
   <loc>http://pleasantprogrammer.com/rss.xml</loc>
-  <lastmod>2015-01-17</lastmod>
+  <lastmod>2015-06-07</lastmod>
  </sitemap>
  <sitemap>
   <loc>http://pleasantprogrammer.com/sitemap.xml</loc>
-  <lastmod>2015-01-17</lastmod>
+  <lastmod>2015-06-07</lastmod>
  </sitemap>
 </sitemapindex>

+ 40 - 0
posts/is-my-terminal-window-active.md

@@ -0,0 +1,40 @@
+<!--
+.. title: Is My Terminal Window Active?
+.. slug: is-my-terminal-window-active
+.. date: 2015-06-07 16:20:45 UTC+08:00
+.. tags: programming
+.. category:
+.. link:
+.. description:
+.. type: text
+-->
+
+I've been working in OSX for almost 3 years now, but I recently switched back to Linux because of all the problems people encountered with Yosemite. There are some things I missed from OSX though. One of which is [zsh-notify](https://github.com/marzocchi/zsh-notify). It's a zsh plugin that alerts you if your long-running task is complete, and whether it failed or not.
+
+It's pretty convenient when you're compiling something and then go on to browse reddit while waiting. Usually, I spend too much time just reading and forget about the compilation entirely. With the plugin, I get the notification and maybe go back to work.
+
+One nice feature it has is that if you're currently looking at the terminal window of the job that just finished, it won't notify you. It only notifies on windows that aren't currently in focus. To do this, it has to actually talk to Terminal.app or iTerm2 to see if the window and tab are active.
+
+This is alright in OSX since those 2 are the generally most used terminal emulators. On Linux though, everyone has their own favorite terminal. Given that, I figured I could probably rely on talking to X to see if the window is active instead of each single terminal emulator. X can't tell if the tab is active though, but I don't use tabs in my current setup so it should still be good.
+
+## xdotool
+
+[Preliminary research](http://superuser.com/questions/382616/detecting-currently-active-window) reveals that we can easily get what the active window is with xdotool. `xdotool getactivewindow` gives us the X window id of the active one. Now all we need is a way to get the window id of the terminal we're in.
+
+## First Attempt: $WINDOWID
+
+Apparently, xterm and similar terminal emulators define an environment variable called `$WINDOWID` with the window id of the terminal. Obviously, this is too good to be true. In xterm and konsole the `$WINDOWID` was correct, but in VTE-based terminal emulators, `$WINDOWID` had the wrong value. In terminology, it didn't define `$WINDOWID` altogether. So `$WINDOWID` wasn't going to work.
+
+## Second Attempt: xdotool search $MAGIC
+
+My second idea was that you can use zsh to change the window title to a magic number and then just check if the active window is the same one as the window with the magic number. This sort of worked for most terminals, except konsole which does whatever it wants with the window title. There's also the problem of some zsh configs automatically settings the window title to the current command.
+
+In hindsight, I could probably have just done `xdotool search --name xdotool` since in most cases, when you run the search, zsh or konsole will set the window name to the current command. Maybe that's another option I can explore some day.
+
+## Third Attempt: $PPID
+
+My third idea was another environment variable called `$PPID`, which is the process id of the parent of the shell. As it happens, the parent is the window containing the zsh instance. This is actually pretty consistent across most terminals. The only problem was if you launched zsh from another shell since your new zsh's parent will now be another zsh instance instead of an X window.
+
+At first glance, launching zsh within zsh doesn't seem like something most people would do, but this is what happens when you run screen or tmux. To work around this, we can actually just save the original `$PPID` in a different variable and use that instead.
+
+Now that we have the PID of the window from zsh, we can once again use xdotool to get the PID of the current active window with `xdotool getactivewindow getwindowpid`. We just simply compare that with our `$PPID` and we can tell if we're in an active window or not. Overall, this approach worked surprisingly well so that's the final solution I went with.

Některé soubory nejsou zobrazeny, neboť je v těchto rozdílových datech změněno mnoho souborů