|
@@ -1,232 +1,784 @@
|
|
-<?xml version="1.0" encoding="utf-8"?>
|
|
|
|
-<?xml-stylesheet type="text/xsl" href="assets/xml/rss.xsl" media="all"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>Pleasant Programmer</title><link>http://pleasantprogrammer.com/</link><description></description><atom:link type="application/rss+xml" rel="self" href="http://pleasantprogrammer.com/rss.xml"></atom:link><language>en</language><lastBuildDate>Fri, 25 Dec 2015 07:29:48 GMT</lastBuildDate><generator>https://getnikola.com/</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>Cloudflare Shenanigans</title><link>http://pleasantprogrammer.com/posts/cloudflare-shenanigans.html</link><dc:creator>Thomas Dy</dc:creator><description><div><p>An old client of ours managed to convince a telco to zero-rate the data for their app. In order to whitelist it though, we needed to use plain HTTP for domain whitelisting. For HTTPS, they can only whitelist by IP address. Like any good developer, we were using HTTPS. Also, like any good developer, we put our server behind Cloudflare.</p>
|
|
|
|
-<p>Now the problem is that Cloudflare can put you behind <a href="https://www.cloudflare.com/ips/">any IP they own</a>, which is a huge range. There's no guarantee that the IP we have now is going to be the same later on. So we did the reasonable thing and asked them to whitelist all of the Cloudflare IPs. And the telco agreed! We were in total disbelief when that happened. But hey, if life gives you free internet, you take it.</p>
|
|
|
|
|
|
+<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
|
|
|
|
+<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
|
|
|
|
+ <channel>
|
|
|
|
+ <title>Pleasant Programmer</title>
|
|
|
|
+ <link>http://pleasantprogrammer.com/</link>
|
|
|
|
+ <description>Recent content on Pleasant Programmer</description>
|
|
|
|
+ <generator>Hugo -- gohugo.io</generator>
|
|
|
|
+ <language>en-us</language>
|
|
|
|
+ <lastBuildDate>Fri, 25 Dec 2015 00:00:00 +0000</lastBuildDate>
|
|
|
|
+ <atom:link href="http://pleasantprogrammer.com/rss.xml" rel="self" type="application/rss+xml" />
|
|
|
|
+
|
|
|
|
+ <item>
|
|
|
|
+ <title>Cloudflare Shenanigans</title>
|
|
|
|
+ <link>http://pleasantprogrammer.com/posts/cloudflare-shenanigans.html</link>
|
|
|
|
+ <pubDate>Fri, 25 Dec 2015 00:00:00 +0000</pubDate>
|
|
|
|
+
|
|
|
|
+ <guid>http://pleasantprogrammer.com/posts/cloudflare-shenanigans.html</guid>
|
|
|
|
+ <description><p>An old client of ours managed to convince a telco to zero-rate the data for their app. In order to whitelist it though, we needed to use plain HTTP for domain whitelisting. For HTTPS, they can only whitelist by IP address. Like any good developer, we were using HTTPS. Also, like any good developer, we put our server behind Cloudflare.</p>
|
|
|
|
+
|
|
|
|
+<p>Now the problem is that Cloudflare can put you behind <a href="https://www.cloudflare.com/ips/">any IP they own</a>, which is a huge range. There&rsquo;s no guarantee that the IP we have now is going to be the same later on. So we did the reasonable thing and asked them to whitelist all of the Cloudflare IPs. And the telco agreed! We were in total disbelief when that happened. But hey, if life gives you free internet, you take it.</p>
|
|
|
|
+
|
|
<p>We never actually empirically tested whether other sites hosted on Cloudflare were also actually zero-rated. But I like to think that we saved a lot of people on their data costs from browsing Reddit and 4chan. But alas, good things must come to an end.</p>
|
|
<p>We never actually empirically tested whether other sites hosted on Cloudflare were also actually zero-rated. But I like to think that we saved a lot of people on their data costs from browsing Reddit and 4chan. But alas, good things must come to an end.</p>
|
|
-<p>A few months after we started beta testing the app, Cloudflare added more IPs to their range. Unfortunately, our server got moved to those new IPs which were not whitelisted yet. Apparently, the telco whitelisting process was incredibly convoluted and time consuming. Our client didn't want to bother asking them to whitelist more IPs. We also tried asking Cloudflare to move us back to the original IP range, but they could only do that if we were in their enterprise tier. We couldn't really afford that, so we looked for other options.</p>
|
|
|
|
-<p>Since Cloudflare was essentially just a giant reverse proxy, theoretically there should be no distinction between one IP address from another. The specific IP we get is probably just for load balancing. So we tried accessing the IPs in the range directly and just setting the Host header and it worked! But we get SSL errors because the IP itself doesn't have its own certificate.</p>
|
|
|
|
|
|
+
|
|
|
|
+<p>A few months after we started beta testing the app, Cloudflare added more IPs to their range. Unfortunately, our server got moved to those new IPs which were not whitelisted yet. Apparently, the telco whitelisting process was incredibly convoluted and time consuming. Our client didn&rsquo;t want to bother asking them to whitelist more IPs. We also tried asking Cloudflare to move us back to the original IP range, but they could only do that if we were in their enterprise tier. We couldn&rsquo;t really afford that, so we looked for other options.</p>
|
|
|
|
+
|
|
|
|
+<p>Since Cloudflare was essentially just a giant reverse proxy, theoretically there should be no distinction between one IP address from another. The specific IP we get is probably just for load balancing. So we tried accessing the IPs in the range directly and just setting the Host header and it worked! But we get SSL errors because the IP itself doesn&rsquo;t have its own certificate.</p>
|
|
|
|
+
|
|
<p>After more testing, we figured out that you could actually use any Cloudflare backed domain so long as we properly set the Host header. We just needed to find one still in the old range. Coincidentally, 4chan.org was. Which led to this wonderful commit</p>
|
|
<p>After more testing, we figured out that you could actually use any Cloudflare backed domain so long as we properly set the Host header. We just needed to find one still in the old range. Coincidentally, 4chan.org was. Which led to this wonderful commit</p>
|
|
-<pre class="code literal-block">commit 123456789abcdef
|
|
|
|
|
|
+<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%">commit 123456789abcdef
|
|
Author: ~~~~~~
|
|
Author: ~~~~~~
|
|
Date: ~~~~~~
|
|
Date: ~~~~~~
|
|
|
|
|
|
4chan hack
|
|
4chan hack
|
|
|
|
|
|
-<span class="gh">diff --git a/src/com/client/common/Util.java b/src/com/client/common/Util.java</span>
|
|
|
|
-<span class="gd">--- a/src/com/client/common/Util.java</span>
|
|
|
|
-<span class="gi">+++ b/src/com/client/common/Util.java</span>
|
|
|
|
-<span class="gu">@@ -210,7 +210,8 @@ public class Util {</span>
|
|
|
|
|
|
+<span style="color: #000080; font-weight: bold">diff --git a/src/com/client/common/Util.java b/src/com/client/common/Util.java</span>
|
|
|
|
+<span style="color: #A00000">--- a/src/com/client/common/Util.java</span>
|
|
|
|
+<span style="color: #00A000">+++ b/src/com/client/common/Util.java</span>
|
|
|
|
+<span style="color: #800080; font-weight: bold">@@ -210,7 +210,8 @@ public class Util {</span>
|
|
}
|
|
}
|
|
|
|
|
|
public static String getServerAddress(Context context) {
|
|
public static String getServerAddress(Context context) {
|
|
-<span class="gd">- String address = "https://backend.client.com";</span>
|
|
|
|
-<span class="gi">+ // String address = "https://backend.client.com";</span>
|
|
|
|
-<span class="gi">+ String address = "https://4chan.org";</span>
|
|
|
|
|
|
+<span style="color: #A00000">- String address = &quot;https://backend.client.com&quot;;</span>
|
|
|
|
+<span style="color: #00A000">+ // String address = &quot;https://backend.client.com&quot;;</span>
|
|
|
|
+<span style="color: #00A000">+ String address = &quot;https://4chan.org&quot;;</span>
|
|
if(!isDebug(context)) return address;
|
|
if(!isDebug(context)) return address;
|
|
try {
|
|
try {
|
|
-<span class="gh">diff --git a/src/com/client/common/logging/APIClient.java b/src/com/client/common/logging/APIClient.java</span>
|
|
|
|
-<span class="gd">--- a/src/com/client/common/logging/APIClient.java</span>
|
|
|
|
-<span class="gi">+++ b/src/com/client/common/logging/APIClient.java</span>
|
|
|
|
-<span class="gu">@@ -101,6 +101,7 @@ public class APIClient {</span>
|
|
|
|
|
|
+<span style="color: #000080; font-weight: bold">diff --git a/src/com/client/common/logging/APIClient.java b/src/com/client/common/logging/APIClient.java</span>
|
|
|
|
+<span style="color: #A00000">--- a/src/com/client/common/logging/APIClient.java</span>
|
|
|
|
+<span style="color: #00A000">+++ b/src/com/client/common/logging/APIClient.java</span>
|
|
|
|
+<span style="color: #800080; font-weight: bold">@@ -101,6 +101,7 @@ public class APIClient {</span>
|
|
private HttpResponse postInternal(String url, List&lt;NameValuePair&gt; data, boolean forRegistration) throws ClientProtocolException, IOException {
|
|
private HttpResponse postInternal(String url, List&lt;NameValuePair&gt; data, boolean forRegistration) throws ClientProtocolException, IOException {
|
|
- HttpPost request = new HttpPost(Util.getServerAddress(mContext)+"/api/"+url);
|
|
|
|
- request.setHeader("X-API-VERSION", apiVersion);
|
|
|
|
-<span class="gi">+ request.setHeader("Host", "backend.client.com");</span>
|
|
|
|
|
|
+ HttpPost request = new HttpPost(Util.getServerAddress(mContext)+&quot;/api/&quot;+url);
|
|
|
|
+ request.setHeader(&quot;X-API-VERSION&quot;, apiVersion);
|
|
|
|
+<span style="color: #00A000">+ request.setHeader(&quot;Host&quot;, &quot;backend.client.com&quot;);</span>
|
|
|
|
|
|
if(data == null) {
|
|
if(data == null) {
|
|
data = new ArrayList&lt;NameValuePair&gt;();
|
|
data = new ArrayList&lt;NameValuePair&gt;();
|
|
-</pre>
|
|
|
|
|
|
+</pre></div>
|
|
|
|
+
|
|
|
|
+<p>Eventually, we did decide to just abandon Cloudflare for the server. We probably weren&rsquo;t going to be the target of a DDOS or anything. This also allowed us to do more secure things like pinning the server certificate in the application itself. Clearly, this is what we should have just done in the first place, but at the time we just wanted a stopgap solution.</p>
|
|
|
|
+
|
|
|
|
+<p>I just still find it funny we were making people&rsquo;s phones go to 4chan.org everyday for more than a year.</p>
|
|
|
|
+</description>
|
|
|
|
+ </item>
|
|
|
|
+
|
|
|
|
+ <item>
|
|
|
|
+ <title>TiddlyWiki in the Sky (or TiddlyWeb for TW5)</title>
|
|
|
|
+ <link>http://pleasantprogrammer.com/posts/tiddlywiki-in-the-sky-or-tiddlyweb-for-tw5.html</link>
|
|
|
|
+ <pubDate>Thu, 24 Dec 2015 00:00:00 +0000</pubDate>
|
|
|
|
+
|
|
|
|
+ <guid>http://pleasantprogrammer.com/posts/tiddlywiki-in-the-sky-or-tiddlyweb-for-tw5.html</guid>
|
|
|
|
+ <description>
|
|
|
|
+
|
|
|
|
+<p>I&rsquo;ve always liked <a href="http://tiddlywiki.com">TiddlyWiki</a>. Back when it first came out, it was really amazing. A wiki all in one file, that worked in the browser. It didn&rsquo;t need a backend, it would just save itself as an all new HTML file with all your posts inside. I&rsquo;ve used it a lot over the years, as a personal wiki/journal and a class notebook. I even had a blog with it at one point using one of the server-side forks.</p>
|
|
|
|
+
|
|
|
|
+<p>Now, there&rsquo;s TiddlyWiki5 which is a rewrite of the original TiddlyWiki that looks a whole lot snazzier, and I assume has better architecture overall. It also has experimental support for all the server-side platforms (particularly TiddlyWeb) that have cropped up.</p>
|
|
|
|
|
|
|
|
+<p>If you&rsquo;re just looking for a simple server setup for TiddlyWiki5, it has native support for that on its own. There&rsquo;s plenty of documentation on the site. But if you&rsquo;re looking for more advanced features (like storing your posts in git or a database), then you&rsquo;ll need to use it with TiddlyWeb. The problem is that most of the documentation for TiddlyWeb still refers to the old TiddlyWiki.</p>
|
|
|
|
|
|
-<p>Eventually, we did decide to just abandon Cloudflare for the server. We probably weren't going to be the target of a DDOS or anything. This also allowed us to do more secure things like pinning the server certificate in the application itself. Clearly, this is what we should have just done in the first place, but at the time we just wanted a stopgap solution.</p>
|
|
|
|
-<p>I just still find it funny we were making people's phones go to 4chan.org everyday for more than a year.</p></div></description><category>cloudflare</category><category>sysadmin</category><guid>http://pleasantprogrammer.com/posts/cloudflare-shenanigans.html</guid><pubDate>Fri, 25 Dec 2015 06:13:26 GMT</pubDate></item><item><title>TiddlyWiki in the Sky (or TiddlyWeb for TW5)</title><link>http://pleasantprogrammer.com/posts/tiddlywiki-in-the-sky-or-tiddlyweb-for-tw5.html</link><dc:creator>Thomas Dy</dc:creator><description><div><p>I've always liked <a href="http://tiddlywiki.com">TiddlyWiki</a>. Back when it first came out, it was really amazing. A wiki all in one file, that worked in the browser. It didn't need a backend, it would just save itself as an all new HTML file with all your posts inside. I've used it a lot over the years, as a personal wiki/journal and a class notebook. I even had a blog with it at one point using one of the server-side forks.</p>
|
|
|
|
-<p>Now, there's TiddlyWiki5 which is a rewrite of the original TiddlyWiki that looks a whole lot snazzier, and I assume has better architecture overall. It also has experimental support for all the server-side platforms (particularly TiddlyWeb) that have cropped up.</p>
|
|
|
|
-<p>If you're just looking for a simple server setup for TiddlyWiki5, it has native support for that on its own. There's plenty of documentation on the site. But if you're looking for more advanced features (like storing your posts in git or a database), then you'll need to use it with TiddlyWeb. The problem is that most of the documentation for TiddlyWeb still refers to the old TiddlyWiki.</p>
|
|
|
|
-<p>To support TiddlyWiki5, we'll need a version of the wiki which has the TiddlyWeb plugin already installed and configured. After that, some tweaking is necessary to get TiddlyWeb to provide what the wiki requires.</p>
|
|
|
|
-<h3>Setting Up TiddlyWiki</h3>
|
|
|
|
-<p>TiddlyWiki5 provides a command line tool via <code>npm</code> that allows building custom versions of the wiki. In fact, it comes with templates, called "editions", that we can use for our setup. Assuming you already have it installed, create the wiki using</p>
|
|
|
|
-<pre class="code literal-block">tiddlywiki mywiki --init tw5tank # create wiki from template
|
|
|
|
-</pre>
|
|
|
|
|
|
+<p>To support TiddlyWiki5, we&rsquo;ll need a version of the wiki which has the TiddlyWeb plugin already installed and configured. After that, some tweaking is necessary to get TiddlyWeb to provide what the wiki requires.</p>
|
|
|
|
|
|
|
|
+<h2 id="setting-up-tiddlywiki:1f502be524b8b2be2ec53e61b7c9a5cf">Setting Up TiddlyWiki</h2>
|
|
|
|
|
|
-<p>This creates a wiki intended for use with <a href="https://tank.peermore.com/">Tank</a>, which is built on top of TiddlyWeb. From here, you should look in <code>mywiki/tiddlers/system</code> which contain the entries for <code>SiteTitle</code>, <code>SiteSubtitle</code>, <code>DefaultTiddlers</code>, and <code>tiddlyweb-host</code>. The first 3 should be configured however you want. These are necessary because they're needed before the wiki can load them from the server. <code>tiddlyweb-host</code> contains the location of the TiddlyWeb server, this should be <code>http://localhost:8080/</code> if you're just testing locally. With everything configured, you can build the new wiki by running</p>
|
|
|
|
-<pre class="code literal-block">tiddlywiki mywiki --build
|
|
|
|
-</pre>
|
|
|
|
|
|
+<p>TiddlyWiki5 provides a command line tool via <code>npm</code> that allows building custom versions of the wiki. In fact, it comes with templates, called &ldquo;editions&rdquo;, that we can use for our setup. Assuming you already have it installed, create the wiki using</p>
|
|
|
|
+<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%">tiddlywiki mywiki --init tw5tank <span style="color: #408080; font-style: italic"># create wiki from template</span>
|
|
|
|
+</pre></div>
|
|
|
|
|
|
|
|
+<p>This creates a wiki intended for use with <a href="https://tank.peermore.com/">Tank</a>, which is built on top of TiddlyWeb. From here, you should look in <code>mywiki/tiddlers/system</code> which contain the entries for <code>SiteTitle</code>, <code>SiteSubtitle</code>, <code>DefaultTiddlers</code>, and <code>tiddlyweb-host</code>. The first 3 should be configured however you want. These are necessary because they&rsquo;re needed before the wiki can load them from the server. <code>tiddlyweb-host</code> contains the location of the TiddlyWeb server, this should be <code>http://localhost:8080/</code> if you&rsquo;re just testing locally. With everything configured, you can build the new wiki by running</p>
|
|
|
|
+<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%">tiddlywiki mywiki --build
|
|
|
|
+</pre></div>
|
|
|
|
|
|
<p>This will output the wiki to <code>mywiki/output/tw5tank.html</code>. You can now serve it using your favorite local webserver, like <code>python -m http.server</code>.</p>
|
|
<p>This will output the wiki to <code>mywiki/output/tw5tank.html</code>. You can now serve it using your favorite local webserver, like <code>python -m http.server</code>.</p>
|
|
-<h3>Setting Up TiddlyWeb</h3>
|
|
|
|
-<p>The TiddlyWeb tutorial recommends using <code>tiddlywebwiki</code> which has all the plugins setup for a nice wiki instance for the old TiddlyWiki. It has a lot of features that aren't really needed, so we won't go with that. So first, we'll need to install TiddlyWeb and any plugins we might want to use.</p>
|
|
|
|
-<pre class="code literal-block">pip install tiddlyweb tiddlywebplugins.status tiddlywebplugins.cherrypy tiddlywebplugins.cors
|
|
|
|
-</pre>
|
|
|
|
|
|
|
|
|
|
+<h2 id="setting-up-tiddlyweb:1f502be524b8b2be2ec53e61b7c9a5cf">Setting Up TiddlyWeb</h2>
|
|
|
|
|
|
-<p>Next, we'll need the tiddlyweb configuration in <code>tiddlywebconfig.py</code></p>
|
|
|
|
-<pre class="code literal-block"><span class="c"># A basic configuration.</span>
|
|
|
|
-<span class="c"># `pydoc tiddlyweb.config` for details on configuration items.</span>
|
|
|
|
|
|
+<p>The TiddlyWeb tutorial recommends using <code>tiddlywebwiki</code> which has all the plugins setup for a nice wiki instance for the old TiddlyWiki. It has a lot of features that aren&rsquo;t really needed, so we won&rsquo;t go with that. So first, we&rsquo;ll need to install TiddlyWeb and any plugins we might want to use.</p>
|
|
|
|
+<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%">pip install tiddlyweb tiddlywebplugins.status tiddlywebplugins.cherrypy tiddlywebplugins.cors
|
|
|
|
+</pre></div>
|
|
|
|
|
|
-<span class="kn">import</span> <span class="nn">tiddlywebplugins.status</span>
|
|
|
|
|
|
+<p>Next, we&rsquo;ll need the tiddlyweb configuration in <code>tiddlywebconfig.py</code></p>
|
|
|
|
+<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span style="color: #408080; font-style: italic"># A basic configuration.</span>
|
|
|
|
+<span style="color: #408080; font-style: italic"># `pydoc tiddlyweb.config` for details on configuration items.</span>
|
|
|
|
|
|
-<span class="n">config</span> <span class="o">=</span> <span class="p">{</span>
|
|
|
|
- <span class="s">'system_plugins'</span><span class="p">:</span> <span class="p">[</span><span class="s">'tiddlywebplugins.status'</span><span class="p">,</span> <span class="s">'tiddlywebplugins.cors'</span><span class="p">],</span>
|
|
|
|
- <span class="s">'secret'</span><span class="p">:</span> <span class="s">'36c98d6d14618c79f0ed2d49cd1b9e272d8d4bd0'</span><span class="p">,</span>
|
|
|
|
- <span class="s">'wsgi_server'</span><span class="p">:</span> <span class="s">'tiddlywebplugins.cherrypy'</span><span class="p">,</span>
|
|
|
|
- <span class="s">'cors.enable_non_simple'</span><span class="p">:</span> <span class="bp">True</span>
|
|
|
|
-<span class="p">}</span>
|
|
|
|
|
|
+<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">tiddlywebplugins.status</span>
|
|
|
|
|
|
-<span class="n">original_gather_data</span> <span class="o">=</span> <span class="n">tiddlywebplugins</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">_gather_data</span>
|
|
|
|
|
|
+config <span style="color: #666666">=</span> {
|
|
|
|
+ <span style="color: #BA2121">&#39;system_plugins&#39;</span>: [<span style="color: #BA2121">&#39;tiddlywebplugins.status&#39;</span>, <span style="color: #BA2121">&#39;tiddlywebplugins.cors&#39;</span>],
|
|
|
|
+ <span style="color: #BA2121">&#39;secret&#39;</span>: <span style="color: #BA2121">&#39;36c98d6d14618c79f0ed2d49cd1b9e272d8d4bd0&#39;</span>,
|
|
|
|
+ <span style="color: #BA2121">&#39;wsgi_server&#39;</span>: <span style="color: #BA2121">&#39;tiddlywebplugins.cherrypy&#39;</span>,
|
|
|
|
+ <span style="color: #BA2121">&#39;cors.enable_non_simple&#39;</span>: <span style="color: #008000">True</span>
|
|
|
|
+}
|
|
|
|
|
|
-<span class="k">def</span> <span class="nf">_status_gather_data</span><span class="p">(</span><span class="n">environ</span><span class="p">):</span>
|
|
|
|
- <span class="n">data</span> <span class="o">=</span> <span class="n">original_gather_data</span><span class="p">(</span><span class="n">environ</span><span class="p">)</span>
|
|
|
|
- <span class="n">data</span><span class="p">[</span><span class="s">'space'</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="s">'recipe'</span><span class="p">:</span> <span class="s">'default'</span><span class="p">}</span>
|
|
|
|
- <span class="k">return</span> <span class="n">data</span>
|
|
|
|
|
|
+original_gather_data <span style="color: #666666">=</span> tiddlywebplugins<span style="color: #666666">.</span>status<span style="color: #666666">.</span>_gather_data
|
|
|
|
|
|
-<span class="n">tiddlywebplugins</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">_gather_data</span> <span class="o">=</span> <span class="n">_status_gather_data</span>
|
|
|
|
-</pre>
|
|
|
|
|
|
+<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">_status_gather_data</span>(environ):
|
|
|
|
+ data <span style="color: #666666">=</span> original_gather_data(environ)
|
|
|
|
+ data[<span style="color: #BA2121">&#39;space&#39;</span>] <span style="color: #666666">=</span> {<span style="color: #BA2121">&#39;recipe&#39;</span>: <span style="color: #BA2121">&#39;default&#39;</span>}
|
|
|
|
+ <span style="color: #008000; font-weight: bold">return</span> data
|
|
|
|
|
|
|
|
+tiddlywebplugins<span style="color: #666666">.</span>status<span style="color: #666666">.</span>_gather_data <span style="color: #666666">=</span> _status_gather_data
|
|
|
|
+</pre></div>
|
|
|
|
|
|
<p>The tweaks involved are:</p>
|
|
<p>The tweaks involved are:</p>
|
|
|
|
+
|
|
<ul>
|
|
<ul>
|
|
<li>using the status plugin which the wiki requires</li>
|
|
<li>using the status plugin which the wiki requires</li>
|
|
-<li>monkeypatching the status plugin for the wiki to use the correct "recipe"</li>
|
|
|
|
|
|
+<li>monkeypatching the status plugin for the wiki to use the correct &ldquo;recipe&rdquo;</li>
|
|
<li>using cherrypy server instead of the buggy default one</li>
|
|
<li>using cherrypy server instead of the buggy default one</li>
|
|
-<li>using cors since we're not hosting the wiki itself on the same server</li>
|
|
|
|
|
|
+<li>using cors since we&rsquo;re not hosting the wiki itself on the same server</li>
|
|
</ul>
|
|
</ul>
|
|
-<p>With that, we just need to create the store that will hold our data</p>
|
|
|
|
-<pre class="code literal-block">twanager recipe default &lt;&lt;EOF
|
|
|
|
-desc: standard TiddlyWebWiki environment
|
|
|
|
-policy: {"read": [], "create": [], "manage": ["R:ADMIN"], "accept": [], "write": ["R:ADMIN"], "owner": "administrator", "delete": ["R:ADMIN"]}
|
|
|
|
|
|
|
|
-/bags/default/tiddlers
|
|
|
|
-EOF
|
|
|
|
|
|
+<p>With that, we just need to create the store that will hold our data</p>
|
|
|
|
+<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%">twanager recipe default <span style="color: #BA2121">&lt;&lt;EOF</span>
|
|
|
|
+<span style="color: #BA2121">desc: standard TiddlyWebWiki environment</span>
|
|
|
|
+<span style="color: #BA2121">policy: {&quot;read&quot;: [], &quot;create&quot;: [], &quot;manage&quot;: [&quot;R:ADMIN&quot;], &quot;accept&quot;: [], &quot;write&quot;: [&quot;R:ADMIN&quot;], &quot;owner&quot;: &quot;administrator&quot;, &quot;delete&quot;: [&quot;R:ADMIN&quot;]}</span>
|
|
|
|
|
|
-twanager bag default &lt;&lt;EOF
|
|
|
|
-{"policy": {"read": [], "create": [], "manage": ["R:ADMIN"], "accept": [], "write": [], "owner": "administrator", "delete": []}}
|
|
|
|
-EOF
|
|
|
|
-</pre>
|
|
|
|
|
|
+<span style="color: #BA2121">/bags/default/tiddlers</span>
|
|
|
|
+<span style="color: #BA2121">EOF</span>
|
|
|
|
|
|
|
|
+twanager bag default <span style="color: #BA2121">&lt;&lt;EOF</span>
|
|
|
|
+<span style="color: #BA2121">{&quot;policy&quot;: {&quot;read&quot;: [], &quot;create&quot;: [], &quot;manage&quot;: [&quot;R:ADMIN&quot;], &quot;accept&quot;: [], &quot;write&quot;: [], &quot;owner&quot;: &quot;administrator&quot;, &quot;delete&quot;: []}}</span>
|
|
|
|
+<span style="color: #BA2121">EOF</span>
|
|
|
|
+</pre></div>
|
|
|
|
|
|
<p>Finally, we can start the TiddlyWeb server</p>
|
|
<p>Finally, we can start the TiddlyWeb server</p>
|
|
-<pre class="code literal-block">twanager server
|
|
|
|
-</pre>
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-<h3>Putting it all together</h3>
|
|
|
|
-<p>Once you have the TiddlyWeb server running, you can just go to wherever you're hosting the wiki html and it should work. You can try creating some posts, and the check mark on the sidebar should be red for a while and then turn black. Once that's done it's saved. You can refresh your browser and your posts should still be there.</p>
|
|
|
|
-<p>At this point, you can start customizing your TiddlyWeb instance, by changing your store to something like a database, or adding authorization. You can also tweak the server setup so you won't need CORS anymore.</p>
|
|
|
|
-<p>TiddlyWiki5 is still relatively new. I hope that eventually, support for server-side and the plugin ecosystem grows to be as great as the old TiddlyWiki.</p></div></description><category>sysadmin</category><category>tiddlywiki</category><guid>http://pleasantprogrammer.com/posts/tiddlywiki-in-the-sky-or-tiddlyweb-for-tw5.html</guid><pubDate>Thu, 24 Dec 2015 06:48:20 GMT</pubDate></item><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><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></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><div><p>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 <em>does not</em> allow you to remove the prefix.</p>
|
|
|
|
-<p>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.</p>
|
|
|
|
-<p>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 <a href="http://www.phandroidinternet.com/2013/06/how-to-remove-on-wifi-name-or-ssid-on.html">Prolink H5004N</a> or the <a href="http://www.symbianize.com/showthread.php?t=730091">ZyXEL P-660HN-T1A</a> but not for the one we got which was the ZyXEL P-2612HNU-F1F.</p>
|
|
|
|
-<p>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.</p>
|
|
|
|
-<p>The backup is actually just an XML file. You can search for SSID and change the parameter there. It's a bit annoying because the router has to restart after restoring the configuration, but it works!</p>
|
|
|
|
-<p>A minor note, the router doesn't seem to support SSIDs with a comma (,) well. It just gets everything before the comma as the SSID for some reason.</p></div></description><category>sysadmin</category><guid>http://pleasantprogrammer.com/posts/removing-pldtmydslbiz-from-the-zyxel-p-2612hnu.html</guid><pubDate>Wed, 27 Nov 2013 02:12:31 GMT</pubDate></item><item><title>Console Keymap Switching</title><link>http://pleasantprogrammer.com/posts/console-keymap-switching.html</link><dc:creator>Thomas Dy</dc:creator><description><div><p>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.</p>
|
|
|
|
-<p>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.</p>
|
|
|
|
-<p>For the console, they'd typically do <code>sudo loadkeys dvorak</code> 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.</p>
|
|
|
|
-<p>I googled around for solutions and came across <a href="http://superuser.com/questions/548234/how-can-i-easily-toggle-between-dvorak-and-qwerty-keyboard-layouts-from-a-linux">a nice idea</a>. You could alias <code>asdf</code> to load the DVORAK mapping and <code>aoeu</code> (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.</p>
|
|
|
|
-<p>After some further searching, I found <a href="http://unix.stackexchange.com/questions/2884/toggle-between-dvorak-and-qwerty">something close to what I wanted</a>. Apparently, Alt+Up sends a KeyboardSignal keycode to the init process, which can act on that. It also works anywhere, even before being logged in. For SysVinit systems, you can just add a line to your inittab for a command to be run when Alt+Up is pressed.</p>
|
|
|
|
-<p>In the office, however, we generally use Arch Linux which uses SystemD. But apparently, it also has a mechanism of accepting the Alt+Up press. It runs the kbrequest target whenever it gets the keypress. <code>kbrequest.target</code> is normally aliased to run the rescue service though, so you have to manually create the file in <code>/etc/systemd/system/kbrequest.target</code> and fill it with a description:</p>
|
|
|
|
-<pre class="code literal-block"><span class="k">[Unit]</span>
|
|
|
|
-<span class="na">Description</span><span class="o">=</span><span class="s">kbrequest target</span>
|
|
|
|
-</pre>
|
|
|
|
|
|
+<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%">twanager server
|
|
|
|
+</pre></div>
|
|
|
|
+
|
|
|
|
+<h2 id="putting-it-all-together:1f502be524b8b2be2ec53e61b7c9a5cf">Putting it all together</h2>
|
|
|
|
+
|
|
|
|
+<p>Once you have the TiddlyWeb server running, you can just go to wherever you&rsquo;re hosting the wiki html and it should work. You can try creating some posts, and the check mark on the sidebar should be red for a while and then turn black. Once that&rsquo;s done it&rsquo;s saved. You can refresh your browser and your posts should still be there.</p>
|
|
|
|
+
|
|
|
|
+<p>At this point, you can start customizing your TiddlyWeb instance, by changing your store to something like a database, or adding authorization. You can also tweak the server setup so you won&rsquo;t need CORS anymore.</p>
|
|
|
|
+
|
|
|
|
+<p>TiddlyWiki5 is still relatively new. I hope that eventually, support for server-side and the plugin ecosystem grows to be as great as the old TiddlyWiki.</p>
|
|
|
|
+</description>
|
|
|
|
+ </item>
|
|
|
|
+
|
|
|
|
+ <item>
|
|
|
|
+ <title>Is My Terminal Window Active?</title>
|
|
|
|
+ <link>http://pleasantprogrammer.com/posts/is-my-terminal-window-active.html</link>
|
|
|
|
+ <pubDate>Sun, 07 Jun 2015 00:00:00 +0000</pubDate>
|
|
|
|
+
|
|
|
|
+ <guid>http://pleasantprogrammer.com/posts/is-my-terminal-window-active.html</guid>
|
|
|
|
+ <description>
|
|
|
|
+
|
|
|
|
+<p>I&rsquo;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&rsquo;s a zsh plugin that alerts you if your long-running task is complete, and whether it failed or not.</p>
|
|
|
|
+
|
|
|
|
+<p>It&rsquo;s pretty convenient when you&rsquo;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&rsquo;re currently looking at the terminal window of the job that just finished, it won&rsquo;t notify you. It only notifies on windows that aren&rsquo;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&rsquo;t tell if the tab is active though, but I don&rsquo;t use tabs in my current setup so it should still be good.</p>
|
|
|
|
+
|
|
|
|
+<h2 id="xdotool:bfade06d39f7975f041a61de11ad4d4f">xdotool</h2>
|
|
|
|
+
|
|
|
|
+<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&rsquo;re in.</p>
|
|
|
|
+
|
|
|
|
+<h2 id="first-attempt-windowid:bfade06d39f7975f041a61de11ad4d4f">First Attempt: $WINDOWID</h2>
|
|
|
|
+
|
|
|
|
+<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&rsquo;t define <code>$WINDOWID</code> altogether. So <code>$WINDOWID</code> wasn&rsquo;t going to work.</p>
|
|
|
|
+
|
|
|
|
+<h2 id="second-attempt-xdotool-search-magic:bfade06d39f7975f041a61de11ad4d4f">Second Attempt: xdotool search $MAGIC</h2>
|
|
|
|
+
|
|
|
|
+<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&rsquo;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&rsquo;s another option I can explore some day.</p>
|
|
|
|
+
|
|
|
|
+<h2 id="third-attempt-ppid:bfade06d39f7975f041a61de11ad4d4f">Third Attempt: $PPID</h2>
|
|
|
|
+
|
|
|
|
+<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&rsquo;s parent will now be another zsh instance instead of an X window.</p>
|
|
|
|
+
|
|
|
|
+<p>At first glance, launching zsh within zsh doesn&rsquo;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&rsquo;re in an active window or not. Overall, this approach worked surprisingly well so that&rsquo;s the final solution I went with.</p>
|
|
|
|
+</description>
|
|
|
|
+ </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>
|
|
|
|
+ <pubDate>Wed, 27 Nov 2013 00:00:00 +0000</pubDate>
|
|
|
|
+
|
|
|
|
+ <guid>http://pleasantprogrammer.com/posts/removing-pldtmydslbiz-from-the-zyxel-p-2612hnu.html</guid>
|
|
|
|
+ <description><p>I&rsquo;ve always thought that people were just too lazy to change their SSIDs when I see &ldquo;PLDTMyDSLBizCafeJapan&rdquo;. It became apparent when we got our own PLDT line that it was because the bundled router/modem <em>does not</em> allow you to remove the prefix.</p>
|
|
|
|
+
|
|
|
|
+<p>This is not the kind of thing you expect as a business customer. Even for home customers, I feel it&rsquo;s still a bit dishonest. I&rsquo;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.</p>
|
|
|
|
+
|
|
|
|
+<p>Of course, we couldn&rsquo;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 <a href="http://www.phandroidinternet.com/2013/06/how-to-remove-on-wifi-name-or-ssid-on.html">Prolink H5004N</a> or the <a href="http://www.symbianize.com/showthread.php?t=730091">ZyXEL P-660HN-T1A</a> but not for the one we got which was the ZyXEL P-2612HNU-F1F.</p>
|
|
|
|
+
|
|
|
|
+<p>We did still try the firebug/inspector tricks, but it seems that there is a server-side check that adds in the &ldquo;PLDTMyDSLBiz&rdquo;. 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.</p>
|
|
|
|
+
|
|
|
|
+<p>The backup is actually just an XML file. You can search for SSID and change the parameter there. It&rsquo;s a bit annoying because the router has to restart after restoring the configuration, but it works!</p>
|
|
|
|
+
|
|
|
|
+<p>A minor note, the router doesn&rsquo;t seem to support SSIDs with a comma (,) well. It just gets everything before the comma as the SSID for some reason.</p>
|
|
|
|
+</description>
|
|
|
|
+ </item>
|
|
|
|
+
|
|
|
|
+ <item>
|
|
|
|
+ <title>Console Keymap Switching</title>
|
|
|
|
+ <link>http://pleasantprogrammer.com/posts/console-keymap-switching.html</link>
|
|
|
|
+ <pubDate>Tue, 29 Oct 2013 00:00:00 +0000</pubDate>
|
|
|
|
+
|
|
|
|
+ <guid>http://pleasantprogrammer.com/posts/console-keymap-switching.html</guid>
|
|
|
|
+ <description><p>At the office, we have some people who use DVORAK. Normally, this isn&rsquo;t a problem. To each his own after all. It does become a bit problematic though, when we&rsquo;re dealing with the servers around the office.</p>
|
|
|
|
+
|
|
|
|
+<p>We normally leave the servers on QWERTY. After all, most people start off as QWERTY typists and migrate to something else. That said, it&rsquo;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.</p>
|
|
|
|
+
|
|
|
|
+<p>For the console, they&rsquo;d typically do <code>sudo loadkeys dvorak</code> 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&rsquo;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&rsquo;t a readily available thing for the console.</p>
|
|
|
|
+
|
|
|
|
+<p>I googled around for solutions and came across <a href="http://superuser.com/questions/548234/how-can-i-easily-toggle-between-dvorak-and-qwerty-keyboard-layouts-from-a-linux">a nice idea</a>. You could alias <code>asdf</code> to load the DVORAK mapping and <code>aoeu</code> (the equivalent to asdf in DVORAK) to load the QWERTY mapping. This actually makes sense since you don&rsquo;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.</p>
|
|
|
|
+
|
|
|
|
+<p>After some further searching, I found <a href="http://unix.stackexchange.com/questions/2884/toggle-between-dvorak-and-qwerty">something close to what I wanted</a>. Apparently, Alt+Up sends a KeyboardSignal keycode to the init process, which can act on that. It also works anywhere, even before being logged in. For SysVinit systems, you can just add a line to your inittab for a command to be run when Alt+Up is pressed.</p>
|
|
|
|
+
|
|
|
|
+<p>In the office, however, we generally use Arch Linux which uses SystemD. But apparently, it also has a mechanism of accepting the Alt+Up press. It runs the kbrequest target whenever it gets the keypress. <code>kbrequest.target</code> is normally aliased to run the rescue service though, so you have to manually create the file in <code>/etc/systemd/system/kbrequest.target</code> and fill it with a description:</p>
|
|
|
|
+<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span style="color: #008000; font-weight: bold">[Unit]</span>
|
|
|
|
+<span style="color: #7D9029">Description</span><span style="color: #666666">=</span><span style="color: #BA2121">kbrequest target</span>
|
|
|
|
+</pre></div>
|
|
|
|
|
|
<p>We can then add a service to be run whenever the target is called. Something like <code>/etc/systemd/system/keymap-switch.service</code>:</p>
|
|
<p>We can then add a service to be run whenever the target is called. Something like <code>/etc/systemd/system/keymap-switch.service</code>:</p>
|
|
-<pre class="code literal-block"><span class="k">[Unit]</span>
|
|
|
|
-<span class="na">Description</span><span class="o">=</span><span class="s">Keymap Switch Service</span>
|
|
|
|
-
|
|
|
|
-<span class="k">[Service]</span>
|
|
|
|
-<span class="na">Type</span><span class="o">=</span><span class="s">oneshot</span>
|
|
|
|
-<span class="na">ExecStart</span><span class="o">=</span><span class="s">/usr/local/bin/keymap-switch</span>
|
|
|
|
-
|
|
|
|
-<span class="k">[Install]</span>
|
|
|
|
-<span class="na">WantedBy</span><span class="o">=</span><span class="s">kbrequest.target</span>
|
|
|
|
-</pre>
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-<p>After enabling said service, we only need the actual keymap switcher, <code>/usr/local/bin/keymap-switch</code>. The StackOverflow answer provides different ways of detecting the current keymap so we know which one to switch to. Since we're using SystemD, we can use that instead for managing which keymap we're actually using. It stores the current settings inside <code>/etc/vconsole.conf</code>. We can also then switch keymaps by using <code>localectl set-keymap</code>.</p>
|
|
|
|
-<table class="codehilitetable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
|
|
|
- 2
|
|
|
|
- 3
|
|
|
|
- 4
|
|
|
|
- 5
|
|
|
|
- 6
|
|
|
|
- 7
|
|
|
|
- 8
|
|
|
|
- 9
|
|
|
|
-10</pre></div></td><td class="code"><pre class="code literal-block"><span class="c">#!/bin/sh</span>
|
|
|
|
-<span class="nb">source</span> /etc/vconsole.conf
|
|
|
|
-
|
|
|
|
-<span class="k">if</span> <span class="o">[</span> <span class="s2">"</span><span class="nv">$TERM</span><span class="s2">"</span> <span class="o">=</span> <span class="s2">"dumb"</span> <span class="o">]</span><span class="p">;</span> <span class="k">then</span>
|
|
|
|
- <span class="k">if</span> <span class="o">[</span> <span class="s2">"</span><span class="nv">$KEYMAP</span><span class="s2">"</span> <span class="o">=</span> <span class="s2">"dvorak"</span> <span class="o">]</span><span class="p">;</span> <span class="k">then</span>
|
|
|
|
- localectl <span class="nb">set</span>-keymap us
|
|
|
|
- <span class="k">else</span>
|
|
|
|
- localectl <span class="nb">set</span>-keymap dvorak
|
|
|
|
- <span class="k">fi</span>
|
|
|
|
-<span class="k">fi</span>
|
|
|
|
-</pre>
|
|
|
|
-</td></tr></table>
|
|
|
|
-
|
|
|
|
-<p>After putting it all together, it works! We can switch keymaps on the fly by simply pressing Alt+Up.</p></div></description><category>sysadmin</category><category>systemd</category><guid>http://pleasantprogrammer.com/posts/console-keymap-switching.html</guid><pubDate>Tue, 29 Oct 2013 12:02:06 GMT</pubDate></item><item><title>Geocoding Services</title><link>http://pleasantprogrammer.com/posts/geocoding-services.html</link><dc:creator>Thomas Dy</dc:creator><description><div><p>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.</p>
|
|
|
|
-<p>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 <em>that</em> much you could do for the competition.</p>
|
|
|
|
-<p>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 <a href="http://nominatim.openstreetmap.org">Nominatim</a>.</p>
|
|
|
|
|
|
+<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span style="color: #008000; font-weight: bold">[Unit]</span>
|
|
|
|
+<span style="color: #7D9029">Description</span><span style="color: #666666">=</span><span style="color: #BA2121">Keymap Switch Service</span>
|
|
|
|
+
|
|
|
|
+<span style="color: #008000; font-weight: bold">[Service]</span>
|
|
|
|
+<span style="color: #7D9029">Type</span><span style="color: #666666">=</span><span style="color: #BA2121">oneshot</span>
|
|
|
|
+<span style="color: #7D9029">ExecStart</span><span style="color: #666666">=</span><span style="color: #BA2121">/usr/local/bin/keymap-switch</span>
|
|
|
|
+
|
|
|
|
+<span style="color: #008000; font-weight: bold">[Install]</span>
|
|
|
|
+<span style="color: #7D9029">WantedBy</span><span style="color: #666666">=</span><span style="color: #BA2121">kbrequest.target</span>
|
|
|
|
+</pre></div>
|
|
|
|
+
|
|
|
|
+<p>After enabling said service, we only need the actual keymap switcher, <code>/usr/local/bin/keymap-switch</code>. The StackOverflow answer provides different ways of detecting the current keymap so we know which one to switch to. Since we&rsquo;re using SystemD, we can use that instead for managing which keymap we&rsquo;re actually using. It stores the current settings inside <code>/etc/vconsole.conf</code>. We can also then switch keymaps by using <code>localectl set-keymap</code>.</p>
|
|
|
|
+<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span style="color: #408080; font-style: italic">#!/bin/sh</span>
|
|
|
|
+<span style="color: #008000">source</span> /etc/vconsole.conf
|
|
|
|
+
|
|
|
|
+<span style="color: #008000; font-weight: bold">if</span> <span style="color: #666666">[</span> <span style="color: #BA2121">&quot;</span><span style="color: #19177C">$TERM</span><span style="color: #BA2121">&quot;</span> <span style="color: #666666">=</span> <span style="color: #BA2121">&quot;dumb&quot;</span> <span style="color: #666666">]</span>; <span style="color: #008000; font-weight: bold">then</span>
|
|
|
|
+ <span style="color: #008000; font-weight: bold">if</span> <span style="color: #666666">[</span> <span style="color: #BA2121">&quot;</span><span style="color: #19177C">$KEYMAP</span><span style="color: #BA2121">&quot;</span> <span style="color: #666666">=</span> <span style="color: #BA2121">&quot;dvorak&quot;</span> <span style="color: #666666">]</span>; <span style="color: #008000; font-weight: bold">then</span>
|
|
|
|
+ localectl <span style="color: #008000">set</span>-keymap us
|
|
|
|
+ <span style="color: #008000; font-weight: bold">else</span>
|
|
|
|
+ localectl <span style="color: #008000">set</span>-keymap dvorak
|
|
|
|
+ <span style="color: #008000; font-weight: bold">fi</span>
|
|
|
|
+<span style="color: #008000; font-weight: bold">fi</span>
|
|
|
|
+</pre></div>
|
|
|
|
+
|
|
|
|
+<p>After putting it all together, it works! We can switch keymaps on the fly by simply pressing Alt+Up.</p>
|
|
|
|
+</description>
|
|
|
|
+ </item>
|
|
|
|
+
|
|
|
|
+ <item>
|
|
|
|
+ <title>Geocoding Services</title>
|
|
|
|
+ <link>http://pleasantprogrammer.com/posts/geocoding-services.html</link>
|
|
|
|
+ <pubDate>Wed, 25 Sep 2013 00:00:00 +0000</pubDate>
|
|
|
|
+
|
|
|
|
+ <guid>http://pleasantprogrammer.com/posts/geocoding-services.html</guid>
|
|
|
|
+ <description><p>A key component for any routing service is being able to do geocoding. Most people who are looking for routes most probably don&rsquo;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.</p>
|
|
|
|
+
|
|
|
|
+<p>The gold standard for doing geocoding right now is Google Maps. It&rsquo;s hard to find a better location search experience. If they actually provided routing for jeeps here in the Philippines, I imagine there wouldn&rsquo;t be <em>that</em> much you could do for the competition.</p>
|
|
|
|
+
|
|
|
|
+<p>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 <a href="http://nominatim.openstreetmap.org">Nominatim</a>.</p>
|
|
|
|
+
|
|
<p>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.</p>
|
|
<p>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.</p>
|
|
-<p>Given a typical mapping app, you might type in "ateneo" and expect it to give you Ateneo de Manila University. With typical geocoding services like Nominatim or even Google's <a href="https://developers.google.com/maps/documentation/javascript/geocoding">geocoding API</a>, you probably won't get any result for this. What you want to use is the <a href="https://developers.google.com/maps/documentation/javascript/places">Places API</a> which provides an autocomplete search box. Using it, when you type in "ateneo", it automatically suggests in the dropdown, "Ateneo de Manila University".</p>
|
|
|
|
-<p>A downside to using the Places API is that it's against the terms of service to use it with something that isn't Google Maps, which means no OpenStreetMap. If there were more time, writing your own autocompletion engine using OpenStreetMap's data will probably be a better long term solution.</p>
|
|
|
|
-<p>For now, since the competition's deadline is just a few days away, I'll be using Google Maps.</p></div></description><category>philippine-transit-app</category><category>programming</category><guid>http://pleasantprogrammer.com/posts/geocoding-services.html</guid><pubDate>Wed, 25 Sep 2013 04:26:59 GMT</pubDate></item><item><title>Jeep and Bus Schedules</title><link>http://pleasantprogrammer.com/posts/jeep-and-bus-schedules.html</link><dc:creator>Thomas Dy</dc:creator><description><div><p>Wouldn't it be wonderful if there were no buses or jeepneys in the Philippines over the weekends? It would truly be a cyclist's paradise. Imagine biking along EDSA, normally that would be a death sentence, but according to the GTFS data, you shouldn't worry. I can assure you, it's still a death sentence.</p>
|
|
|
|
|
|
+
|
|
|
|
+<p>Given a typical mapping app, you might type in &ldquo;ateneo&rdquo; and expect it to give you Ateneo de Manila University. With typical geocoding services like Nominatim or even Google&rsquo;s <a href="https://developers.google.com/maps/documentation/javascript/geocoding">geocoding API</a>, you probably won&rsquo;t get any result for this. What you want to use is the <a href="https://developers.google.com/maps/documentation/javascript/places">Places API</a> which provides an autocomplete search box. Using it, when you type in &ldquo;ateneo&rdquo;, it automatically suggests in the dropdown, &ldquo;Ateneo de Manila University&rdquo;.</p>
|
|
|
|
+
|
|
|
|
+<p>A downside to using the Places API is that it&rsquo;s against the terms of service to use it with something that isn&rsquo;t Google Maps, which means no OpenStreetMap. If there were more time, writing your own autocompletion engine using OpenStreetMap&rsquo;s data will probably be a better long term solution.</p>
|
|
|
|
+
|
|
|
|
+<p>For now, since the competition&rsquo;s deadline is just a few days away, I&rsquo;ll be using Google Maps.</p>
|
|
|
|
+</description>
|
|
|
|
+ </item>
|
|
|
|
+
|
|
|
|
+ <item>
|
|
|
|
+ <title>Jeep and Bus Schedules</title>
|
|
|
|
+ <link>http://pleasantprogrammer.com/posts/jeep-and-bus-schedules.html</link>
|
|
|
|
+ <pubDate>Sun, 28 Jul 2013 00:00:00 +0000</pubDate>
|
|
|
|
+
|
|
|
|
+ <guid>http://pleasantprogrammer.com/posts/jeep-and-bus-schedules.html</guid>
|
|
|
|
+ <description><p>Wouldn&rsquo;t it be wonderful if there were no buses or jeepneys in the Philippines over the weekends? It would truly be a cyclist&rsquo;s paradise. Imagine biking along EDSA, normally that would be a death sentence, but according to the GTFS data, you shouldn&rsquo;t worry. I can assure you, it&rsquo;s still a death sentence.</p>
|
|
|
|
+
|
|
<p>The GTFS spec defines 2 ways of statically specifying trip schedules. You can define the exact times that a service will arrive at a stop. You can also specify between what times the service is active and how often a new bus or jeep leaves the first stop. You also define which days those rules apply. You could say every MWF, the bus operates from 9:00AM to 9:00PM and every TTH, the bus services from 3:00AM to 11:00PM.</p>
|
|
<p>The GTFS spec defines 2 ways of statically specifying trip schedules. You can define the exact times that a service will arrive at a stop. You can also specify between what times the service is active and how often a new bus or jeep leaves the first stop. You also define which days those rules apply. You could say every MWF, the bus operates from 9:00AM to 9:00PM and every TTH, the bus services from 3:00AM to 11:00PM.</p>
|
|
-<p>This should be sufficient in theory, but real world conditions like traffic or the weather could throw the schedules off. To solve this, there's another spec, GTFS-realtime. This allows transit agencies to push temporary schedule updates and service announcements.</p>
|
|
|
|
-<p>Like much everything else about the Philippine transit system, there aren't really any "schedules" to speak of. It's generally whenever the buses or jeeps feel like it. So we have no static schedules. We don't have a central agency or the tracking technology to make it feasible to push updates via GTFS-RT.</p>
|
|
|
|
-<p>Ideally, we shouldn't bother inputting the schedule information into GTFS. Only the route data is really important for jeeps and buses. However, the schedule information is required in the GTFS, and routing apps wouldn't work without it. So we have to add a reasonable trip schedule for jeeps and buses.</p>
|
|
|
|
|
|
+
|
|
|
|
+<p>This should be sufficient in theory, but real world conditions like traffic or the weather could throw the schedules off. To solve this, there&rsquo;s another spec, GTFS-realtime. This allows transit agencies to push temporary schedule updates and service announcements.</p>
|
|
|
|
+
|
|
|
|
+<p>Like much everything else about the Philippine transit system, there aren&rsquo;t really any &ldquo;schedules&rdquo; to speak of. It&rsquo;s generally whenever the buses or jeeps feel like it. So we have no static schedules. We don&rsquo;t have a central agency or the tracking technology to make it feasible to push updates via GTFS-RT.</p>
|
|
|
|
+
|
|
|
|
+<p>Ideally, we shouldn&rsquo;t bother inputting the schedule information into GTFS. Only the route data is really important for jeeps and buses. However, the schedule information is required in the GTFS, and routing apps wouldn&rsquo;t work without it. So we have to add a reasonable trip schedule for jeeps and buses.</p>
|
|
|
|
+
|
|
<p>The current GTFS data does define these trip schedules. We assume that jeeps and buses operate between 6:00AM and 11:00PM and a new jeep passes by every 10 minutes. Also, jeeps and buses are defined to only operate on weekdays.</p>
|
|
<p>The current GTFS data does define these trip schedules. We assume that jeeps and buses operate between 6:00AM and 11:00PM and a new jeep passes by every 10 minutes. Also, jeeps and buses are defined to only operate on weekdays.</p>
|
|
-<p>While there might be jeeps who change routes or don't operate on weekends, I'm pretty sure that jeeps and buses run on weekends. We'll have to fix it ourselves temporarily since there's no central GTFS feed yet.</p>
|
|
|
|
-<pre class="code literal-block"><span class="c"># 724594 seems to be the service id used by jeeps and buses</span>
|
|
|
|
-sed -i .bak <span class="s1">'/^724594/ s/0,0/1,1/'</span> calendar.txt
|
|
|
|
-</pre>
|
|
|
|
|
|
|
|
|
|
+<p>While there might be jeeps who change routes or don&rsquo;t operate on weekends, I&rsquo;m pretty sure that jeeps and buses run on weekends. We&rsquo;ll have to fix it ourselves temporarily since there&rsquo;s no central GTFS feed yet.</p>
|
|
|
|
+<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span style="color: #408080; font-style: italic"># 724594 seems to be the service id used by jeeps and buses</span>
|
|
|
|
+sed -i .bak <span style="color: #BA2121">&#39;/^724594/ s/0,0/1,1/&#39;</span> calendar.txt
|
|
|
|
+</pre></div>
|
|
|
|
+
|
|
|
|
+<p>Another thing we could do is to adjust the time between buses, although the improvement is arguable. With the current 10 minutes between jeeps, it might provide some routes a significant advantage just because the timing is right. So you might get differing route suggestions depending on what time you planned the route. This makes sense when you&rsquo;re sure what the times are, so you can minimize the wait, but with jeeps, you never really know how long the wait will actually be.</p>
|
|
|
|
+
|
|
|
|
+<p>If we set the frequency to one minute, it <em>might</em> give better routes by eliminating the timing issue. Or not, it&rsquo;s kind of hard to tell.</p>
|
|
|
|
+<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span style="color: #408080; font-style: italic"># jeep and bus route ids tend to start with 72</span>
|
|
|
|
+sed -i .bak <span style="color: #BA2121">&#39;/^72/ s/,600/,60/&#39;</span> frequencies.txt
|
|
|
|
+</pre></div>
|
|
|
|
+
|
|
|
|
+<p>Overall, the problems we&rsquo;re having is a symptom of the mismatch between our transit system and the GTFS. It would be great if our transit system gets better and we don&rsquo;t need to do hackish things for it to fit the GTFS, but that&rsquo;s still a dream. For now, all we can really do is fit a triangle into a square hole.</p>
|
|
|
|
+</description>
|
|
|
|
+ </item>
|
|
|
|
+
|
|
|
|
+ <item>
|
|
|
|
+ <title>Highways in OTP</title>
|
|
|
|
+ <link>http://pleasantprogrammer.com/posts/highways-in-otp.html</link>
|
|
|
|
+ <pubDate>Wed, 24 Jul 2013 00:00:00 +0000</pubDate>
|
|
|
|
+
|
|
|
|
+ <guid>http://pleasantprogrammer.com/posts/highways-in-otp.html</guid>
|
|
|
|
+ <description><p>One of the weird things that happens with OTP is sometimes it gives absurdly roundabout routes. Here is OTP&rsquo;s suggested route for walking from UP to Ateneo:</p>
|
|
|
|
+
|
|
|
|
+<p><img src="../galleries/transit/otproundabout.png" alt="Roundabout route from UP to Ateneo" /></p>
|
|
|
|
+
|
|
|
|
+<p>This is just so hilariously wrong. It&rsquo;s much simpler to just walk along Katipunan Avenue.</p>
|
|
|
|
+
|
|
|
|
+<p>OTP couldn&rsquo;t possibly be that dumb though, so there must be something we&rsquo;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 &ldquo;road type&rdquo; 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>
|
|
|
|
+<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%">sed -i .bak s/trunk/primary/g manila.osm
|
|
|
|
+</pre></div>
|
|
|
|
+
|
|
|
|
+<p>And rebuild the graph. It doesn&rsquo;t really matter much because the OSM data isn&rsquo;t used to render the maps. It&rsquo;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&rsquo;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&rsquo;s better since you keep the weighting done by OTP, but you&rsquo;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&rsquo;m not sure on the particulars with updating OSM though.</p>
|
|
|
|
+</description>
|
|
|
|
+ </item>
|
|
|
|
+
|
|
|
|
+ <item>
|
|
|
|
+ <title>Elevation Data in OTP</title>
|
|
|
|
+ <link>http://pleasantprogrammer.com/posts/elevation-data-in-otp.html</link>
|
|
|
|
+ <pubDate>Tue, 23 Jul 2013 00:00:00 +0000</pubDate>
|
|
|
|
+
|
|
|
|
+ <guid>http://pleasantprogrammer.com/posts/elevation-data-in-otp.html</guid>
|
|
|
|
+ <description><p><img src="../galleries/transit/otpelevation.png" alt="OpenTripPlanner showing elevation data" /></p>
|
|
|
|
|
|
-<p>Another thing we could do is to adjust the time between buses, although the improvement is arguable. With the current 10 minutes between jeeps, it might provide some routes a significant advantage just because the timing is right. So you might get differing route suggestions depending on what time you planned the route. This makes sense when you're sure what the times are, so you can minimize the wait, but with jeeps, you never really know how long the wait will actually be.</p>
|
|
|
|
-<p>If we set the frequency to one minute, it <em>might</em> give better routes by eliminating the timing issue. Or not, it's kind of hard to tell.</p>
|
|
|
|
-<pre class="code literal-block"><span class="c"># jeep and bus route ids tend to start with 72</span>
|
|
|
|
-sed -i .bak <span class="s1">'/^72/ s/,600/,60/'</span> frequencies.txt
|
|
|
|
-</pre>
|
|
|
|
|
|
+<p>One thing I hadn&rsquo;t tested out last time was OTP&rsquo;s support for elevation data. It makes use of this by showing the elevation you have to traverse while walking along the suggested route. It can also take it into account when suggesting bike routes.</p>
|
|
|
|
|
|
|
|
+<p>The <a href="https://github.com/openplans/OpenTripPlanner/wiki/FiveMinutes">5 minute tutorial</a> actually discusses the elevation data briefly, but a more in-depth thing you can look at is the <a href="https://github.com/openplans/OpenTripPlanner/wiki/GraphBuilder#elevation-data">GraphBuilder documentation</a>. It suggests using the ASTER dataset which is free but requires registration. I just opted to use the SRTM data available from the <a href="http://www.philgis.org/freegisdata.htm">PhilGIS website</a>.</p>
|
|
|
|
|
|
-<p>Overall, the problems we're having is a symptom of the mismatch between our transit system and the GTFS. It would be great if our transit system gets better and we don't need to do hackish things for it to fit the GTFS, but that's still a dream. For now, all we can really do is fit a triangle into a square hole.</p></div></description><category>philippine-transit-app</category><category>programming</category><guid>http://pleasantprogrammer.com/posts/jeep-and-bus-schedules.html</guid><pubDate>Sun, 28 Jul 2013 08:26:31 GMT</pubDate></item><item><title>Highways in OTP</title><link>http://pleasantprogrammer.com/posts/highways-in-otp.html</link><dc:creator>Thomas Dy</dc:creator><description><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="http://pleasantprogrammer.com/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>I don&rsquo;t know about the ASTER dataset, but the PhilGIS data was in the ERDAS img format. OTP only supports GeoTIFF so there was a need to convert it beforehand. You can use <a href="http://www.gdal.org/">GDAL</a> for this. You&rsquo;d just then run,</p>
|
|
|
|
+<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%">gdal_translate srtm41_90m_phl.img phil.tiff
|
|
|
|
+</pre></div>
|
|
|
|
|
|
|
|
+<p>Afterwards, it&rsquo;s just a matter of following the OTP instructions on using a local elevation dataset. The process actually doubled the size of the generated Graph.obj so it might not be ideal if you&rsquo;re running on limited RAM.</p>
|
|
|
|
|
|
-<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></description><category>philippine-transit-app</category><category>programming</category><guid>http://pleasantprogrammer.com/posts/highways-in-otp.html</guid><pubDate>Wed, 24 Jul 2013 15:15:57 GMT</pubDate></item><item><title>Elevation Data in OTP</title><link>http://pleasantprogrammer.com/posts/elevation-data-in-otp.html</link><dc:creator>Thomas Dy</dc:creator><description><div><p><img alt="OpenTripPlanner showing elevation data" src="http://pleasantprogrammer.com/galleries/transit/otpelevation.png"></p>
|
|
|
|
-<p>One thing I hadn't tested out last time was OTP's support for elevation data. It makes use of this by showing the elevation you have to traverse while walking along the suggested route. It can also take it into account when suggesting bike routes.</p>
|
|
|
|
-<p>The <a href="https://github.com/openplans/OpenTripPlanner/wiki/FiveMinutes">5 minute tutorial</a> actually discusses the elevation data briefly, but a more in-depth thing you can look at is the <a href="https://github.com/openplans/OpenTripPlanner/wiki/GraphBuilder#elevation-data">GraphBuilder documentation</a>. It suggests using the ASTER dataset which is free but requires registration. I just opted to use the SRTM data available from the <a href="http://www.philgis.org/freegisdata.htm">PhilGIS website</a>.</p>
|
|
|
|
-<p>I don't know about the ASTER dataset, but the PhilGIS data was in the ERDAS img format. OTP only supports GeoTIFF so there was a need to convert it beforehand. You can use <a href="http://www.gdal.org/">GDAL</a> for this. You'd just then run,</p>
|
|
|
|
-<pre class="code literal-block"> gdal_translate srtm41_90m_phl.img phil.tiff
|
|
|
|
-</pre>
|
|
|
|
|
|
+<p>I&rsquo;ve actually hosted a <a href="http://maps.pleasantprogrammer.com">working example</a>. It&rsquo;s pretty much at the limits of the RAM so it might be slow and unreliable, but you can test it out just for fun. Please don&rsquo;t abuse it though.</p>
|
|
|
|
+</description>
|
|
|
|
+ </item>
|
|
|
|
+
|
|
|
|
+ <item>
|
|
|
|
+ <title>GraphServer</title>
|
|
|
|
+ <link>http://pleasantprogrammer.com/posts/graphserver.html</link>
|
|
|
|
+ <pubDate>Tue, 23 Jul 2013 00:00:00 +0000</pubDate>
|
|
|
|
+
|
|
|
|
+ <guid>http://pleasantprogrammer.com/posts/graphserver.html</guid>
|
|
|
|
+ <description><p>Link: <a href="http://graphserver.github.io/graphserver/">http://graphserver.github.io/graphserver/</a></p>
|
|
|
|
|
|
|
|
+<p>One other routing webapp I saw was GraphServer. It&rsquo;s actually more of a general purpose Graph library which supports GTFS and OSM data than an actual dedicated routing software like OpenTripPlanner. It&rsquo;s also based off python and C instead of Java, so it feels a lot less heavy.</p>
|
|
|
|
|
|
-<p>Afterwards, it's just a matter of following the OTP instructions on using a local elevation dataset. The process actually doubled the size of the generated Graph.obj so it might not be ideal if you're running on limited RAM.</p>
|
|
|
|
-<p>I've actually hosted a <a href="http://maps.pleasantprogrammer.com">working example</a>. It's pretty much at the limits of the RAM so it might be slow and unreliable, but you can test it out just for fun. Please don't abuse it though.</p></div></description><category>philippine-transit-app</category><category>programming</category><guid>http://pleasantprogrammer.com/posts/elevation-data-in-otp.html</guid><pubDate>Tue, 23 Jul 2013 10:23:00 GMT</pubDate></item><item><title>GraphServer</title><link>http://pleasantprogrammer.com/posts/graphserver.html</link><dc:creator>Thomas Dy</dc:creator><description><div><p>Link: <a href="http://graphserver.github.io/graphserver/">http://graphserver.github.io/graphserver/</a></p>
|
|
|
|
-<p>One other routing webapp I saw was GraphServer. It's actually more of a general purpose Graph library which supports GTFS and OSM data than an actual dedicated routing software like OpenTripPlanner. It's also based off python and C instead of Java, so it feels a lot less heavy.</p>
|
|
|
|
<p>The instructions on the website are already pretty good. There are just some minor errors with it. Where it says <code>gs_gtfsdb_build</code>, you should actually use <code>gs_gtfsdb_compile</code>. Also, when running <code>gs_osmdb_compile</code> you might need to use <code>-t</code> for tolerant in case you follow the instructions on chopping up the original OSM data.</p>
|
|
<p>The instructions on the website are already pretty good. There are just some minor errors with it. Where it says <code>gs_gtfsdb_build</code>, you should actually use <code>gs_gtfsdb_compile</code>. Also, when running <code>gs_osmdb_compile</code> you might need to use <code>-t</code> for tolerant in case you follow the instructions on chopping up the original OSM data.</p>
|
|
-<p>A nice suggestion from the GraphServer instructions was to crop the OSM data to minimize the graph size. This is actually quite helpful if you downloaded the entire Philippine OSM dump. It reduced the original 900MB file to 135MB which was a lot more workable. I did hit a problem with their instructions though. The linked version of osmosis is an old one, which doesn't support 64-bit ids. The <a href="http://wiki.openstreetmap.org/wiki/Osmosis">latest version of Osmosis</a> easily did the job though.</p>
|
|
|
|
-<p>The actual routing though, was not exactly good. I only tried one route which should normally take 1-2 transfers, it suggested a route which involved 4+ transfers. It also didn't provide any alternate routes aside from that one. I'm not sure if it's a limitation of the provided routeserver, but I didn't bother checking if it supported parameters which might provide better routes.</p>
|
|
|
|
-<p>I think graphserver could be useful, but it seems more involved than say OpenTripPlanner. There do seem to be people who use graphserver for their routing apps, but for the bounds of the contest, or just as a side project, it might require too much effort.</p></div></description><category>philippine-transit-app</category><category>programming</category><guid>http://pleasantprogrammer.com/posts/graphserver.html</guid><pubDate>Tue, 23 Jul 2013 06:48:29 GMT</pubDate></item></channel></rss>
|
|
|
|
|
|
+
|
|
|
|
+<p>A nice suggestion from the GraphServer instructions was to crop the OSM data to minimize the graph size. This is actually quite helpful if you downloaded the entire Philippine OSM dump. It reduced the original 900MB file to 135MB which was a lot more workable. I did hit a problem with their instructions though. The linked version of osmosis is an old one, which doesn&rsquo;t support 64-bit ids. The <a href="http://wiki.openstreetmap.org/wiki/Osmosis">latest version of Osmosis</a> easily did the job though.</p>
|
|
|
|
+
|
|
|
|
+<p>The actual routing though, was not exactly good. I only tried one route which should normally take 1-2 transfers, it suggested a route which involved 4+ transfers. It also didn&rsquo;t provide any alternate routes aside from that one. I&rsquo;m not sure if it&rsquo;s a limitation of the provided routeserver, but I didn&rsquo;t bother checking if it supported parameters which might provide better routes.</p>
|
|
|
|
+
|
|
|
|
+<p>I think graphserver could be useful, but it seems more involved than say OpenTripPlanner. There do seem to be people who use graphserver for their routing apps, but for the bounds of the contest, or just as a side project, it might require too much effort.</p>
|
|
|
|
+</description>
|
|
|
|
+ </item>
|
|
|
|
+
|
|
|
|
+ <item>
|
|
|
|
+ <title>Transit Wand</title>
|
|
|
|
+ <link>http://pleasantprogrammer.com/posts/transit-wand.html</link>
|
|
|
|
+ <pubDate>Mon, 15 Jul 2013 00:00:00 +0000</pubDate>
|
|
|
|
+
|
|
|
|
+ <guid>http://pleasantprogrammer.com/posts/transit-wand.html</guid>
|
|
|
|
+ <description><p>Link: <a href="https://play.google.com/store/apps/details?id=com.conveyal.transitwand">http://transitwand.com</a></p>
|
|
|
|
+
|
|
|
|
+<p>Overall, this was the simplest of the <a href="http://philippine-transit.hackathome.com/use-this-code/">open-source transit tools</a> to actually get up and running. There&rsquo;s already a deployed instance of the server, and you can easily download the phone app via the <a href="https://play.google.com/store/apps/details?id=com.conveyal.transitwand">Play Store</a>. Even running the server by yourself didn&rsquo;t have any of the hiccups I had with GTFS Editor.</p>
|
|
|
|
+
|
|
|
|
+<p>The phone app is actually quite simple. It allows you to capture a trip, which will record your GPS coordinates as you ride public transit. It also allows you to mark points of the trip where you stop and also how long the stop took. Lastly, it allows you to record embarking and disembarking passengers which is potentially useful for ridership data.</p>
|
|
|
|
+
|
|
|
|
+<p>After doing a capture session, you can review the data on the phone. It will plot out the route on a map, with markers for the stops. You then either delete the data if it looks wrong, or you can upload it to the Transit Wand server. Uploading involves registering an account, but it&rsquo;s free and you don&rsquo;t even actually need to put in a username or anything. It simply registers the phone&rsquo;s IMEI on the server and gives you a 6-digit identifier.</p>
|
|
|
|
+
|
|
|
|
+<p>You can then use the 6-digit identifier to view the data on Transit Wand&rsquo;s server, which is good since uploading any data automatically deletes it from the phone. There really isn&rsquo;t much else you can do with it though. It just allows you to view the data, and export it as a <a href="https://en.wikipedia.org/wiki/Shapefile">Shapefile</a>.</p>
|
|
|
|
+
|
|
|
|
+<p>As is, this is purely a data collection client-server app. Barring looking at the database, there is no way to get a list of phones which have collected data. Only the person who initiated the data collection knows the 6-digit code to view their data. There&rsquo;s also no way to extract the ridership information from the server yet. This isn&rsquo;t to say that the data won&rsquo;t eventually go public though.</p>
|
|
|
|
+
|
|
|
|
+<p>An interesting thing you <em>can</em> do with the Transit Wand data is import it into GTFS Editor to make a new route. You don&rsquo;t even have to manually download and upload the data. Just type in your 6-digit identifier and it will give you a list of routes you&rsquo;ve captured via Transit Wand. This is wonderful as you get all the stop data, as well as the shape of the route.</p>
|
|
|
|
+
|
|
|
|
+<p>I imagine these two tools were how the DOTC came up with all the GTFS data we have now. What I don&rsquo;t understand is why the shape data isn&rsquo;t present. Importing from Transit Wand already gets you shape data. There are even facilities to edit the shape within the editor if clean up is necessary. The only problem I saw was the fact that you can&rsquo;t easily move stops, you have to input coordinates to change the position.</p>
|
|
|
|
+
|
|
|
|
+<p>It <em>might</em> also be possible that when the DOTC was still collecting the data, the route collection or editing features weren&rsquo;t present yet. That would just be lame and depressing though.</p>
|
|
|
|
+
|
|
|
|
+<p>Overall, Transit Wand does what it&rsquo;s supposed to do. You collect data, and then upload it to a server. There is a lot of room for improvement though. It would be nice to have a better API that allows access to more of the data. Building in analysis tools for the ridership data might also be a welcome thing. I imagine it would also be great if you could encourage people to use the app and upload their own trips.</p>
|
|
|
|
+</description>
|
|
|
|
+ </item>
|
|
|
|
+
|
|
|
|
+ <item>
|
|
|
|
+ <title>Fare Data</title>
|
|
|
|
+ <link>http://pleasantprogrammer.com/posts/fare-data.html</link>
|
|
|
|
+ <pubDate>Sat, 13 Jul 2013 00:00:00 +0000</pubDate>
|
|
|
|
+
|
|
|
|
+ <guid>http://pleasantprogrammer.com/posts/fare-data.html</guid>
|
|
|
|
+ <description>
|
|
|
|
+
|
|
|
|
+<p>As part of the data released by the DOTC, we also have the <a href="http://philippine-transit.hackathome.com/dataset-philippines-transit-information-service-gtfs/">fare matrix</a> for aircon buses, ordinary buses and jeeps. All as wonderful images. The data is also actually available from the <a href="http://ltfrb.gov.ph/main/farerates">LTFRB website</a>. Generally, the fare scheme is represented as &ldquo;pay <em>X</em> pesos for the first <em>Y</em> kilometers, pay <em>Z</em> for every succeeding kilometer.&rdquo; Instead of a table, we can simply represent this as a formula instead,</p>
|
|
|
|
+<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%">base_fare + (distance - initial) * per_km
|
|
|
|
+</pre></div>
|
|
|
|
+
|
|
|
|
+<p>The relevant values for the three services are:</p>
|
|
|
|
+
|
|
|
|
+<table>
|
|
|
|
+<thead>
|
|
|
|
+ <tr>
|
|
|
|
+ <td>type</td>
|
|
|
|
+ <td>base_fare</td>
|
|
|
|
+ <td>initial</td>
|
|
|
|
+ <td>per_km</td>
|
|
|
|
+ </tr>
|
|
|
|
+</thead>
|
|
|
|
+<tbody>
|
|
|
|
+ <tr>
|
|
|
|
+ <td>bus aircon</td>
|
|
|
|
+ <td>12.00</td>
|
|
|
|
+ <td>5 km</td>
|
|
|
|
+ <td>2.20</td>
|
|
|
|
+ </tr>
|
|
|
|
+ <tr>
|
|
|
|
+ <td>bus ordinary</td>
|
|
|
|
+ <td>10.00</td>
|
|
|
|
+ <td>5 km</td>
|
|
|
|
+ <td>1.85</td>
|
|
|
|
+ </tr>
|
|
|
|
+ <tr>
|
|
|
|
+ <td>jeep aircon</td>
|
|
|
|
+ <td>8.00</td>
|
|
|
|
+ <td>4 km</td>
|
|
|
|
+ <td>1.40</td>
|
|
|
|
+ </tr>
|
|
|
|
+</tbody>
|
|
|
|
+</table>
|
|
|
|
+
|
|
|
|
+<p>It isn&rsquo;t as simple as that though. Fares are also rounded to the nearest 25 centavos. So we&rsquo;d need to round them off correctly. This can be achieved by doing,</p>
|
|
|
|
+<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%">round(calculated_fare * 4.0)/4.0
|
|
|
|
+</pre></div>
|
|
|
|
+
|
|
|
|
+<p>There&rsquo;s also the discounted fare for students, senior citizens and persons with disability. They get 20% off the fare (prior to rounding) and the resulting fare is rounded off as well.</p>
|
|
|
|
+
|
|
|
|
+<p>Doing just this, we actually do get the same results as the fare matrices in the image for the most part. There are some discrepancies with the discounted jeep fares. I&rsquo;ve tried to resolve it by tweaking around with the formulas, but it really doesn&rsquo;t make sense in any way. I presume these were manually adjusted for one reason or another.</p>
|
|
|
|
+
|
|
|
|
+<p>Here&rsquo;s a <a href="../uploads/farematrix.rb">script</a> that generates CSVs of all the three fare matrices. If you&rsquo;re too lazy to run it, here are links to the <a href="../uploads/pub_aircon.csv">aircon bus</a>, <a href="../uploads/pub_ordinary.csv">ordinary bus</a> and <a href="../uploads/puj.csv">jeep</a> fare matrices.</p>
|
|
|
|
+
|
|
|
|
+<h3 id="gtfs-compatibility:a6ffa536f572175993ee2d6ec342ac72">GTFS compatibility</h3>
|
|
|
|
+
|
|
|
|
+<p>As is, the provided GTFS data does not have any fare data. I imagine this is because the existing spec doesn&rsquo;t have good support for distance-based fares like we have in the Philippines. Judging from the <a href="https://code.google.com/p/googletransitdatafeed/wiki/FareExamples">fare examples</a>, the only reasonable way we could implement distance-based fares is following example 6. This would involve setting a fare for each possible pair of stops based on the distance between them. This isn&rsquo;t exactly ideal. In fact, the people originally working on the DOTC project have voiced <a href="https://groups.google.com/forum/#!topic/gtfs-fare-wg/V63xRSnQJGw">issues</a> and made <a href="https://groups.google.com/forum/#!msg/gtfs-changes/uybrAokZ9Cg/rqlzXdMypUgJ">proposals</a> for having distance-based fares included into GTFS.</p>
|
|
|
|
+
|
|
|
|
+<p>Apparently, public transit fares are a really complicated thing. You have fares based on distance, number of stops passed through, and transfers which may or may not cost extra. Not only that, you might have discounted fares, or first-class vs economy fares. The community will want to get it right before it&rsquo;s formally included in the spec. You can see the current state of the consolidated <a href="https://docs.google.com/document/d/1mK3--o5g4-3cCXaqmch92U63JTwChh0L2VCmcDViIlM/edit">GTFS fare proposal here</a>.</p>
|
|
|
|
+
|
|
|
|
+<p>Even in it&rsquo;s proposal form though, we might have hope of being able to see these being used. There&rsquo;s currently a <a href="https://github.com/OneBusAway/onebusaway-gtfs-modules/pull/30">pull request</a> for supporting the distance-based fare scheme into the OneBusAway libraries. The libraries actually used by GTFS Editor and OpenTripPlanner for working with GTFS data.</p>
|
|
|
|
+
|
|
|
|
+<h3 id="remaining-problems:a6ffa536f572175993ee2d6ec342ac72">Remaining Problems</h3>
|
|
|
|
+
|
|
|
|
+<p>Given all that, it would probably still be a long way before this allows us to make a really good routing app. We still don&rsquo;t have shape data, so the distance estimates would really be rough estimates at best. There&rsquo;s no support for rounding to the nearest centavo. I realize that&rsquo;s just nitpicking, but if we want something truly polished, even that has to be taken care of.</p>
|
|
|
|
+
|
|
|
|
+<p>We also don&rsquo;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&rsquo;t really measure distance that exactly. I assume they generally work off the notion of &ldquo;zones&rdquo; 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 &ldquo;zones&rdquo; you pass through.</p>
|
|
|
|
+
|
|
|
|
+<h3 id="conclusion:a6ffa536f572175993ee2d6ec342ac72">Conclusion</h3>
|
|
|
|
+
|
|
|
|
+<p>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&rsquo;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.</p>
|
|
|
|
+
|
|
|
|
+<p>Side note: I&rsquo;d also actually really like to hear about the DOTC developers&rsquo; experience with the project. It would be nice if they had a devblog.</p>
|
|
|
|
+</description>
|
|
|
|
+ </item>
|
|
|
|
+
|
|
|
|
+ <item>
|
|
|
|
+ <title>GTFS Editor</title>
|
|
|
|
+ <link>http://pleasantprogrammer.com/posts/gtfs-editor.html</link>
|
|
|
|
+ <pubDate>Wed, 10 Jul 2013 00:00:00 +0000</pubDate>
|
|
|
|
+
|
|
|
|
+ <guid>http://pleasantprogrammer.com/posts/gtfs-editor.html</guid>
|
|
|
|
+ <description>
|
|
|
|
+
|
|
|
|
+<p>Link: <a href="https://github.com/conveyal/gtfs-editor">https://github.com/conveyal/gtfs-editor</a></p>
|
|
|
|
+
|
|
|
|
+<p><strong>TL;DR</strong> they really meant under development</p>
|
|
|
|
+
|
|
|
|
+<p>When I first saw the source of GTFS Editor, I was ecstatic. They used <a href="http://playframework.com/">Play framework</a>!!! Not only that, they&rsquo;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.</p>
|
|
|
|
+
|
|
|
|
+<p>Getting it to actually run though, wasn&rsquo;t very pleasant. The initial setup was easy enough. Get <a href="http://www.playframework.com/download">Play 1.2.5</a>, 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&rsquo;s necessary. Wonderful. Then, run play, open a browser, go to <a href="http://localhost:9000">http://localhost:9000</a>, compilation error. Fantastic.</p>
|
|
|
|
+
|
|
|
|
+<p>If you don&rsquo;t want to go through the technical details, you can just jump to the <a href="#conclusion">conclusion</a>.</p>
|
|
|
|
+
|
|
|
|
+<h2 id="let-s-debug:9dc7854b573f1a2be2b19d1bfe826d39">Let&rsquo;s Debug!</h2>
|
|
|
|
+
|
|
|
|
+<p>I&rsquo;ll be splitting the next section up into 2 parts. In the first pass, I&rsquo;ll talk about what I did to just get the app to run but I won&rsquo;t try hard to fix any bugs. This generally is what I do when I try to get apps to run. I&rsquo;ll also be dropping enough information so that you can actually figure out what the real problem is. In the second pass, I&rsquo;ll explain what the problems were and how I fixed them.</p>
|
|
|
|
+
|
|
|
|
+<h3 id="first-pass:9dc7854b573f1a2be2b19d1bfe826d39">First Pass</h3>
|
|
|
|
+
|
|
|
|
+<p>A thing to note about Play (and one of the reasons it&rsquo;s a lovely Java framework) is that you don&rsquo;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&rsquo;s what I saw, <code>Error: type Check already defined</code></p>
|
|
|
|
+<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span style="color: #AA22FF">@Retention</span><span style="color: #666666">(</span>RetentionPolicy<span style="color: #666666">.</span><span style="color: #7D9029">RUNTIME</span><span style="color: #666666">)</span>
|
|
|
|
+<span style="color: #AA22FF">@Target</span><span style="color: #666666">({</span>ElementType<span style="color: #666666">.</span><span style="color: #7D9029">METHOD</span><span style="color: #666666">,</span> ElementType<span style="color: #666666">.</span><span style="color: #7D9029">TYPE</span><span style="color: #666666">})</span>
|
|
|
|
+<span style="color: #008000; font-weight: bold">public</span> <span style="color: #AA22FF">@interface</span> Check <span style="color: #666666">{</span> <span style="color: #408080; font-style: italic">// error here</span>
|
|
|
|
+
|
|
|
|
+ String<span style="color: #666666">[]</span> <span style="color: #0000FF">value</span><span style="color: #666666">();</span>
|
|
|
|
+<span style="color: #666666">}</span>
|
|
|
|
+</pre></div>
|
|
|
|
+
|
|
|
|
+<p>You also know that typical behavior among programmers where your program doesn&rsquo;t compile, but you keep trying to compile it anyway hoping that it will magically just work. That&rsquo;s what I did, and it actually ran. I couldn&rsquo;t really just let this pass, so I decided to try deleting <code>Check.java</code>. I got another compilation error, <code>Error: type Secure already defined</code></p>
|
|
|
|
+<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span style="color: #008000; font-weight: bold">public</span> <span style="color: #008000; font-weight: bold">class</span> <span style="color: #0000FF; font-weight: bold">Secure</span> <span style="color: #008000; font-weight: bold">extends</span> Controller <span style="color: #666666">{</span> <span style="color: #408080; font-style: italic">// error here</span>
|
|
|
|
+
|
|
|
|
+ <span style="color: #AA22FF">@Before</span><span style="color: #666666">(</span>unless<span style="color: #666666">={</span><span style="color: #BA2121">&quot;login&quot;</span><span style="color: #666666">,</span> <span style="color: #BA2121">&quot;authenticate&quot;</span><span style="color: #666666">,</span> <span style="color: #BA2121">&quot;logout&quot;</span><span style="color: #666666">})</span>
|
|
|
|
+
|
|
|
|
+ <span style="color: #008000; font-weight: bold">static</span> <span style="color: #B00040">void</span> <span style="color: #0000FF">checkAccess</span><span style="color: #666666">()</span> <span style="color: #008000; font-weight: bold">throws</span> Throwable <span style="color: #666666">{</span>
|
|
|
|
+</pre></div>
|
|
|
|
+
|
|
|
|
+<p>At that point, I just decided to just debug it later. It works by just forcing it anyway. So I put <code>Check.java</code> back in and proceeded to just refresh until it compiled and ran.</p>
|
|
|
|
+
|
|
|
|
+<p>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 <code>account</code> table directly. One problem though was how to set the password correctly. Plaintext obviously wouldn&rsquo;t work.</p>
|
|
|
|
+
|
|
|
|
+<p>Another note regarding Play 1.x, it provides the <a href="http://www.playframework.com/documentation/1.2.5/secure">secure module</a> which handles logins and keeping state, you simply need to implement the method <code>boolean authenticate(String username, String password)</code>. It leaves the actual process of verifying the login to the programmer. This can be exploited by just making the method return <code>true</code> and then any login would work. No need to actually set the password. Excellent.</p>
|
|
|
|
+
|
|
|
|
+<p>And we&rsquo;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, <code>IndexOutOfBoundsException occured : Index: 0, Size: 0</code></p>
|
|
|
|
+<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span style="color: #008000; font-weight: bold">if</span><span style="color: #666666">(</span>session<span style="color: #666666">.</span><span style="color: #7D9029">get</span><span style="color: #666666">(</span><span style="color: #BA2121">&quot;agencyId&quot;</span><span style="color: #666666">)</span> <span style="color: #666666">==</span> <span style="color: #008000; font-weight: bold">null</span><span style="color: #666666">)</span> <span style="color: #666666">{</span>
|
|
|
|
+
|
|
|
|
+ Agency agency <span style="color: #666666">=</span> agencies<span style="color: #666666">.</span><span style="color: #7D9029">get</span><span style="color: #666666">(0);</span> <span style="color: #408080; font-style: italic">// error here</span>
|
|
|
|
+
|
|
|
|
+ session<span style="color: #666666">.</span><span style="color: #7D9029">put</span><span style="color: #666666">(</span><span style="color: #BA2121">&quot;agencyId&quot;</span><span style="color: #666666">,</span> agency<span style="color: #666666">.</span><span style="color: #7D9029">id</span><span style="color: #666666">);</span>
|
|
|
|
+ session<span style="color: #666666">.</span><span style="color: #7D9029">put</span><span style="color: #666666">(</span><span style="color: #BA2121">&quot;agencyName&quot;</span><span style="color: #666666">,</span> agency<span style="color: #666666">.</span><span style="color: #7D9029">name</span><span style="color: #666666">);</span>
|
|
|
|
+</pre></div>
|
|
|
|
+
|
|
|
|
+<p>Apparently, we need to have an agency. That&rsquo;s generally simple enough. You just manually insert an agency into the <code>agency</code> table. After that&rsquo;s done, we finally have a view of the actual application. It&rsquo;s very Bootstrap-y, but that&rsquo;s just fine. The workflow though, is not perfectly intuitive, but I&rsquo;ll talk about that some other day.</p>
|
|
|
|
+
|
|
|
|
+<p>That&rsquo;s not the end of it though, we still have to fix these bugs. The developer obviously didn&rsquo;t have to put up with this when they were working, so what happened? Also, the log is showing some weird things,</p>
|
|
|
|
+<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%">~ _ _
|
|
|
|
+~ _ __ | | __ _ _ _| |
|
|
|
|
+~ | &#39;_ \| |/ _&#39; | || |_|
|
|
|
|
+~ | __/|_|\____|\__ (_)
|
|
|
|
+~ |_| |__/
|
|
|
|
+~
|
|
|
|
+~ 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&#39;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 &#39;gtfs-editor&#39; 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.&lt;init&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 (&#39;hibernate_sequence&#39;)
|
|
|
|
+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
|
|
|
|
+</pre></div>
|
|
|
|
+
|
|
|
|
+<p>After <code>23:32:34</code> is when I get the login page. <code>23:32:40</code> is after I&rsquo;ve logged in.</p>
|
|
|
|
+
|
|
|
|
+<h3 id="second-pass:9dc7854b573f1a2be2b19d1bfe826d39">Second Pass</h3>
|
|
|
|
+
|
|
|
|
+<p>So how did you do? First, the error that <code>type Check already defined</code> usually does mean that <code>Check</code> was already defined elsewhere. Looking in the app folder though, there was nothing of the sort. It&rsquo;s the only one there that was <code>Check.java</code>. But remember the secure module? Modules work by providing source files and Play just compiles them all together. Bingo, <code>Check.java</code>. Doing a diff shows nothing was changed. So the solution really was just simply delete <code>Check.java</code> and also <code>Secure.java</code>. No more compilation errors!</p>
|
|
|
|
+
|
|
|
|
+<p>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,</p>
|
|
|
|
+<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span style="color: #008000; font-weight: bold">if</span><span style="color: #666666">(</span>Security<span style="color: #666666">.</span><span style="color: #7D9029">isConnected</span><span style="color: #666666">())</span> <span style="color: #666666">{</span>
|
|
|
|
+ <span style="color: #666666">...</span>
|
|
|
|
+ Account account <span style="color: #666666">=</span> Account<span style="color: #666666">.</span><span style="color: #7D9029">find</span><span style="color: #666666">(</span><span style="color: #BA2121">&quot;username = ?&quot;</span><span style="color: #666666">,</span> Security<span style="color: #666666">.</span><span style="color: #7D9029">connected</span><span style="color: #666666">()).</span><span style="color: #7D9029">first</span><span style="color: #666666">();</span>
|
|
|
|
+ <span style="color: #666666">...</span>
|
|
|
|
+ <span style="color: #008000; font-weight: bold">if</span><span style="color: #666666">(</span>account <span style="color: #666666">==</span> <span style="color: #008000; font-weight: bold">null</span> <span style="color: #666666">&amp;&amp;</span> Account<span style="color: #666666">.</span><span style="color: #7D9029">count</span><span style="color: #666666">()</span> <span style="color: #666666">==</span> <span style="color: #666666">0)</span> <span style="color: #666666">{</span>
|
|
|
|
+ account <span style="color: #666666">=</span> <span style="color: #008000; font-weight: bold">new</span> Account<span style="color: #666666">(</span><span style="color: #BA2121">&quot;admin&quot;</span><span style="color: #666666">,</span> <span style="color: #BA2121">&quot;admin&quot;</span><span style="color: #666666">,</span> <span style="color: #BA2121">&quot;admin@test.com&quot;</span><span style="color: #666666">,</span> <span style="color: #008000; font-weight: bold">true</span><span style="color: #666666">,</span> <span style="color: #008000; font-weight: bold">null</span><span style="color: #666666">);</span>
|
|
|
|
+ account<span style="color: #666666">.</span><span style="color: #7D9029">save</span><span style="color: #666666">();</span>
|
|
|
|
+ <span style="color: #666666">}</span>
|
|
|
|
+ <span style="color: #666666">...</span>
|
|
|
|
+<span style="color: #666666">}</span>
|
|
|
|
+</pre></div>
|
|
|
|
+
|
|
|
|
+<p>You can actually see this in action at <code>23:32:41,051</code> in the log. So what&rsquo;s wrong with all of this? The account creation happened after I&rsquo;ve already logged in. In fact, <code>Security.isConnected()</code> checks whether the user is already logged in or not. How does this even make sense?</p>
|
|
|
|
+
|
|
|
|
+<p>Lastly, we have the problem of the agencies. Just by looking at the log, you can safely say we&rsquo;re missing a file called <code>initial-agencies-data.yml</code>. Ok, apparently it&rsquo;s a <a href="http://www.playframework.com/documentation/1.2.5/test#fixtures">fixture</a> like you would use for testing. It&rsquo;s easy enough to infer what the file&rsquo;s contents should be. We just copy it over from the GTFS data.</p>
|
|
|
|
+
|
|
|
|
+<p>But then where do you put the file? If you look at the log, it says <code>/Users/thomas/.root/opt/play-1.2.5/modules/docviewer/app/initial-agencies-data.yml</code> but that doesn&rsquo;t look right. That&rsquo;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 <code>test/</code> directory? No, that doesn&rsquo;t work either since we&rsquo;re not running a test.</p>
|
|
|
|
+
|
|
|
|
+<p>What I ended up doing was just looking at the sources for <code>Fixtures.load</code>. If you follow the stack trace, you end up finding <code>Play.javaPath</code> which sort of works like PATH for Fixtures and some other things. So where can we put the file? <code>app/</code> and <code>conf/</code>. And with that, we&rsquo;re done.</p>
|
|
|
|
+
|
|
|
|
+<h3 id="conclusion">Conclusion</h3>
|
|
|
|
+
|
|
|
|
+<p>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 <a href="https://github.com/thatsmydoing/gtfs-editor">my branch</a> as I&rsquo;ve fixed the issues discussed earlier. The default login is <code>admin:admin</code>.</p>
|
|
|
|
+
|
|
|
|
+<p>Even after getting it to run, it&rsquo;s still not quite usable. Not in the UX sense, but you really can&rsquo;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&rsquo;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.</p>
|
|
|
|
+</description>
|
|
|
|
+ </item>
|
|
|
|
+
|
|
|
|
+ <item>
|
|
|
|
+ <title>One Bus (or maybe Jeep) Away</title>
|
|
|
|
+ <link>http://pleasantprogrammer.com/posts/one-bus-or-maybe-jeep-away.html</link>
|
|
|
|
+ <pubDate>Tue, 09 Jul 2013 00:00:00 +0000</pubDate>
|
|
|
|
+
|
|
|
|
+ <guid>http://pleasantprogrammer.com/posts/one-bus-or-maybe-jeep-away.html</guid>
|
|
|
|
+ <description><p>Link: <a href="http://onebusaway.org/">http://onebusaway.org/</a></p>
|
|
|
|
+
|
|
|
|
+<p><strong>TL;DR</strong> no routing; useless in Philippines</p>
|
|
|
|
+
|
|
|
|
+<p>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.</p>
|
|
|
|
+
|
|
|
|
+<p>It&rsquo;s comparable to what you get in some bus stops abroad. You&rsquo;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&rsquo;s useful for locals who already know how to get around, and want to avoid waiting for the bus. But it&rsquo;s not particularly good for people who want to know how to get around the city.</p>
|
|
|
|
+
|
|
|
|
+<p>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&rsquo;t have the necessary infrastructure yet in the Philippines. We don&rsquo;t have bus or jeepney stops. We also wouldn&rsquo;t have realtime data to make the app particularly useful.</p>
|
|
|
|
+
|
|
|
|
+<p>You can try it out for yourself by following their <a href="https://github.com/OneBusAway/onebusaway-application-modules/wiki/OneBusAway-Quickstart-Guide">Quickstart Guide</a>. One caveat is you will have to add <code>-P tripEntriesFactory.throwExceptionOnInvalidStopToShapeMappingException=false</code> when building the bundle. This has to do with the OneBusAway having difficulty matching the <a href="https://github.com/OneBusAway/onebusaway-application-modules/wiki/Stop-to-Shape-Matching">stops to the shape data</a>.</p>
|
|
|
|
+
|
|
|
|
+<p>Here&rsquo;s some screenshots of the app with the Philippine data. Notice how you only see the stops but there isn&rsquo;t a line for the route. This is a problem with our GTFS data. Also, at some points it&rsquo;s hard to tell where the jeep is going to pass since there isn&rsquo;t any indication of order either. This is more of a OneBusAway problem. It usually expects there to be shape data available.</p>
|
|
|
|
+
|
|
|
|
+<p><a href="../galleries/transit/onebusaway1.png"><img src="../galleries/transit/onebusaway1.png" alt="OneBusAway" title="All the stops along Katipunan Avenue are named Katipunan Avenue." /></a></p>
|
|
|
|
+
|
|
|
|
+<p>It doesn&rsquo;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&rsquo;s just a bit weird though.</p>
|
|
|
|
+
|
|
|
|
+<p>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&rsquo;t the case for all jeeps though, so it might also be an implementation issue with the GTFS editor.</p>
|
|
|
|
+
|
|
|
|
+<p><a href="../galleries/transit/onebusaway2.png"><img src="../galleries/transit/onebusaway2.png" alt="OneBusAway" /></a></p>
|
|
|
|
+
|
|
|
|
+<p><a href="../galleries/transit/onebusaway3.png"><img src="../galleries/transit/onebusaway3.png" alt="OneBusAway" /></a></p>
|
|
|
|
+</description>
|
|
|
|
+ </item>
|
|
|
|
+
|
|
|
|
+ <item>
|
|
|
|
+ <title>Open Trip Planner</title>
|
|
|
|
+ <link>http://pleasantprogrammer.com/posts/open-trip-planner.html</link>
|
|
|
|
+ <pubDate>Tue, 09 Jul 2013 00:00:00 +0000</pubDate>
|
|
|
|
+
|
|
|
|
+ <guid>http://pleasantprogrammer.com/posts/open-trip-planner.html</guid>
|
|
|
|
+ <description>
|
|
|
|
+
|
|
|
|
+<p>Link: <a href="http://www.opentripplanner.org">http://www.opentripplanner.org</a></p>
|
|
|
|
+
|
|
|
|
+<p><strong>TL;DR</strong> routes pretty well; data might cause weird issues</p>
|
|
|
|
+
|
|
|
|
+<p>OpenTripPlanner, as the name implies, is a routing app. Given point A and point B, it can provide possible routes by taking transit, riding a bike, or a mix of both. You can also specify options on how much walking you&rsquo;re willing to do or if you prefer fewer transfers over trip time. It could be a good competitor to the transit directions of Google Maps.</p>
|
|
|
|
+
|
|
|
|
+<p>It&rsquo;s actually in general use by the <a href="http://maps.trimet.org/">Trimet</a>, Portland&rsquo;s public transit system. I think a good reason why they deployed OpenTripPlanner is that Portland is a very bike friendly area. OpenTripPlanner&rsquo;s support for multi-modal (bike + transit) routing is one thing that even Google Maps doesn&rsquo;t have. This actually just screams <a href="http://philippine-transit.hackathome.com/prizes/">Inclusive Technology Award</a>.</p>
|
|
|
|
+
|
|
|
|
+<h3 id="setup:8052f9d579c0ac6326f58a643a8791fb">Setup</h3>
|
|
|
|
+
|
|
|
|
+<p>Getting OpenTripPlanner up and running involves a bit more downloading than OneBusAway. I&rsquo;d suggest going through the <a href="https://github.com/openplans/OpenTripPlanner/wiki/FiveMinutes">5-minute introduction</a> if you want to actually work with the Philippine data. You will also need to download the <a href="http://download.geofabrik.de/asia/philippines.html">Philippine data dump</a> from OSM. You will want the <code>osm.bz2</code> one (WARNING: 900MB unzipped).</p>
|
|
|
|
+
|
|
|
|
+<p>Once you get the webapp running, you&rsquo;ll notice the map tiles won&rsquo;t load correctly. This is because the default tileset used is from Mapbox which doesn&rsquo;t provide publicly free tilesets anymore. To actually see things on the map, you should click the + on the upper-right of the map and change the base layer to something like Open Street Map or OSM Mapquest. This has been fixed in their latest sources.</p>
|
|
|
|
+
|
|
|
|
+<h3 id="issues:8052f9d579c0ac6326f58a643a8791fb">Issues</h3>
|
|
|
|
+
|
|
|
|
+<p>The next thing you&rsquo;ll notice is that you can&rsquo;t search for a place. You can only just pick points on the map and route between those. I&rsquo;m still not exactly sure if it&rsquo;s supposed to have it, since the Trimet one has it. But even then adding it by using the Google Maps or MapQuest APIs shouldn&rsquo;t be too difficult.</p>
|
|
|
|
+
|
|
|
|
+<p>Another missing thing compared to the Trimet planner is being able to look at the routes akin to OneBusAway. And even then, Trimet&rsquo;s implementation isn&rsquo;t as good for exploring as OneBusAway is. Seeing the schedule or seeing which routes pass through a stop are left to an external site to do.</p>
|
|
|
|
+
|
|
|
|
+<p>There have been some weird issues with the routing though. A common occurence is the steps are somewhat disconnected (see image below). The left half shows OpenTripPlanner, it shows that you get off at a &ldquo;stop&rdquo; in EDSA and you should magically teleport to Arguilla street and start walking. To be fair, Google Maps (right half) shows that there is a street from the &ldquo;stop&rdquo; to Arguilla.</p>
|
|
|
|
+
|
|
|
|
+<p><img src="../galleries/transit/otp1.png" alt="OpenTripPlanner disconnected route" /></p>
|
|
|
|
+
|
|
|
|
+<p>I can&rsquo;t say this isn&rsquo;t a bug. After all, OpenTripPlanner couldn&rsquo;t have magically known there really was a street there. If it did, it wouldn&rsquo;t just teleport you to the corner. I&rsquo;m more inclined to think though that this is a result of not having any shape data. As a result, OpenTripPlanner might try to assume the stop could mean places within a certain radius of where it was defined.</p>
|
|
|
|
+
|
|
|
|
+<p>Another weird issue that pops up sometimes is where it tells you to ride a jeep past the stop you want and then after a while, get off and ride a jeep back to your stop. A more general issue is that sometimes it won&rsquo;t give you the best route because it thinks you have to loop around to get to where you want to be. I don&rsquo;t really know how common this issue pops up though. It&rsquo;s highly dependent on where you put the marker. If you just move the marker down a little bit, it actually does give the correct route.</p>
|
|
|
|
+
|
|
|
|
+<p><img src="../galleries/transit/otp2.png" alt="OpenTripPlanner loopy route" /></p>
|
|
|
|
+
|
|
|
|
+<p>Much like the earlier problem, I can&rsquo;t tell if this is a bug or it&rsquo;s a result of the bad data. Once again though, I think the issue is more of bad data. If you look at the plotted UP-Katipunan route, the stops aren&rsquo;t even on the road. This probably makes it more difficult for OpenTripPlanner to actually tell if the stop and road are connected.</p>
|
|
|
|
+
|
|
|
|
+<p><img src="../galleries/transit/upkatipunan.jpg" alt="UP Katipunan Route" /></p>
|
|
|
|
+
|
|
|
|
+<p>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&rsquo;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.</p>
|
|
|
|
+
|
|
|
|
+<h3 id="conclusion:8052f9d579c0ac6326f58a643a8791fb">Conclusion</h3>
|
|
|
|
+
|
|
|
|
+<p>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&rsquo;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.</p>
|
|
|
|
+</description>
|
|
|
|
+ </item>
|
|
|
|
+
|
|
|
|
+ </channel>
|
|
|
|
+</rss>
|