Alex Jhttps://alexj.org/
Recent content on Alex JHugo -- gohugo.ioalex@alexj.org (Alex Jackson)alex@alexj.org (Alex Jackson)Thu, 07 Dec 2017 18:00:00 +0000A Banner View for iOS 11+https://alexj.org/12/banner-view/
Thu, 07 Dec 2017 18:00:00 +0000alex@alexj.org (Alex Jackson)https://alexj.org/12/banner-view/I needed a way to present non-modal alerts inside an app I&rsquo;m working on and wanted to use a banner system that&rsquo;s a bit like what Tweetbot1 does. I ended up writing a UIView subclass called BannerView that I&rsquo;ve open sourced for anybody to use.
<p>I needed a way to present non-modal alerts inside an app I&rsquo;m working on and
wanted to use a banner system that&rsquo;s a bit like what Tweetbot<sup class="footnote-ref" id="fnref:fn-tweetbot"><a rel="footnote" href="#fn:fn-tweetbot">1</a></sup>
does. I ended up writing a <code>UIView</code> subclass called <code>BannerView</code> that I&rsquo;ve <a href="https://gist.github.com/alexjohnj/df4d969fa0ac6f29fa8a134c91fa30ff">open
sourced</a> for anybody to use.</p>
<p></p>
<p>The banner view uses the new <a href="https://developer.apple.com/documentation/uikit/uiview/2891102-safearealayoutguide">safe area layout guides</a> introduced
in iOS 11 to lay itself out correctly when navigation bars are present. The top
of the banner expands to fill the top safe area which looks really cool on an
iPhone X<sup class="footnote-ref" id="fnref:fn-iphone-x"><a rel="footnote" href="#fn:fn-iphone-x">2</a></sup>:</p>
<video loop autoplay muted>
<source src="https://alexj.org/videos/banner-view/no-nav.webm" type="video/webm">
<source src="https://alexj.org/videos/banner-view/no-nav.mp4" type="video/mp4">
Ack! Your browser doesn't support WebM or MP4 videos! What is this, the 3DS browser?
</video>
<p>The appearance of the banner is easily customised and an optional icon can be
displayed alongside the message. There&rsquo;s support for a swipe-to-dismiss gesture
baked in too.</p>
<p>There are a few minor issues but they shouldn&rsquo;t be too hard to fix. The banner
doesn&rsquo;t quite resize properly if the phone&rsquo;s rotated and things get a bit funky
if the banner&rsquo;s embedded inside a navigation bar with <code>prefersLargeTitles =
true</code>. Oh, and there&rsquo;s no built in way to perform an action when the user taps
the banner although you could accomplish that by attaching a
<code>UITapGestureRecognizer</code> to the view.</p>
<p>Again, you can get <code>BannerView</code> from <a href="https://gist.github.com/alexjohnj/df4d969fa0ac6f29fa8a134c91fa30ff">here</a>. It&rsquo;s licensed under
an MIT license.</p>
<div class="footnotes">
<hr />
<ol>
<li id="fn:fn-tweetbot">I haven&rsquo;t used Tweetbot for almost a year but I know it <em>used</em> to have these banners.
<a class="footnote-return" href="#fnref:fn-tweetbot"><sup>[return]</sup></a></li>
<li id="fn:fn-iphone-x">At least, it does in the simulator. I can only imagine what it looks like on an actual device.
<a class="footnote-return" href="#fnref:fn-iphone-x"><sup>[return]</sup></a></li>
</ol>
</div>How a Core Data Attribute's Name Can Lead to Crasheshttps://alexj.org/11/core-data-attribute-naming/
Fri, 10 Nov 2017 19:55:00 +0000alex@alexj.org (Alex Jackson)https://alexj.org/11/core-data-attribute-naming/TL;DR: You can&rsquo;t name a Core Data attribute new* in Objective-C or Swift because of how automatic reference counting interacts with manual reference counting. If you do, you&rsquo;ll crash unreliably when your Core Data stack is deallocated.
I&rsquo;ve spent the better part of a day trying to fix this hard to track down bug in my Core Data stack that was causing a crash. The crash was introduced when I added a new entity to my object model. The NSManagedObject subclass looked a little like this:
<p><em>TL;DR: You can&rsquo;t name a Core Data attribute <code>new*</code> in Objective-C or Swift
because of how automatic reference counting interacts with manual reference
counting. If you do, you&rsquo;ll crash unreliably when your Core Data stack is
deallocated.</em></p>
<p>I&rsquo;ve spent the better part of a day trying to fix this hard to track down bug in
my Core Data stack that was causing a crash. The crash was introduced when I
added a new entity to my object model. The <code>NSManagedObject</code> subclass looked a
little like this:</p>
<p></p>
<div class="highlight"><pre style="background-color:#f0f3f3;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-swift" data-lang="swift"><span style="color:#069;font-weight:bold">public</span> <span style="color:#069;font-weight:bold">final</span> <span style="color:#069;font-weight:bold">class</span> <span style="color:#0a8;font-weight:bold">RenamedThing</span>: NSManagedObject {
<span style="color:#069;font-weight:bold">@NSManaged</span> <span style="color:#069;font-weight:bold">private</span>(<span style="color:#069;font-weight:bold">set</span>) <span style="color:#069;font-weight:bold">public</span> <span style="color:#069;font-weight:bold">var</span> <span style="color:#033">newName</span>: <span style="color:#366">String</span>
<span style="color:#069;font-weight:bold">@NSManaged</span> <span style="color:#069;font-weight:bold">private</span>(<span style="color:#069;font-weight:bold">set</span>) <span style="color:#069;font-weight:bold">public</span> <span style="color:#069;font-weight:bold">var</span> <span style="color:#033">oldName</span>: <span style="color:#366">String</span>
<span style="color:#069;font-weight:bold">@NSManaged</span> <span style="color:#069;font-weight:bold">public</span> <span style="color:#069;font-weight:bold">var</span> <span style="color:#033">markedForLocalDeletionDate</span>: Date?
}</code></pre></div>
<p>Any tests that accessed <code>RenamedThing</code>&rsquo;s <code>newName</code> attribute would crash when
the <code>NSPersistentContainer</code> was set to <code>nil</code> in the test&rsquo;s <code>tearDown()</code>
method. The crash message looked like:</p>
<div class="highlight"><pre style="background-color:#f0f3f3;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-text" data-lang="text">xctest(..) malloc: *** error for object ..: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug</code></pre></div>
<p>After eliminating any possibility of this being a bug related to Core Data&rsquo;s
concurrency model, I broke out Xcode&rsquo;s memory graph debugger and then <code>NSZombie</code>
to see if I could find anything. This felt like an odd thing to do since this is
Swift and so automatic reference counting (ARC) is active and I can&rsquo;t make any
manual calls to <code>release</code> anywhere. In the end, neither the memory graph
debugger nor <code>NSZombie</code> were of any help.</p>
<p>At this point I was starting to think that this might be a bug in Core Data. To
check I wasn&rsquo;t doing something crazy stupid with ARC though, I checked through
the documentation on ARC. Eventually, I came across the <a href="https://developer.apple.com/library/content/releasenotes/ObjectiveC/RN-TransitioningToARC/Introduction/Introduction.html#//apple_ref/doc/uid/TP40011226-CH1-SW14">Transitioning to ARC
release notes</a> and found this lovely tidbit under the &ldquo;new&rdquo;
rules section:</p>
<blockquote>
<p>You cannot give an accessor a name that begins with new. This in turn means
that you can’t, for example, declare a property whose name begins with new
unless you specify a different getter[.]</p>
</blockquote>
<p>I renamed the <code>newName</code> attribute to something else and, of course, my tests
stopped crashing. This is both my favourite and least favourite type of bug&mdash;a
bug that takes hours to figure out but just a second to fix.</p>
<p>I was surprised to find that the transitioning to ARC guide is still relevant
today, even in Swift. I <em>think</em> this means that Core Data is still using manual
memory management (at least in parts) which is a little surprising given how
long ARC has been available and how complicated the memory management must be
for Core Data. Still, &ldquo;if it ain&rsquo;t broke then don&rsquo;t fix it&rdquo; is probably a
<em>really</em> good rule to stick by for something as complex as Core Data.</p>Core Data Property-Level Model Validation in Swift 4https://alexj.org/09/core-data-model-validation-swift4/
Mon, 25 Sep 2017 19:00:00 +0100alex@alexj.org (Alex Jackson)https://alexj.org/09/core-data-model-validation-swift4/I ran into an issue while writing property validation methods for a Core Data stack where the methods simply weren&rsquo;t being called. After a bit of head scratching I realised it was because the methods needed to be annotated with @objc. This wasn&rsquo;t needed in Swift 3 because @objc was inferred on all methods of subclasses of NSObject; however, the behaviour of @objc inference changed in Swift 4. Now, subclasses of NSObject must explicitly mark methods that need to be accessible from Objective-C. This took longer to realise than it should have since the Core Data documentation&rsquo;s sample code for property-level validation hasn&rsquo;t been updated for Swift 4.
<p>I ran into an issue while writing property validation methods for a Core Data
stack where the methods simply weren&rsquo;t being called. After a bit of head
scratching I realised it was because the methods needed to be annotated with
<code>@objc</code>. This wasn&rsquo;t needed in Swift 3 because <code>@objc</code> was inferred on all
methods of subclasses of <code>NSObject</code>; however, the behaviour of <code>@objc</code> inference
<a href="https://github.com/apple/swift-evolution/blob/master/proposals/0160-objc-inference.md">changed in Swift 4</a>. Now, subclasses of <code>NSObject</code>
must explicitly mark methods that need to be accessible from Objective-C. This
took longer to realise than it should have since the <a href="https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CoreData/ObjectValidation.html#//apple_ref/doc/uid/TP40001075-CH20-SW1">Core Data
documentation&rsquo;s</a> sample code for property-level
validation hasn&rsquo;t been updated for Swift 4.</p>
<p>
<!--theres-no-more--></p>Strongly Typed Notifications in Swifthttps://alexj.org/07/swift-typed-notifications/
Fri, 07 Jul 2017 14:48:00 +0000alex@alexj.org (Alex Jackson)https://alexj.org/07/swift-typed-notifications/While working on rewriting Spotijack in Swift, I started to feel dissatisfied with Foundation&rsquo;s notification API. It&rsquo;s a stringly typed API that makes heavy use of Any and as someone who loves their types this makes me sad. To cheer myself up, I set about writing a more strongly typed notification system.
The end result is a small library1&mdash;TypedNotification&mdash;that provides a set of protocols defining a more descriptive type system for notifications. Check out the GitHub project if you&rsquo;re interested. There&rsquo;s a Playground in it demoing the protocols. The rest of this blog post will cover them in a bit more detail.
<p>While working on rewriting <a href="https://github.com/alexjohnj/spotijack">Spotijack</a> in Swift, I started to
feel dissatisfied with
Foundation&rsquo;s <a href="https://developer.apple.com/documentation/foundation/notificationcenter">notification API</a>. It&rsquo;s a stringly typed
API that makes heavy use of <code>Any</code> and as someone who <em>loves</em> their types this
makes me sad. To cheer myself up, I set about writing a more strongly typed
notification system.</p>
<p>The end result is a small
library<sup class="footnote-ref" id="fnref:fn-microframework"><a rel="footnote" href="#fn:fn-microframework">1</a></sup>&mdash;<a href="https://github.com/alexjohnj/typednotification">TypedNotification</a>&mdash;that
provides a set of protocols defining a more descriptive type system for
notifications. Check out the GitHub project if you&rsquo;re interested. There&rsquo;s a
Playground in it demoing the protocols. The rest of this blog post will cover
them in a bit more detail.</p>
<p></p>
<h2 id="features">Features</h2>
<p>Before I show you the protocols, let me run you through what I wanted to
achieve.</p>
<h3 id="closure-based-api">Closure Based API</h3>
<p>First, I wanted to have a closure based API that closely mirrors the foundation
API. Swift has a concise syntax for closures that makes it easy to create short
pieces of code. For longer blocks of code, Swift has function references that
let functions be used as closures. Furthermore, closures encapsulate information
on the types of their arguments which selectors lack. The foundation API already
contains a block based function for notifications so my protocol can simply
mimic that API.</p>
<h3 id="notifications-as-types">Notifications as Types</h3>
<p>The second requirement is for notifications to convey as much information as
possible using their types. That means no identifying notifications by a string
(at least, not to the user) and no <code>userInfo</code> dictionary to attach data to a
notification. A notification&rsquo;s identifier should be inherent to its type and any
data attached to the notification should be declared as properties.</p>
<h3 id="automatic-removal-of-observers">Automatic Removal of Observers</h3>
<p>Finally, I wanted to get rid of the need to think about the lifetime of
observers. The block based foundation API returns an opaque object that users
must remember to unregister before it is deallocated. Forgetting to manage these
objects creates bugs that are difficult to pass off as features.</p>
<h2 id="the-typednotifcation-protocol">The <em>TypedNotifcation</em> Protocol</h2>
<h3 id="overview">Overview</h3>
<p>This is the core protocol of <em>TypedNotifications</em>. Types that conform to this
protocol can be posted as notifications. The protocol declaration is simple:</p>
<div class="highlight"><pre style="background-color:#f0f3f3;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-swift" data-lang="swift"><span style="color:#069;font-weight:bold">protocol</span> <span style="color:#0a8;font-weight:bold">TypedNotification</span>: Namespaced {
associatedtype Sender
<span style="color:#09f;font-style:italic">/// The name of the notification to be used as an identifier.</span>
<span style="color:#069;font-weight:bold">static</span> <span style="color:#069;font-weight:bold">var</span> <span style="color:#033">name</span>: <span style="color:#366">String</span> { <span style="color:#069;font-weight:bold">get</span> }
<span style="color:#09f;font-style:italic">/// The object sending the notification.</span>
<span style="color:#069;font-weight:bold">var</span> <span style="color:#033">sender</span>: Sender { <span style="color:#069;font-weight:bold">get</span> }
}</code></pre></div>
<p>All types conforming to <code>TypedNotification</code> have a <code>name</code> property that&rsquo;s used
to identify the notification and a <code>sender</code> property that&rsquo;s used to identify the
sender. The <code>sender</code> property has an associated type that can be used to
constrain senders to a subset of types.</p>
<p>This protocol reduces the chances of making a mistake with the stringly typed
notification system by only having to declare the name of the notification
once. It also adds some information about the contents of the notification by
providing an associated type for the <code>sender</code> property.</p>
<p>To reduce the chances of a notification name collision, I&rsquo;ve made the
<code>TypedNotification</code> protocol conform to a <code>Namespaced</code> protocol which looks
like:</p>
<div class="highlight"><pre style="background-color:#f0f3f3;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-swift" data-lang="swift"><span style="color:#069;font-weight:bold">protocol</span> <span style="color:#0a8;font-weight:bold">Namespaced</span> {
<span style="color:#069;font-weight:bold">static</span> <span style="color:#069;font-weight:bold">var</span> <span style="color:#033">namespace</span>: <span style="color:#366">String</span> { <span style="color:#069;font-weight:bold">get</span> }
}</code></pre></div>
<p>A protocol extension on <code>TypedNotifcation</code> uses the <code>Namespaced</code> protocol to
provide a default implementation for the <code>name</code> property:</p>
<div class="highlight"><pre style="background-color:#f0f3f3;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-swift" data-lang="swift"><span style="color:#069;font-weight:bold">extension</span> <span style="color:#0a8;font-weight:bold">TypedNotification</span> {
<span style="color:#069;font-weight:bold">static</span> <span style="color:#069;font-weight:bold">var</span> <span style="color:#033">name</span>: <span style="color:#366">String</span> {
<span style="color:#069;font-weight:bold">return</span> <span style="color:#c30">&#34;</span><span style="color:#a00">\(</span><span style="color:#069;font-weight:bold">Self</span>.namespace<span style="color:#a00">)</span><span style="color:#c30">.</span><span style="color:#a00">\(</span><span style="color:#069;font-weight:bold">Self</span>.<span style="color:#069;font-weight:bold">self</span><span style="color:#a00">)</span><span style="color:#c30">&#34;</span>
}
}</code></pre></div>
<p>This will generate a notification name using the <code>namespace</code> property and the
name of the type conforming to <code>TypedNotifcation</code>.</p>
<h3 id="usage">Usage</h3>
<p>For each notification that your application posts, create a type that conforms
to <code>TypedNotification</code> and implement the required properties. Thanks to the
aforementioned protocol extension, only the <code>sender</code> and <code>namespace</code> properties
need to be implemented. You can write a protocol extension on <code>Namespaced</code> to
reduce the implementation down to just the <code>sender</code> property. As an example:</p>
<div class="highlight"><pre style="background-color:#f0f3f3;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-swift" data-lang="swift"><span style="color:#069;font-weight:bold">extension</span> <span style="color:#0a8;font-weight:bold">Namespaced</span> {
<span style="color:#069;font-weight:bold">static</span> <span style="color:#069;font-weight:bold">var</span> <span style="color:#033">namespace</span>: <span style="color:#366">String</span> { <span style="color:#069;font-weight:bold">return</span> <span style="color:#c30">&#34;org.alexj&#34;</span> }
}
<span style="color:#069;font-weight:bold">struct</span> <span style="color:#0a8;font-weight:bold">ExampleNotification</span>: TypedNotification {
<span style="color:#069;font-weight:bold">let</span> <span style="color:#033">sender</span>: ExampleClass
<span style="color:#069;font-weight:bold">let</span> <span style="color:#033">newValue</span>: <span style="color:#366">Double</span>
}</code></pre></div>
<p>Here, <code>ExampleClass</code> is the only class that&rsquo;s responsible for sending instances
of <code>ExampleNotification</code>. If multiple types can post a notification, consider
constraining the <code>sender</code> property using a protocol. If worst comes to worst,
you can make <code>sender</code> an instance of <code>Any?</code> at the expense of some type safety.</p>
<h2 id="the-typednotificationcenter-protocol">The <em>TypedNotificationCenter</em> Protocol</h2>
<h3 id="overview-1">Overview</h3>
<p>To post instances of <code>TypedNotifcation</code>, the library provides another protocol
called <code>TypedNotificationCenter</code>. This declares three methods to post
notifications, add observers and remove observers:</p>
<div class="highlight"><pre style="background-color:#f0f3f3;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-swift" data-lang="swift"><span style="color:#069;font-weight:bold">protocol</span> <span style="color:#0a8;font-weight:bold">TypedNotificationCenter</span> {
<span style="color:#09f;font-style:italic">/// Post a `TypedNotification`</span>
<span style="color:#069;font-weight:bold">func</span> <span style="color:#c0f">post</span>&lt;T: TypedNotification<span style="color:#555">&gt;</span>(<span style="color:#069;font-weight:bold">_</span> notification: T)
<span style="color:#09f;font-style:italic">/// Register a block to be executed when a `TypedNotification` is posted.</span>
<span style="color:#069;font-weight:bold">func</span> <span style="color:#c0f">addObserver</span>&lt;T: TypedNotification<span style="color:#555">&gt;</span>(forType type: T.<span style="color:#069;font-weight:bold">Type</span>, object obj: T.Sender?,
queue: OperationQueue?, using block: @escaping (T) -&gt; <span style="color:#366">Void</span>) -&gt; NotificationObserver
<span style="color:#09f;font-style:italic">/// Deregister a `NotificationObserver`.</span>
<span style="color:#069;font-weight:bold">func</span> <span style="color:#c0f">removeObserver</span>(observer: NotificationObserver)
}</code></pre></div>
<p>Aside from a different type signature, these methods mirror the Foundation
<code>NotificationCenter</code> APIs. <em>TypedNotification</em> includes an extension on
<code>NotificationCenter</code> that adds conformance to the <code>TypedNotificationCenter</code>
protocol. You can use the protocol when writing tests.</p>
<h3 id="the-notifcationobserver-class">The <em>NotifcationObserver</em> Class</h3>
<p>The <code>addObserver</code> method returns an instance of <code>NotificationObserver</code> rather
than the <code>NSObjectProtocol</code> conforming object returned by the Foundation
API. <code>NotificationObserver</code> is a lightweight class that stores an
<code>NSObjectProtocol</code> conforming object. When a <code>NotificationObserver</code> is
deallocated, <code>removeObserver</code> is automatically called. There&rsquo;s no need to
manually remove observers any more, just store<sup class="footnote-ref" id="fnref:fn-notificationobserver-return"><a rel="footnote" href="#fn:fn-notificationobserver-return">2</a></sup>
a strong reference to the <code>NotificationObserver</code>.</p>
<h3 id="usage-1">Usage</h3>
<p>Usage is almost identical to using the Foundation API. Building on the previous
example, here&rsquo;s how to use a <code>TypedNotification</code> conforming type with
<code>NotificationCenter</code>:</p>
<div class="highlight"><pre style="background-color:#f0f3f3;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-swift" data-lang="swift"><span style="color:#069;font-weight:bold">class</span> <span style="color:#0a8;font-weight:bold">ExampleClass</span> {
<span style="color:#069;font-weight:bold">private</span> <span style="color:#069;font-weight:bold">let</span> <span style="color:#033">center</span> = NotificationCenter.<span style="color:#069;font-weight:bold">default</span>
<span style="color:#069;font-weight:bold">private</span> <span style="color:#069;font-weight:bold">var</span> <span style="color:#033">_valueObserver</span>: NotificationObserver? = <span style="color:#069;font-weight:bold">nil</span>
<span style="color:#069;font-weight:bold">init</span>() {
_valueObserver = center.addObserver(forType: ExampleNotification.<span style="color:#069;font-weight:bold">self</span>, object: <span style="color:#069;font-weight:bold">self</span>, queue: <span style="color:#069;font-weight:bold">nil</span>) { (noti) <span style="color:#069;font-weight:bold">in</span>
print(<span style="color:#c30">&#34;New value: </span><span style="color:#a00">\(</span>noti.newValue<span style="color:#a00">)</span><span style="color:#c30">&#34;</span>)
}
}
<span style="color:#069;font-weight:bold">var</span> <span style="color:#033">value</span> = <span style="color:#f60">0.0</span> {
<span style="color:#069;font-weight:bold">didSet</span> {
center.post(ExampleNotification(sender: <span style="color:#069;font-weight:bold">self</span>, newValue: value))
}
}
}</code></pre></div>
<p>Note that the closure parameter <code>noti</code> is of type <code>ExampleNotification</code> so you
can directly access the <code>newValue</code> property without any downcasting. Also note
that the observer is tied to the lifetime of <code>ExampleClass</code>. When an instance of
<code>ExampleClass</code> is deallocated, <code>_valueObserver</code> will remove itself as an
observer.</p>
<h2 id="conclusions">Conclusions</h2>
<p>I think the advantages of this library compared to the Foundation API are
clear. Representing notifications as types improves the safety of your code by
eliminating manually managed string identifiers and weakly typed <code>userInfo</code>
dictionaries. A further advantage of typed notifications is
self-documentation. As data attached to a notification is part of the type,
there&rsquo;s no need to document the keys of a <code>userInfo</code> dictionary. Users can look
at the public interface of a <code>TypedNotification</code> conforming type to see what
data it provides.</p>
<p>The <code>TypedNotificationCenter</code> protocol goes hand in hand with the
<code>TypedNotification</code> protocol. It improves run time safety by automatically
removing observers when they are deallocated, eliminating an entire class of
bugs. Furthermore, it provides a starting point for writing tests for
notifications.</p>
<p>The <em>TypedNotification</em> library is available
from <a href="https://github.com/alexjohnj/typednotification">GitHub</a> under an MIT license. It is compatible
with the Swift Package Manager and Carthage.</p>
<div class="footnotes">
<hr />
<ol>
<li id="fn:fn-microframework">I believe the cool kids call this a µFramework.
<a class="footnote-return" href="#fnref:fn-microframework"><sup>[return]</sup></a></li>
<li id="fn:fn-notificationobserver-return">Xcode will emit a warning if you don&rsquo;t store the returned <code>NotificationObserver</code>. It might be a good idea to enable &ldquo;Treat Warnings as Errors&rdquo; in your build settings.
<a class="footnote-return" href="#fnref:fn-notificationobserver-return"><sup>[return]</sup></a></li>
</ol>
</div>Fixing MATLAB on Fedorahttps://alexj.org/03/fixing-matlab-fedora/
Fri, 10 Mar 2017 15:00:00 +0000alex@alexj.org (Alex Jackson)https://alexj.org/03/fixing-matlab-fedora/The other week I had to set up a new installation of MATLAB r2016a on a (somewhat) fresh Fedora installation. After running the installer, I ran into a bunch of library errors when trying to run external C++ programs1 from MATLAB or when trying to plot something. When running an external C++ program, MATLAB would complain about missing versions of CXXABI and GLIBCXX in libstdc++2. When plotting something, MATLAB would complain about libmwosgserver.so.
<p>The other week I had to set up a new installation of MATLAB r2016a on a
(somewhat) fresh Fedora installation. After running the installer, I ran into a
bunch of library errors when trying to run external C++ programs<sup class="footnote-ref" id="fnref:fish-matlab"><a rel="footnote" href="#fn:fish-matlab">1</a></sup>
from MATLAB or when trying to plot something. When running an external C++
program, MATLAB would complain about missing versions of <code>CXXABI</code> and <code>GLIBCXX</code>
in <code>libstdc++</code><sup class="footnote-ref" id="fnref:1"><a rel="footnote" href="#fn:1">2</a></sup>. When plotting something, MATLAB would complain about
<code>libmwosgserver.so</code>.</p>
<p></p>
<p>The first problem is caused by MATLAB trying to use its own, older version of
<code>libstdc++</code>. The second problem is caused by MATLAB trying to use the system&rsquo;s
version of <code>libmwosgserver</code>. To fix the error when running C++ programs, I had
to tell MATLAB to use the system&rsquo;s version of <code>libstdc++</code>. To fix the error when
plotting, I had to tell MATLAB to use its own OpenGL libraries rather than the
system&rsquo;s.</p>
<p>The fixes are easy to make, you need to edit a couple of lines in a startup
script. First of all, find out where the system&rsquo;s version of <code>libstdc++</code> is
located (<code>$</code> indicates text to enter in a shell):</p>
<div class="highlight"><pre style="background-color:#f0f3f3;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ find /usr -name <span style="color:#c30">&#39;libstdc++.so.6&#39;</span> -exec dirname <span style="color:#c30">&#39;{}&#39;</span> <span style="color:#c30;font-weight:bold">\;</span>
/usr/local/MATLAB/R2016a/sys/os/glnxa64
/usr/lib64
/usr/lib</code></pre></div>
<p>The first line is MATLAB&rsquo;s version of the library, the second the system&rsquo;s
64-bit version of the library, the third the system&rsquo;s 32-bit version. If you&rsquo;re
somehow still on a 32-bit system you&rsquo;ll need to note down the path
<code>/usr/lib</code>. Otherwise, the path you need is <code>/usr/lib64</code>. Now you need to edit
MATLAB&rsquo;s init script. The exact location will depend on where you installed
MATLAB to. Assuming you installed MATLAB into the <code>/usr/local</code> directory then
you&rsquo;ll need to edit <code>/usr/local/MATLAB/R2016a/bin/.matlab7rc.sh</code>.</p>
<p>This script is essentially a massive switch statement that sets different
environment variables depending on which operating system and architecture
you&rsquo;re on. Find the case statement corresponding to your architecture (<code>glnxa64</code>
for 64-bit Linux) which will look something like this:</p>
<div class="highlight"><pre style="background-color:#f0f3f3;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#069;font-weight:bold">case</span> <span style="color:#c30">&#34;</span><span style="color:#033">$ARCH</span><span style="color:#c30">&#34;</span> in
glnx86|glnxa64<span style="color:#555">)</span></code></pre></div>
<p>For me that was around line 164 but it will probably depend on which version of
MATLAB you&rsquo;re running. Inside this case, find the line that says</p>
<div class="highlight"><pre style="background-color:#f0f3f3;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#033">LDPATH_PREFIX</span><span style="color:#555">=</span><span style="color:#c30">&#34;&#34;</span></code></pre></div>
<p>and change it to</p>
<div class="highlight"><pre style="background-color:#f0f3f3;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#033">LDPATH_PREFIX</span><span style="color:#555">=</span><span style="color:#c30">&#34;</span><span style="color:#033">$MATLAB</span><span style="color:#c30">/sys/opengl/lib/</span><span style="color:#033">$ARCH</span><span style="color:#c30">:/usr/lib64&#34;</span></code></pre></div>
<p>This pushes MATLAB&rsquo;s OpenGL libraries and the system&rsquo;s C++ libraries to the
front of MATLAB&rsquo;s load path, forcing it to use those versions of the
libraries. Save the file, restart MATLAB and you should be good to go.</p>
<div class="footnotes">
<hr />
<ol>
<li id="fn:fish-matlab">Since I use fish as my shell, that meant any external command.
<a class="footnote-return" href="#fnref:fish-matlab"><sup>[return]</sup></a></li>
<li id="fn:1">Really it was the external program complaining, not MATLAB.
<a class="footnote-return" href="#fnref:1"><sup>[return]</sup></a></li>
</ol>
</div>Integrating Receipts with ledger-modehttps://alexj.org/07/integrating-receipts-with-ledger-mode/
Sat, 02 Jul 2016 16:00:00 +0000alex@alexj.org (Alex Jackson)https://alexj.org/07/integrating-receipts-with-ledger-mode/I&rsquo;ve written a couple of functions for Emacs&rsquo; ledger-mode that make working with receipts a bit easier. With the cursor on a transaction, calling alex/ledger-attach-receipt will prompt for a file. This function copies the file to a receipts directory, renaming it to its hash and sorting it in subdirectories according to the transaction&rsquo;s year and month1. Finally, the function adds a comment to the transaction with the hash of the file. The function alex/ledger-open-attached-receipt reads this comment and opens the associated file in Emacs. The receipts folder can be customised through the variable alex/ledger-receipt-folder.
<p>I&rsquo;ve written a couple of functions for Emacs&rsquo; ledger-mode that make working with
receipts a bit easier. With the cursor on a transaction, calling
<code>alex/ledger-attach-receipt</code> will prompt for a file. This function copies the
file to a receipts directory, renaming it to its hash and sorting it in
subdirectories according to the transaction&rsquo;s year and month<sup class="footnote-ref" id="fnref:sorting"><a rel="footnote" href="#fn:sorting">1</a></sup>. Finally,
the function adds a comment to the transaction with the hash of the file. The
function <code>alex/ledger-open-attached-receipt</code> reads this comment and opens the
associated file in Emacs. The receipts folder can be customised through the
variable <code>alex/ledger-receipt-folder</code>.</p>
<p></p>
<div class="highlight"><pre style="background-color:#f0f3f3;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-emacs-lisp" data-lang="emacs-lisp">(<span style="color:#366">defvar</span> <span style="color:#033">alex/ledger-receipt-folder</span> <span style="color:#c30">&#34;~/finance/receipts&#34;</span>)
(<span style="color:#366">defun</span> <span style="color:#033">alex/ledger-get-xact-date</span> ()
<span style="color:#c30">&#34;Read the effective date (before =) of a
</span><span style="color:#c30">transaction. Returns the date as a time value.&#34;</span>
(<span style="color:#366">save-excursion</span>
(<span style="color:#033">ledger-navigate-beginning-of-xact</span>)
(<span style="color:#c0f">re-search-forward</span> <span style="color:#033">ledger-iso-date-regexp</span>)
(<span style="color:#c0f">encode-time</span> <span style="color:#f60">0</span> <span style="color:#f60">0</span> <span style="color:#f60">0</span> (<span style="color:#c0f">string-to-number</span> (<span style="color:#033">match-string</span> <span style="color:#f60">4</span>))
(<span style="color:#c0f">string-to-number</span> (<span style="color:#033">match-string</span> <span style="color:#f60">3</span>))
(<span style="color:#c0f">string-to-number</span> (<span style="color:#033">match-string</span> <span style="color:#f60">2</span>)))))
(<span style="color:#366">defun</span> <span style="color:#033">alex/ledger-construct-receipt-path</span> (<span style="color:#033">date</span> <span style="color:#033">hash</span> <span style="color:#069">&amp;optional</span> <span style="color:#033">ext</span>)
<span style="color:#c30">&#34;Construct a path to a receipt file. DATE is a time value. HASH is a
</span><span style="color:#c30">string. EXT is the file extension (with dot) and defaults to .pdf&#34;</span>
(<span style="color:#366">unless</span> <span style="color:#033">ext</span> (<span style="color:#366">setq</span> <span style="color:#033">ext</span> <span style="color:#c30">&#34;.pdf&#34;</span>))
(<span style="color:#c0f">concat</span> (<span style="color:#c0f">file-name-as-directory</span> <span style="color:#033">alex/ledger-receipt-folder</span>)
(<span style="color:#c0f">file-name-as-directory</span> (<span style="color:#c0f">format-time-string</span> <span style="color:#c30">&#34;%Y&#34;</span> <span style="color:#033">date</span>))
(<span style="color:#c0f">file-name-as-directory</span> (<span style="color:#c0f">format-time-string</span> <span style="color:#c30">&#34;%m&#34;</span> <span style="color:#033">date</span>))
<span style="color:#033">hash</span>
<span style="color:#033">ext</span>))
(<span style="color:#366">defun</span> <span style="color:#033">alex/ledger-attach-receipt</span> ()
<span style="color:#c30">&#34;Prompt for a receipt file, calculate its hash and move the file to
</span><span style="color:#c30">alex/ledger-receipt-folder, renaming it to its hash. Inserts the new file name
</span><span style="color:#c30">as a comment to the transaction.&#34;</span>
(<span style="color:#366">interactive</span>)
(<span style="color:#366">let*</span> ((<span style="color:#033">fname</span> (<span style="color:#033">read-file-name</span> <span style="color:#c30">&#34;Receipt File Name:&#34;</span>))
(<span style="color:#033">fhash</span> (<span style="color:#366">with-temp-buffer</span>
(<span style="color:#c0f">insert-file-contents</span> <span style="color:#033">fname</span>)
(<span style="color:#c0f">secure-hash</span> <span style="color:#fc3">&#39;sha1</span> (<span style="color:#c0f">current-buffer</span>))))
(<span style="color:#033">xdate</span> (<span style="color:#033">alex/ledger-get-xact-date</span>))
(<span style="color:#033">newpath</span> (<span style="color:#033">alex/ledger-construct-receipt-path</span> <span style="color:#033">xdate</span> <span style="color:#033">fhash</span> (<span style="color:#033">file-name-extension</span> <span style="color:#033">fname</span> <span style="color:#360">t</span>))))
(<span style="color:#033">mkdir</span> (<span style="color:#c0f">file-name-directory</span> <span style="color:#033">newpath</span>) <span style="color:#360">t</span>)
(<span style="color:#c0f">copy-file</span> <span style="color:#033">fname</span> <span style="color:#033">newpath</span>)
(<span style="color:#366">save-excursion</span>
(<span style="color:#033">ledger-navigate-beginning-of-xact</span>)
(<span style="color:#c0f">end-of-line</span>)
(<span style="color:#c0f">insert</span> <span style="color:#c30">&#34;\n; Receipt: &#34;</span> <span style="color:#033">fhash</span> (<span style="color:#033">file-name-extension</span> <span style="color:#033">fname</span> <span style="color:#360">t</span>))
(<span style="color:#033">indent-line-to</span> <span style="color:#033">ledger-post-account-alignment-column</span>))))
(<span style="color:#366">defun</span> <span style="color:#033">alex/ledger-open-attached-receipt</span> ()
<span style="color:#c30">&#34;Open the receipt file specified by the Receipt tag in a new buffer.&#34;</span>
(<span style="color:#366">interactive</span>)
(<span style="color:#366">save-excursion</span>
(<span style="color:#033">ledger-navigate-beginning-of-xact</span>)
(<span style="color:#366">let*</span> ((<span style="color:#033">xact-date</span> (<span style="color:#033">alex/ledger-get-xact-date</span>))
(<span style="color:#033">xact-end</span> (<span style="color:#366">save-excursion</span> (<span style="color:#033">ledger-navigate-end-of-xact</span>)))
(<span style="color:#033">receipt-pos</span> (<span style="color:#c0f">re-search-forward</span> <span style="color:#c30">&#34;; Receipt: \\(.*\\)&#34;</span> <span style="color:#033">xact-end</span> <span style="color:#360">t</span> <span style="color:#360">nil</span>))
(<span style="color:#033">receipt-hash-fname</span> (<span style="color:#033">match-string</span> <span style="color:#f60">1</span>)))
(<span style="color:#366">when</span> (<span style="color:#033">not</span> <span style="color:#033">receipt-pos</span>) (<span style="color:#c00;font-weight:bold">error</span> <span style="color:#c30">&#34;No receipt found for current transaction&#34;</span>))
(<span style="color:#033">find-file</span> (<span style="color:#033">alex/ledger-construct-receipt-path</span> <span style="color:#033">xact-date</span>
(<span style="color:#033">file-name-base</span> <span style="color:#033">receipt-hash-fname</span>)
(<span style="color:#033">file-name-extension</span> <span style="color:#033">receipt-hash-fname</span> <span style="color:#360">t</span>))))))</code></pre></div>
<p>With evil-leader, I&rsquo;ve bound the attach and open functions to <code>SPC-i</code> and
<code>SPC-I</code> respectively. Combined with git, I&rsquo;ve found these functions work nicely
for sorting scans of receipts.</p>
<div class="footnotes">
<hr />
<ol>
<li id="fn:sorting">With the default receipt folder, files get copied to <code>~/finance/receipts/$YEAR/$MONTH</code>.
<a class="footnote-return" href="#fnref:sorting"><sup>[return]</sup></a></li>
</ol>
</div>Using Ledger With an Encrypted Journalhttps://alexj.org/10/encrypted-ledger-journals/
Thu, 15 Oct 2015 17:00:00 -0600alex@alexj.org (Alex Jackson)https://alexj.org/10/encrypted-ledger-journals/I&rsquo;m a pretty big fan of Ledger, a command line accounting system based on the double entry bookkeeping system. One of its strengths lies in the fact that the journal file that contains your transactions is a plain text file. This makes it super easy to sync the journal using your favourite file syncing service. Of course, before putting the journal file on a remote server, you&rsquo;ll probably want to encrypt it. Ledger program doesn&rsquo;t support encrypted journal files but, using GPG and a shell alias, you can get the vast majority of Ledger&rsquo;s functionality to work with an encrypted journal.
<p>I&rsquo;m a pretty big fan of <a href="http://ledger-cli.org">Ledger</a>, a command line
accounting system based on the double entry bookkeeping system. One of
its strengths lies in the fact that the journal file that contains
your transactions is a plain text file. This makes it super easy to
sync the journal using your favourite file syncing service. Of course,
before putting the journal file on a remote server, you&rsquo;ll probably
want to encrypt it. Ledger program doesn&rsquo;t support encrypted journal
files but, using <a href="https://gnupg.org">GPG</a> and a shell alias, you can get
the vast majority of Ledger&rsquo;s functionality to work with an encrypted
journal.</p>
<p></p>
<p>To read the encrypted journal, I use a simple shell alias to pipe the
output of <code>gpg</code> into <code>ledger</code>, telling it to read from <code>stdin</code>. For
the fish shell, the alias I use is:</p>
<div class="highlight"><pre style="background-color:#f0f3f3;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-sh" data-lang="sh"><span style="color:#366">alias</span> eledger <span style="color:#c30">&#34;gpg --batch -d -q </span><span style="color:#033">$LEDGER_FILE</span><span style="color:#c30"> | ledger -f - &#34;</span></code></pre></div>
<p>Adjust this for your shell of choice. Here I&rsquo;ve assumed you&rsquo;ve defined
the <code>$LEDGER_FILE</code> env variable, which Ledger uses by default. I&rsquo;m
also running <code>gpg</code> in batch mode, which suppresses most of its
output. Remove the <code>--batch</code> flag if you&rsquo;d rather see this output (it
won&rsquo;t get piped into Ledger).</p>
<p>Use this alias like you&rsquo;d use the <code>ledger</code> command. Any commands or
arguments get added to the end of the alias and passed on to
ledger. The majority of Ledger&rsquo;s commands will work using this
method. Only commands that rely on the journal&rsquo;s path will fail.</p>
<h2 id="editing">Editing</h2>
<p>If you edit your Ledger journal in Emacs then good news, Emacs will
decrypt the journal file automatically and encrypt it when you
save. Unfortunately, if you use <code>ledger-mode</code>, not all of the built in
commands will function correctly. In particular, reports won&rsquo;t work
since these are generated by running the <code>ledger</code> command. This is
<em>probably</em> easy to fix but I haven&rsquo;t tried yet.</p>Spotijack 0.6 Releasedhttps://alexj.org/07/spotijack-0.6-released/
Fri, 24 Jul 2015 23:00:00 +0000alex@alexj.org (Alex Jackson)https://alexj.org/07/spotijack-0.6-released/After sitting on the project for a few months, I&rsquo;ve just released the next version of Spotijack on GitHub, as well as the application&rsquo;s source code. This is the first public version of Spotijack because I&rsquo;ve spent a while contemplating whether the project is OK to release.
Spotijack is a utility for the Mac that automates the process of recording music playing in Spotify with Audio Hijack Pro. Whenever the song changes in Spotify, Spotijack tells Audio Hijack Pro to split the recording and update the new recording&rsquo;s metadata. Obviously the program enables piracy which I do not support, and this is why I&rsquo;ve sat on it for so long.
<p>After sitting on the project for a few months, I&rsquo;ve just released the
next version of Spotijack on <a href="https://github.com/alexjohnj/spotijack/releases">GitHub</a>, as well as the
application&rsquo;s <a href="https://github.com/alexjohnj/spotijack">source code</a>. This is the first public
version of Spotijack because I&rsquo;ve spent a while contemplating whether
the project is OK to release.</p>
<p>Spotijack is a utility for the Mac that automates the process of
recording music playing in Spotify with Audio Hijack Pro. Whenever the
song changes in Spotify, Spotijack tells Audio Hijack Pro to split the
recording and update the new recording&rsquo;s metadata. Obviously the
program enables piracy which I do not support, and this is why I&rsquo;ve
sat on it for so long.</p>
<p></p>
<p>I wrote the first version of Spotijack back in December of 2011. At
this point it was a simple AppleScript with no user interface and a
lot of bugs. After that I didn&rsquo;t touch the project for another two
years, largely because I didn&rsquo;t use it. In 2013, looking for a new
side project, I started working on Spotijack again. I ported the
application to Cocoa-AppleScript (a horrible experience) and gave it a
proper user interface. In 2014, I then rewrote the application in
Objective-C using the ScriptingBridge framework (a mostly non-horrible
experience). Ditching AppleScript made the project much more fun to
work on. As a result, I started adding new features and fixing bugs
just for fun. I started to treat it like a proper project and wanted
to make the code public.</p>
<p>I&rsquo;m aware that the application&rsquo;s only real use is for music piracy
but, it&rsquo;s a fairly inefficient way of pirating music. I don&rsquo;t think
anybody will actually use Spotijack because there are far more
efficient ways to get music. So, I don&rsquo;t think I&rsquo;m doing much harm by
releasing Spotijack and treating it as a little side project.</p>Always Switch Sockets off Before Plugging inhttps://alexj.org/01/always-switch-sockets-off-before-plugging-in/
Tue, 20 Jan 2015 09:00:00 +0000alex@alexj.org (Alex Jackson)https://alexj.org/01/always-switch-sockets-off-before-plugging-in/Oh, and make sure your stuff is on a surge protector.
Normally I&rsquo;m a stickler when it comes to electrical safety, probably because my Granddad was an electrician and taught me about it. The other night though, in a lapse of consciousness, I plugged my laptop&rsquo;s charger into a power strip that was still switched on at the mains. Or, should I say, started to plug in the charger because as the plug went in, the air between it and the power strip ignited in a decent explosion.
<p>Oh, and make sure your stuff is on a surge protector.</p>
<p>Normally I&rsquo;m a stickler when it comes to electrical safety, probably because my
Granddad was an electrician and taught me about it. The other night though, in
a lapse of consciousness, I plugged my laptop&rsquo;s charger into a power strip that
was still switched on at the mains. Or, should I say, started to plug in the
charger because as the plug went in, the air between it and the power strip
ignited in a decent explosion.</p>
<p></p>
<p>The boom was loud enough to leave a ringing in my ears and it sent out a
perceptible air wave from the socket too. Fortunately the power strip doubled
as a surge protector and it did its job in protecting the desktop computer and
monitor that were also plugged in at the time. The damage to the laptop
charger&rsquo;s plug was pretty interesting though. Aside from being charred, the
neutral pin has deformed slightly as has the live pin, although to a lesser
extent. The ground pin looks perfectly fine.</p>
<!--<div class="full-width-image-wrap">
<img src="https://alexj.org/images/posts/always-switch-sockets-off-before-plugging-in/plug-960px.jpeg" alt="The damaged plug"/>
</div>-->
<div class="full-width-image-wrap">
<picture>
<source srcset="https://alexj.org/images/posts/always-switch-sockets-off-before-plugging-in/plug-960px.webp" type="image/webp">
<source srcset="https://alexj.org/images/posts/always-switch-sockets-off-before-plugging-in/plug-960px.jpeg" type="image/jpeg">
<img src="https://alexj.org/images/posts/always-switch-sockets-off-before-plugging-in/plug-960px.jpeg"/>
</picture>
</div>
<p>Amazingly, the laptop&rsquo;s power brick still works but I haven&rsquo;t tested&mdash;and
don&rsquo;t want to test&mdash;the actual plug. Thanks to the surge protector, the only
costs were for a new fuse and a new power cable but I&rsquo;d hate to think what
would&rsquo;ve happened without the surge protector. Lesson learnt though, always
switch sockets off before plugging in.</p>julius 0.2.0 Releasedhttps://alexj.org/09/julius-0.2.0-released/
Tue, 09 Sep 2014 14:02:51 +0100alex@alexj.org (Alex Jackson)https://alexj.org/09/julius-0.2.0-released/Besides the project page, I haven&rsquo;t written about julius on this blog before so here&rsquo;s a quick overview. julius is a stupidly simple command line tool for encrypting and decrypting text using the Caesar Cipher. It&rsquo;s designed to play nicely with Unix redirections so you can use it to easily encrypt/decrypt the output of commands.
<p>Besides the <a href="https://alexj.org/projects/julius/">project page</a>, I haven&rsquo;t written about julius on this blog before so here&rsquo;s a quick overview. julius is a stupidly simple command line tool for encrypting and decrypting text using the Caesar Cipher. It&rsquo;s designed to play nicely with Unix redirections so you can use it to easily encrypt/decrypt the output of commands.</p>
<p></p>
<p>Everyone knows that the Caesar cipher is unbelievably weak which is why nobody in their right mind uses it for anything serious. Version 0.2.0 of julius highlights this weakness by adding the <code>brute</code> subcommand. Using this command, julius will try every possible key for an encrypted message and output the plaintext. Because there&rsquo;s only 25 possible keys, this takes next to no time to run even on very modest hardware.</p>
<p>As an example, here&rsquo;s some benchmarks performed on a Raspberry Pi Model B+ running ArchLinux:</p>
<table>
<thead>
<tr>
<th align="center">Text to Brute-force</th>
<th align="center">Text Size (Bytes)</th>
<th align="center">Time Taken (ms)</th>
</tr>
</thead>
<tbody>
<tr>
<td align="center">&ldquo;Hello, world!&rdquo;</td>
<td align="center">14</td>
<td align="center">4.18</td>
</tr>
<tr>
<td align="center"><a href="https://github.com/alexjohnj/julius/blob/master/julius.go">julius sourcecode</a></td>
<td align="center">6007</td>
<td align="center">56.42</td>
</tr>
<tr>
<td align="center"><a href="http://www.gutenberg.org/cache/epub/11/pg11.txt">Alice in Wonderland</a></td>
<td align="center">167518</td>
<td align="center">1080.00</td>
</tr>
</tbody>
</table>
<p>On more powerful hardware (like, say, a MacBook Air), it takes julius no time at all to brute force a message.</p>
<p>You can download 0.2.0 today from the <a href="https://github.com/alexjohnj/julius/releases/tag/v0.2.0">GitHub releases</a> page. There&rsquo;s builds available for 64 bit versions of OS X, Linux and Windows as well as an ARM build for Linux.</p>New Design, New Tools, New Everythinghttps://alexj.org/09/new-design-new-tools-new-everything/
Mon, 01 Sep 2014 21:43:00 +0100alex@alexj.org (Alex Jackson)https://alexj.org/09/new-design-new-tools-new-everything/I&rsquo;ve spent the past week working on a new design for this site which should be live right now. The site wasn&rsquo;t in desperate need for a redesign to begin with but I wanted to try out some new tools and figured a redesign was the best way to do it.
<p>I&rsquo;ve spent the past week working on a new design for this site which <em>should</em> be live right now. The site wasn&rsquo;t in desperate need for a redesign to begin with but I wanted to try out some new tools and figured a redesign was the best way to do it.</p>
<p></p>
<p>The new design is &ldquo;inspired&rdquo; by Google&rsquo;s <a href="http://www.google.com/design/">Material Design UI</a>. I&rsquo;ve sprinkled plenty of shadows and animations throughout the site to give it a sense of depth and fluidity. If you get chance, check out one of the <a href="https://alexj.org/projects/">projects</a> with screenshots. The screenshot gallery is built with vanilla JavaScript and all the animations are done with CSS 2D transforms so they run at 60FPS even on low end devices.</p>
<h2 id="hugo">Hugo</h2>
<p>While the new design is interesting and all, the really interesting things with this redesign are the new tools being used. First up, the site is no longer built with <a href="jekyllrb.com">Jekyll</a> instead using <a href="http://hugo.spf13.com">Hugo</a>. Hugo is a relatively new static site generator that is written in Go&mdash;one of my favourite programming languages. The biggest advantage Hugo has over Jekyll is its speed. It&rsquo;s crazy fast compared to Jekyll and I <em>love</em> this. The site builds nearly instantly which is great for development when combined with <a href="http://livereload.com/">LiveReload</a>, which, may I add, comes built into Hugo.</p>
<p>Hugo also offers a more flexible way of organising content than Jekyll. Jekyll pretty much assumes you&rsquo;re working with content for a blog while Hugo assumes that the way you lay out your source content is how you want your site to be. This is awesome and really makes me want to move <a href="https://alexj.org/projects/geographyas/">Geography AS Notes</a> over to Hugo so I can stop doing some weird organisation techniques with the content.</p>
<p>Unfortunately, Hugo is still young and is missing a few features that Jekyll has. This hasn&rsquo;t been much of a problem with this site but it is stopping me from moving Geography AS Notes over to it. One very simple feature that is missing is the ability to get the next/previous piece of content <em>of a certain type</em>. Hugo currently provides the <code>{{ .Next }}</code> and <code>{{ .Prev }}</code> template variables for the next/previous piece of content but they ignore the type of the content (for example mixing blog posts with project pages) and there&rsquo;s no way to specify the sorting that determines what the next/previous content is.</p>
<p>Other issues I ran into include a lack of plugin support (Hugo has &ldquo;shortcodes&rdquo; which are similar to Jekyll&rsquo;s custom liquid filters but can&rsquo;t run external commands), a lack of an asset pipeline and a pretty bare bones <code>{{ .Summary }}</code> variable for generating post summaries. The generated summaries are processed by Markdown but the resulting HTML is stripped leaving a blob of plaintext.</p>
<p>Despite these shortcomings, I still love Hugo. It&rsquo;s fast, it&rsquo;s stable and it has, in my opinion, a superior way of organising content. I&rsquo;ve been watching the project on GitHub for the past couple of weeks and it&rsquo;s very active so I have a lot of hope for the future of this project. I&rsquo;ll definitely be using Hugo for new projects going forwards.</p>
<h2 id="gulp-js">Gulp.js</h2>
<p>Another new tool I got to play around with was <a href="http://gulpjs.com/">gulp.js</a>. Gulp is a task runner written in JavaScript that proved to be super useful in working around Hugo&rsquo;s lack of an asset pipeline. Initially I didn&rsquo;t want to use Gulp and instead wanted to use Make as a task runner, my main reason being the Node.js dependency. Ten minutes of trying to figure out Make&rsquo;s syntax though and I gave Gulp a go.</p>
<p>I&rsquo;m pretty happy with the result. Despite being (almost) illiterate when it comes to JavaScipt<sup class="footnote-ref" id="fnref:1"><a rel="footnote" href="#fn:1">1</a></sup>, writing tasks in a Gulpfile wasn&rsquo;t too hard. The biggest challenge was wrapping my head around the concurrency system Gulp uses. By default tasks are run concurrently so it&rsquo;s important to specify task dependencies to make sure things run in the right order. After rewriting my Gulpfile a few times the concurrency issues were fixed and things seemed to just work.</p>
<p>Gulp and Hugo seem to work quite well together. Using Gulp I can recompile CoffeeScript and Sass files when they change. This, in turn, makes Hugo regenerate the site (did I mention it does this quickly?) and then the site automatically reloads in the browser. Brilliant.</p>
<h2 id="autoprefixer">Autoprefixer</h2>
<p><a href="https://github.com/postcss/autoprefixer">Autoprefixer</a> is a useful little Node.js utility that automatically adds vendor prefixes to experimental CSS properties. It works nicely with gulp.js and helped make my Sass files cleaner. It also made development a little faster since I didn&rsquo;t have to spend time looking up which properties require vendor prefixes and which don&rsquo;t. Autoprefixer makes life easier, there&rsquo;s not much else to say about it.</p>
<h2 id="open-source">Open Source</h2>
<p>Because this site is built using Hugo and because Hugo is still quite a young project, I&rsquo;ve decided to put the source for the site <a href="https://github.com/alexjohnj/alexjohnj">up on GitHub</a>. Previously I kept it in a private repository but I think it&rsquo;s for the greater good to make the source publicly available as a potential learning resource for people new to Hugo. Just a small point, the repository was private in the past and I may have been a bit neglectful when it came to commit messages. Don&rsquo;t judge.</p>
<div class="footnotes">
<hr />
<ol>
<li id="fn:1">I can read and write JavaScript it&rsquo;s just I don&rsquo;t do it often enough to remember the syntax and when I do write it, I prefer to use CoffeeScript.
<a class="footnote-return" href="#fnref:1"><sup>[return]</sup></a></li>
</ol>
</div>Restoring the Network Manager Applet After Upgrading to Lubuntu 14.04https://alexj.org/04/restoring-the-network-manager-applet-after-upgrading-lubuntu/
Sat, 19 Apr 2014 22:30:00 +0000alex@alexj.org (Alex Jackson)https://alexj.org/04/restoring-the-network-manager-applet-after-upgrading-lubuntu/It seems there&rsquo;s a bug when upgrading Lubuntu to version 14.04 that causes the network manager applet to disappear from the system tray. I&rsquo;ve experienced the problem on two separate installations so I&rsquo;m going to guess this is a widespread problem.
The fix is easy. Just open a terminal session and run this command:
echo &#34;nm-applet&#34; &gt;&gt; ~/.config/lxsession/Lubuntu/autostart All the command does is add nm-applet to your LXDE autostart file. If you logout and log back in, the network manager applet should be running.
<p>It seems there&rsquo;s a bug when upgrading Lubuntu to version 14.04 that causes the network manager applet to disappear from the system tray. I&rsquo;ve experienced the problem on two separate installations so I&rsquo;m going to guess this is a widespread problem.</p>
<p>The fix is easy. Just open a terminal session and run this command:</p>
<div class="highlight"><pre style="background-color:#f0f3f3;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash"><span style="color:#366">echo</span> <span style="color:#c30">&#34;nm-applet&#34;</span> &gt;&gt; ~/.config/lxsession/Lubuntu/autostart</code></pre></div>
<p>All the command does is add <code>nm-applet</code> to your LXDE autostart file. If you logout and log back in, the network manager applet should be running.</p>
<p></p>Some .sexy New TLDshttps://alexj.org/03/some-sexy-new-tlds/
Wed, 12 Mar 2014 21:45:00 +0000alex@alexj.org (Alex Jackson)https://alexj.org/03/some-sexy-new-tlds/Today I became the proud owner of alexj.sexy following in the footsteps of people like Myke Hurley of myke.sexy. This is possibly the best $25 I&rsquo;ve ever spent.
Joking aside, I couldn&rsquo;t help but notice how stupid some of the new TLDs are. A sliver do allow for some creative and memorable domains but for the most part they&rsquo;re pretty useless. Take, for example, the .guru TLD. How many times in the past year have you referred to someone as a guru? I&rsquo;d guess it&rsquo;s a pretty small number.
I&rsquo;m probably getting cranky over nothing here. Nowadays people don&rsquo;t access a website via its domain name anyway so the new TLDs will likely be of little importance. Still, I find it funny to think that a board of people at ICANN looked at TLDs like .sexy or .cool and thought they were good.
<p>Today I became the proud owner of <a href="http://alexj.sexy">alexj.sexy</a> following in the footsteps of people like Myke Hurley of <a href="http://myke.sexy">myke.sexy</a>. This is possibly the best $25 I&rsquo;ve ever spent.</p>
<p>Joking aside, I couldn&rsquo;t help but notice how stupid some of the new TLDs are. A sliver do allow for some creative and memorable domains but for the most part they&rsquo;re pretty useless. Take, for example, the <code>.guru</code> TLD. How many times in the past year have you referred to someone as a guru? I&rsquo;d guess it&rsquo;s a pretty small number.</p>
<p>I&rsquo;m probably getting cranky over nothing here. Nowadays people don&rsquo;t access a website via its domain name anyway so the new TLDs will likely be of little importance. Still, I find it funny to think that a board of people at ICANN looked at TLDs like <code>.sexy</code> or <code>.cool</code> and thought they were good.</p>
<p></p>Nginx—Surprisingly Easyhttps://alexj.org/02/nginx-surprisingly-easy/
Mon, 03 Feb 2014 00:15:00 +0000alex@alexj.org (Alex Jackson)https://alexj.org/02/nginx-surprisingly-easy/Out of curiosity I spent my Sunday afternoon moving this blog from Amazon S3 to a DigitalOcean VPS (spoiler, that&rsquo;s a referral link). I didn&rsquo;t have a solid reason to do this&mdash;it&rsquo;s both more expensive and more effort&mdash;aside from to learn. I&rsquo;ve never set up a web server from scratch before let alone owned a VPS. I kind of felt I needed one so I could earn some geek cred.
<p>Out of curiosity I spent my Sunday afternoon moving this blog from Amazon S3 to a <a href="https://www.digitalocean.com/?refcode=755d29c48c8c">DigitalOcean</a> VPS (spoiler, that&rsquo;s a referral link). I didn&rsquo;t have a solid reason to do this&mdash;it&rsquo;s both more expensive and more effort&mdash;aside from to learn. I&rsquo;ve never set up a web server from scratch before let alone owned a VPS. I kind of felt I needed one so I could earn some geek cred.</p>
<p></p>
<p>I&rsquo;m running Ubuntu 12.04 LTS on the VPS since Ubuntu&rsquo;s the Linux distribution I have the most experience with<sup class="footnote-ref" id="fnref:1"><a rel="footnote" href="#fn:1">1</a></sup>. Nginx is acting as the web server and seems to be fast. It&rsquo;s not like I have anything to compare it with though. The VPS is DigitalOcean&rsquo;s cheapest droplet&mdash;512 MB of RAM and a 20 GB SSD.</p>
<p>Given my lack of experience with web servers, I was expecting Nginx to be a pain to set up. Surprisingly, it wasn&rsquo;t. Within 30 minutes I had a test page up and within an hour I was serving a mirror of this site from a subdomain of this site. Granted, this is a purely static site, so I didn&rsquo;t have to set up the full LEMP stack.</p>
<p>I won&rsquo;t go into detail about how I set up the VPS but I&rsquo;ll share a few resources I found. DigitalOcean&rsquo;s support website has some <a href="https://www.digitalocean.com/community">good documentation</a> on setting up a Linux VPS. There&rsquo;s also a tutorial on <a href="https://www.digitalocean.com/community/articles/how-to-install-linux-nginx-mysql-php-lemp-stack-on-ubuntu-12-04">setting up a LEMP stack</a> but I&rsquo;m not a fan of it. The tutorial uses the outdated nginx package provided in the Ubuntu repositories. It needs updating with info on getting the latest version of Nginx.</p>
<p>A very useful resource I found for learning about Nginx was <a href="http://blog.martinfjordvald.com">Martin Fjordvald&rsquo;s blog</a>. He&rsquo;s written several useful and interesting articles especially <a href="http://blog.martinfjordvald.com/2010/07/nginx-primer/">&ldquo;Nginx Configuration Primer&rdquo;</a>. He&rsquo;s also <a href="http://blog.martinfjordvald.com/2013/05/my-new-nginx-book-instant-nginx-starter/">written a short book</a> that goes into a bit more detail. It&rsquo;s a quick read and definitely worth the ~£6.00 if you&rsquo;re new to Nginx.</p>
<h2 id="advantages">Advantages</h2>
<p>More than anything this was a learning exercise but there were a few benefits.</p>
<p>The biggest advantage is native support for root domain names. AWS doesn&rsquo;t support them unless you use their <a href="http://aws.amazon.com/route53/">Route 53</a> service. As a result, I had to use a 3^rd party service to redirect the root domain to the www <code>cname</code> record. This added an extra 200&ndash;300 ms to the DNS look up if somebody used the naked domain. It was a noticeable difference in performance. Now, the homepage loads in ~300 ms regardless of which domain you use.</p>
<p>Another advantage is the extra control I get. With S3, supporting features like gzip compression was an all or nothing choice. If a browser didn&rsquo;t support gzip&mdash;an admittedly rare occurrence&mdash;it&rsquo;d receive nothing but garbled data. With Nginx though I can enable the <code>gzip_static</code> directive and support these browsers.</p>
<p>Going forwards I&rsquo;m probably going to serve <a href="http://geographyas.info">Geography AS Notes</a> from the same DigitalOcean droplet since GitHub pages offers even less control than Amazon S3. I don&rsquo;t see any reason why I can&rsquo;t serve it from the same droplet since this website is such a low volume site, it will have a negligible performance impact. If need be I can get a better DigitalOcean droplet but since Geography AS Notes is strictly not for profit and advertisement free I&rsquo;d have to find some way to subsidise the cost.</p>
<div class="footnotes">
<hr />
<ol>
<li id="fn:1">I&rsquo;ve been running and maintaining Ubuntu on my Grandmother&rsquo;s computer since 8.04. She uses my old MacBook now but had no problems with Ubuntu when she used it.
<a class="footnote-return" href="#fnref:1"><sup>[return]</sup></a></li>
</ol>
</div>Redesigning Geography AS Noteshttps://alexj.org/01/redesigning-geography-as-notes/
Wed, 08 Jan 2014 21:45:00 +0000alex@alexj.org (Alex Jackson)https://alexj.org/01/redesigning-geography-as-notes/Just under a month ago, I wrote about which projects I&rsquo;d be focusing my time on in the coming year. The main takeaway from the post was that Geography AS Notes was going to get some love. Well, here&rsquo;s my first packet of love1, a redesign.
<p>Just under a month ago, I <a href="https://alexj.org/12/project-updates/">wrote about</a> which projects I&rsquo;d be
focusing my time on in the coming year. The main takeaway from the post was
that <a href="https://alexj.org/projects/geographyas/">Geography AS Notes</a> was going to get some love. Well,
here&rsquo;s my first packet of love<sup class="footnote-ref" id="fnref:1"><a rel="footnote" href="#fn:1">1</a></sup>, a redesign.</p>
<p></p>
<p>It&rsquo;s been nearly two years since I last refreshed <em>Geography AS Notes&rsquo;</em> design
and in that time its grown boring and stale. The website&rsquo;s design has never
been eye catching&mdash;one frequent piece of feedback I get is that the site is
boring to look at&mdash;but for the past two years I&rsquo;ve taken the function over
form approach. This needed to change.</p>
<p>If a site is boring to look at, the reader is more likely to perceive the
content as boring which isn&rsquo;t good if you want them to study using it.
Furthermore, I&rsquo;ve realised that Helvetica (or Arial on Windows) ins&rsquo;t a good
body font and my choice of font was hurting the legibility of the site, a
problem that grew worse with the length of articles.</p>
<p>For the redesign, I wanted to make something that not only looked half decent
but was comfortable to read on a multitude of devices. In addition, I wanted to
simplify the site&rsquo;s markup and make use of the new HTML5 semantic elements to
improve accessibility, something which is very important when you&rsquo;re dealing
with people&rsquo;s education. Finally, I wanted to make it easier for people to find
content on the site by implementing site search. These were the four main
objectives when redesigning the website.</p>
<p>The first objective I worked on was improving the HTML semantics. This didn&rsquo;t
take too long and drastically simplified the site&rsquo;s markup. I found a fantastic
<a href="http://mystrd.at/modern-clean-css-sticky-footer/">new method</a> for writing CSS sticky footers. By using it I
was able to eliminate lots of un-semantic wrapper styles and layout my pages
with just the <code>&lt;header&gt;</code>, <code>&lt;article&gt;</code> and <code>&lt;footer&gt;</code> elements. The new CSS
sticky footer doesn&rsquo;t work in IE &lt;= 7 but <em>nobody</em> uses that anymore.</p>
<p>Speaking of IE, I raised my minimum target from IE 7 to 8<sup class="footnote-ref" id="fnref:2"><a rel="footnote" href="#fn:2">2</a></sup>. I was surprised
by how painless it was developing for IE 8. All I needed to do was drop in
<a href="https://code.google.com/p/html5shiv/">html5shiv.js</a> and there were no further problems. I&rsquo;ve
actually had more problems with IE 9/10/11 and their funky way of resizing
<code>&lt;img&gt;</code> elements with SVG content (which I still haven&rsquo;t fixed).</p>
<p>With the site&rsquo;s structure modernised, I started working on how the site looks.
I opted for a dark colour scheme with splashes of orange. I think it looks good
and it&rsquo;s much better than the old design. Article headers receive more emphasis
than they used to while the site&rsquo;s header is less dominant to focus on the
content. The new design is more fluid than the old one, relying less on media
queries and making extensive use of % dimensions. This kept the SCSS clean.</p>
<p>I made some significant changes to the homepage. Previously, the homepage used
a set of expanding divs that contained the site&rsquo;s content. It looked sort of
cool but didn&rsquo;t work well on small screens and content was often truncated
since I couldn&rsquo;t use <code>height:auto</code> on the divs and have CSS3 transitions work.
In the new design, a (pseudo) segmented control is used to control the visible
topic. This works better on mobiles and doesn&rsquo;t have any problems with
truncated content as I&rsquo;m only toggling the div&rsquo;s (well, <code>&lt;section&gt;</code> now)
<code>visibility</code> and <code>display</code> properties.</p>
<p>The next objective to strike off was legibility. I played around with a few
font combinations from Google Fonts and ended up combining
<a href="https://www.google.com/fonts/specimen/Arvo">Arvo</a> and <a href="http://www.google.com/fonts/specimen/Raleway">Raleway</a>. Arvo&mdash;a slab-serif
font&mdash;is used for the site&rsquo;s body while Raleway&mdash;a sans-serif font&mdash;is used
for headers. I like the combination, they look nice together and, most
importantly, they&rsquo;re highly readable.</p>
<p>The final objective was search. Most people arrive at <em>Geography AS Notes</em>
using Google but once they&rsquo;re on the site, there&rsquo;s no further search
functionality. Since the site&rsquo;s Jekyll powered, implementing search has a few
challenges. Mainly, it needs to be handled client-side. I <a href="https://github.com/alexjohnj/geographyas/tree/super-experimental-search">toyed
with</a> writing a search engine back in January last year. It
worked&mdash;surprisingly efficiently may I add&mdash;but it needed <em>a lot</em> of work and
I never got around to finishing it.</p>
<p>I tried again to implement client-side site search, this time using
<a href="http://lunrjs.com">lunr.js</a> so I didn&rsquo;t have to handle the actual searching. Lunr.js is
simple to set up but, in my limited testing, it proved too slow at indexing
full text content for every page. It was unreasonable of me to expect it to
handle such a large index but it was worth a shot.</p>
<p>Ultimately, I offloaded site search to a third party service. I tried
<a href="http://tapirgo.com">Tapir</a> but the service seems to have shut down<sup class="footnote-ref" id="fnref:3"><a rel="footnote" href="#fn:3">3</a></sup>. I ended up using
DuckDuckGo which offers some limited customisation of the search results. It&rsquo;s
a compromise though&mdash;I&rsquo;d much rather have results on my website.</p>
<p>The final design ended up looking like this:</p>
<p><picture>
<source srcset="https://alexj.org/images/posts/redesigning-geography-as-notes/geography-as-new.webp" type="image/webp">
<source srcset="https://alexj.org/images/posts/redesigning-geography-as-notes/geography-as-new.png" type="image/png">
<img class="shadow" src="https://alexj.org/images/posts/redesigning-geography-as-notes/geography-as-new.png" alt="Screenshot of the new design">
</picture></p>
<p><picture>
<source srcset="https://alexj.org/images/posts/redesigning-geography-as-notes/geography-as-new-article.webp" type="image/webp">
<source srcset="https://alexj.org/images/posts/redesigning-geography-as-notes/geography-as-new-article.png" type="image/png">
<img class="shadow" src="https://alexj.org/images/posts/redesigning-geography-as-notes/geography-as-new-article.png" alt="Screenshot of an article with the new design.">
</picture></p>
<p>For reference, the old design:</p>
<p><picture>
<source srcset="https://alexj.org/images/posts/redesigning-geography-as-notes/geography-as-old.webp" type="image/webp">
<source srcset="https://alexj.org/images/posts/redesigning-geography-as-notes/geography-as-old.png" type="image/png">
<img class="shadow" src="https://alexj.org/images/posts/redesigning-geography-as-notes/geography-as-old.png" alt="Screenshot of the old design">
</picture></p>
<p><picture>
<source srcset="https://alexj.org/images/posts/redesigning-geography-as-notes/geography-as-old-article.webp" type="image/webp">
<source srcset="https://alexj.org/images/posts/redesigning-geography-as-notes/geography-as-old-article.png" type="image/png">
<img class="shadow" src="https://alexj.org/images/posts/redesigning-geography-as-notes/geography-as-old-article.png" alt="Screenshot of an article with the old design.">
</picture></p>
<p>I made a few smaller changes while working on the redesign. All the topics now
have their own page which can be linked to. In addition, I&rsquo;ve made it more
obvious that people can edit existing articles and create new ones. All
articles have an edit link in their footer and I&rsquo;ve <a href="http://geographyas.info/pages/contributing/">written
about</a> other ways people can contribute.</p>
<p>This redesign is just the first in what I hope is a string of updates to
<em>Geography AS Notes</em> that will be coming throughout the year. If you have any
suggestions for the website, let me know via the <a href="https://github.com/alexjohnj/geographyas/">GitHub
repository</a>.</p>
<div class="footnotes">
<hr />
<ol>
<li id="fn:1">It&rsquo;s quantum love, coming in discrete packets.
<a class="footnote-return" href="#fnref:1"><sup>[return]</sup></a></li>
<li id="fn:2">I&rsquo;d like to raise it higher than this but a lot of schools&mdash;where the website&rsquo;s most commonly accessed from&mdash;still use IE 8.
<a class="footnote-return" href="#fnref:2"><sup>[return]</sup></a></li>
<li id="fn:3">I never received an email with my private API key and received no response from the API with the public key when I tried to use it.
<a class="footnote-return" href="#fnref:3"><sup>[return]</sup></a></li>
</ol>
</div>Project Updateshttps://alexj.org/12/project-updates/
Wed, 11 Dec 2013 01:22:00 +0000alex@alexj.org (Alex Jackson)https://alexj.org/12/project-updates/This is a boring updated on the status of several of my projects. If you don&rsquo;t care about them then just give this post a miss. There&rsquo;ll be a new post in a couple of months which may be more interesting.
<p>This is a boring updated on the status of several of my projects. If you don&rsquo;t care about them then just give this post a miss. There&rsquo;ll be a new post in a couple of months which may be more interesting.</p>
<p></p>
<p>My situation&rsquo;s changed a lot in the past couple of months. I&rsquo;m now at university, living away from my parents, studying what I want to study with some great people. It&rsquo;s pretty awesome. It&rsquo;s also a lot of work which is why I&rsquo;m changing what projects I&rsquo;m focusing on in my spare time.</p>
<h2 id="simplecode">SimpleCode</h2>
<p><strong>SimpleCode is dead</strong>. The website&rsquo;s been inactive for some time now<sup class="footnote-ref" id="fnref:1"><a rel="footnote" href="#fn:1">1</a></sup> and, on December 4<sup>th</sup> 2013, I let the domain name expire. I&rsquo;ve been waiting to kill this project and I&rsquo;m glad that it&rsquo;s finally gone. Looking back on the programming tutorials I wrote when I was a less experienced programmer I feel sorry for anybody who tried to learn from them. There&rsquo;s so much incorrect or poorly explained information, it&rsquo;s horrible. I feel only a small bit of sadness killing this projects as it was the first website that I actively maintained and the first domain name I ever owned.</p>
<h2 id="symsteam-projects-symsteam"><a href="https://alexj.org/projects/symsteam/">SymSteam</a></h2>
<p><strong>SymSteam is on an indefinite hiatus</strong>. I love SymSteam. It was the first Mac application I worked on where I actually understood most of what I was doing. I didn&rsquo;t need to refer to Stack Overflow<sup class="footnote-ref" id="fnref:2"><a rel="footnote" href="#fn:2">2</a></sup> every other line of code and I was actively trying to follow best practices rather than doing my own thing. It was also my first useful application. SimpleCalc was useless, there are thousands of calculators far more powerful than it but SymSteam, as far as I can tell, is unique.</p>
<p>Work on beta 3 of SymSteam started in April 2013 and the most recent commit was in the tail end of June. Since then, the project&rsquo;s stalled. Ever since building a dedicated computer for gaming, I&rsquo;ve failed to find the motivation to work on SymSteam and it&rsquo;s for this reason that I&rsquo;m officially putting it on hold. I&rsquo;m not calling the project dead because one day I may find the motivation to start working on it again but for now, it just isn&rsquo;t there.</p>
<h2 id="appcastr-projects-appcastr"><a href="https://alexj.org/projects/appcastr/">Appcastr</a></h2>
<p><strong>It&rsquo;s dead</strong>. Appcastr&rsquo;s a funny project. I enjoyed making it despite the constant headaches autolayout gave me but for some reason, I completely lost interest in it. It&rsquo;s annoying because I still have ideas for features to add but I don&rsquo;t want to set aside the time to work on them when there&rsquo;s other things I can be doing.</p>
<p>The project page for Appcastr has, for almost a year, said that it&rsquo;s not dead and that version 0.2 will be released some day. That&rsquo;s not happening. If you want to try out version 0.2, compile it from the 0.2 branch in the <a href="https://github.com/alexjohnj/appcastr">git repository</a>. Otherwise, you can <a href="https://github.com/downloads/alexjohnj/appcastr/Appcastr-0.1.1.zip">download</a> a &lsquo;stable&rsquo; and usable build of version 0.1.1.</p>
<h2 id="geography-as-notes-projects-geographyas"><a href="https://alexj.org/projects/geographyas/">Geography AS Notes</a></h2>
<p><strong>It&rsquo;s alive!</strong>. Work on Geography AS Notes has been all over the place this year. At the start of the year, I rewrote the rivers topic over the space of three months, replacing the old content that was essentially notes with researched prose<sup class="footnote-ref" id="fnref:3"><a rel="footnote" href="#fn:3">3</a></sup>. After the rewrite though, I haven&rsquo;t done much but manage the technical side of the website. In the coming months, I&rsquo;m going to start focusing on the website&rsquo;s content again.</p>
<p>Currently, I&rsquo;m converting diagrams to the SVG format so that they look good at all resolutions. I&rsquo;m also adding more information to several of the diagrams to make them more useful. After this, there will be some significant content updates to the coasts and population change topics. The latter topic is in desperate need of a rewrite so I&rsquo;ll try to prioritise this. After that, I will look into adding some new content. I&rsquo;d like to write something about volcanoes &amp; plate tectonics so I think that&rsquo;ll probably be what&rsquo;s coming next.</p>
<h2 id="a-prototype">A Prototype</h2>
<p>Although my main focus for the coming months is going to be my degree and Geography AS Notes, I recently started prototyping an application that I may or may not develop further. I don&rsquo;t want to reveal too much about it as it&rsquo;s something that I&rsquo;m considering making for profit but let&rsquo;s just say it&rsquo;d be my first proper attempt at iOS &amp; graphics programming<sup class="footnote-ref" id="fnref:4"><a rel="footnote" href="#fn:4">4</a></sup> and it&rsquo;d be related to my degree&hellip;</p>
<div class="footnotes">
<hr />
<ol>
<li id="fn:1">I&rsquo;ve had a 4,000 word draft for a post sitting uncommitted in the git repository for nearly 18 months.
<a class="footnote-return" href="#fnref:1"><sup>[return]</sup></a></li>
<li id="fn:2">OK, I did ask <a href="http://stackoverflow.com/questions/11811119/cocoa-application-crashing-when-launched-on-login">one question</a> on SO when I couldn&rsquo;t figure out why SymSteam was crashing when started on login but I ended up solving that my self any way.
<a class="footnote-return" href="#fnref:2"><sup>[return]</sup></a></li>
<li id="fn:3">The feedback on the rewrite&rsquo;s been great by the way. Thanks to everyone who&rsquo;s emailed me with comments and suggestions. It&rsquo;s really nice.
<a class="footnote-return" href="#fnref:3"><sup>[return]</sup></a></li>
<li id="fn:4">It isn&rsquo;t a game.
<a class="footnote-return" href="#fnref:4"><sup>[return]</sup></a></li>
</ol>
</div>Review - Tomb Raiderhttps://alexj.org/08/review-tomb-raider/
Sat, 10 Aug 2013 23:00:00 +0000alex@alexj.org (Alex Jackson)https://alexj.org/08/review-tomb-raider/The newest entry in the Tomb Raider franchise is a much needed reboot of an ageing series. Published by Square Enix &amp; developed by Crystal Dynamics, the game is a major improvement over past titles in the series with the developers focusing a significant amount of their resources on creating an engaging and enjoyable solo experience.
<p>The newest entry in the Tomb Raider franchise is a much needed reboot of an ageing series. Published by Square Enix &amp; developed by Crystal Dynamics, the game is a major improvement over past titles in the series with the developers focusing a significant amount of their resources on creating an engaging and enjoyable solo experience.</p>
<p></p>
<p>The story of the new Tomb Raider is the real meat of the game. It focuses on the early days of Lara Croft as she is thrown between a rock and a hard place and starts to develop her survival skills. Lara, an archaeologist, and her colleagues/friends are investigating the ancient Yamani Kingdom when their ship is shipwrecked on an island that happens to be Yamani. They pretty quickly find out they&rsquo;re not alone and that there are other survivors on the island who aren&rsquo;t very friendly and kidnap them. Lara escapes and begins trying to rescue her friends while doing some archaeology on the side like any good scholar.</p>
<p>The story is told through a series of cutscenes as well as several of Lara&rsquo;s self narrated diary entries. The cutscenes are interesting to watch and the diary entries are equally interesting to listen to. The voice acting in both is well done with some convincing performances. Overall the story is well told, entertaining and captivating. The development of the characters, more specifically Lara, is very good. By choosing to have parts of the story re-told through Lara&rsquo;s diary entries, it really helps hammer home just how much she is changing as a result of the events and by the end of the game, you&rsquo;ll see a very big difference between the Lara you started with and the Lara you ended with. The other characters don&rsquo;t get as much attention as Lara does but their relationship with Lara is well portrayed and there is a strong sense of emotional attachment between her and some of the characters such as Roth.</p>
<p>Tomb Raider&rsquo;s gameplay is by no means poor or boring but compared to the fantastic story it feels a little second rate. It relies a little too much on quicktime events &amp; button mashing. After the first two hours of gameplay I&rsquo;d already been through nearly a dozen quicktime or button mashing sequences and there were many places in the game where said sequences felt unnecessary. At the same time, there were some places where the sequences did actually work well.</p>
<p>There are essentially two components to Tomb Raider&rsquo;s gameplay, platforming and shooting. There is arguably a third in the form of stealth but that really takes a back seat as while there appears to be the option to stealthily take out entire groups of enemies I think that this is just an illusion as when I tried this I often found myself in the midst of a firefight just moments later. Maybe I was just doing it wrong.</p>
<p>The platforming sections work well. The controls are tight and it&rsquo;s always fairly obvious where you need to go thanks to Lara&rsquo;s “Survival Instincts”. The threat of dying in the platforming sections is next to non existent thanks to some <em>very</em> lenient platforming targets. When I did die it was generally because I hit the wrong key and made Lara go the wrong way not because a certain jump was too hard to make.</p>
<p>The shooting sections tend to be duck and cover affairs. You&rsquo;ll spend most of your time crouching behind a crate, popping out every now and then to shoot some enemies. Sometimes the shooting sections can feel a bit boring as you face wave after wave of enemy, especially later on in the game when the enemies start throwing grenades that force you to keep moving from cover to cover, often not giving you chance to actually return fire. At other points though the combat can be fun and exciting. The level where Lara obtains a grenade launcher is particularly memorable for me. The cover system in Tomb Raider works well enough. Lara automatically takes cover behind objects as you approach them assuming there are enemies nearby. I would have preferred a dedicated button to make her stick to cover but there&rsquo;s nothing up with the cover system that has been implemented.</p>
<p>Shooting sections are occasionally spiced up with the introduction of boss fights. These tend to be heavy gunners dressed in body armour or with shields. They put up a bit more of a fight than the regular enemies but you tend to face them one-on-one which sort of eliminates the threat of them since you can easily dodge their attacks and attack their weak points. Doing so then leads to a joyous quicktime event. Failing said event causes the enemy to get back up but in the time it takes for them to get back up, you can probably hit them in their weak spot again causing them to go back down. It&rsquo;s a bit of a cheap tactic but hey, it works.</p>
<p>The weapons in the game are OK. You get a bow &amp; arrow which, if used correctly, is possibly the most powerful and certainly the most versatile weapon in the game. You also get a pistol, rifle &amp; shotgun which get upgraded to more advanced models as you progress through the story. You&rsquo;ll probably find yourself using your pistol the most often since ammo is so plentiful for it and it tends to kill enemies in one or two shots. Throughout the game there are weapon modifications to collect and also a sort of in game currency called salvage which allows you to purchase said modifications. The modifications improve the base stats of your weapons and a few add some cool new functions to them like firing incendiary rounds from your shotgun.</p>
<p>You also gain experience as you kill enemies in the game which allows you to buy perks. The experience rewarded is based on how badass the kill is. Body shots earn the least, followed by headshots and then executions. Executions can only be performed by purchasing the required perk though. Aside from adding executions, perks also make various improvements to Lara such as reducing fall damage or making her more efficient at looting enemies. The perks are all helpful but there isn&rsquo;t much need to ration your experience points. You earn a significant quantity of experience every time you finish a story mission so you&rsquo;ll never really run short and be unable to afford a perk.</p>
<p>There are many collectibles to be found in this game too ranging from artefacts which have their own L.A. Noir like inspection mode to diary entries from other characters which help flesh out their backstory a little bit. It is actually sort of worth trying to find these collectibles since they add a bit to the story but the placement of them is often illogical. It would seem, for example, that characters that are kidnapped right in front of you and you chase after take the time to leave their diary entries as they are kidnapped.</p>
<p>In addition to hidden items to find there are also hidden tombs to find. Known as Challenge Tombs, these sections are one of my favourite parts of the game aside from the story. Challenge Tombs lack enemies, offering some slightly more relaxing gameplay. Instead, they have one large central puzzle which you must solve in order to access a reward (generally a weapon modification). Some of the puzzles require a few minutes of thought but solving them is fairly satisfying, generally employing a bit of platforming, timing and interacting with the environment. The puzzles are made a bit easier by the use of Lara&rsquo;s “Survival Instincts” which highlight points of interest in the environment. While it&rsquo;s helpful, “Survival Instincts” sort of spoils the challenge of the Challenge Tombs. To get maximum enjoyment out of the challenge tombs, try and ration your usage of the “Survival Instincts”.</p>
<p>The graphical design of the game is truly fantastic. The game looks beautiful with the character models being very detailed and believable. Environments are rich and detailed with some great vistas at various points in the game. The graphics aren&rsquo;t just eye candy though, they do a great job of adding to the atmosphere of the game and making the world as a whole more immersive. Another aspect of the game&rsquo;s design which is fantastic is the sound. As I&rsquo;ve already said, the voice acting in this game is terrific and that&rsquo;s not just for the cutscenes. Enemies in the game have their own conversations which are fun to listen to before killing them. It&rsquo;s really cool to hear how enemies go from questioning how some girl can be running circles around them to genuinely fearing her. Then, when things start to go their way again, they fear her less.</p>
<p>Not only is the voice acting great but the ambient sound is brilliant too. The sound of Lara climbing up a craggy cliff face is incredibly satisfying as is the sound an arrow makes as it lodges itself in an enemy&rsquo;s skull. All the individual grunts and breaths Lara takes sound brilliant and add to the immersion of the game.</p>
<p>As far as reboots go, Tomb Raider is a shining example of how to do one properly. Thanks to some TLC by the developers, Tomb Raider is a fantastic game with an engaging and worthwhile story mixed in with some beautiful set pieces. Yes the gameplay isn&rsquo;t the most original or exciting thing out there but it&rsquo;s easy to forget when the story is this good. I only wish that the developers had laid off the quicktime events and button mashing because it really did make some sections of the game tedious to play. Still, even though these sequences exist throughout the game, they make up a relatively small amount of the actual game and won&rsquo;t detriment from your overall enjoyment of the game. Definitely play this game.</p>
<h2 id="a-side-note-the-multiplayer">A Side Note - The Multiplayer</h2>
<p>It&rsquo;s obvious that Tomb Raider is a game focused on a solo experience but, for better or for worse, the publisher decided that a multiplayer component was also necessary. The multiplayer section of the game was developed by a separate studio and, while it isn&rsquo;t terrible, it&rsquo;s easily forgettable. The multiplayer includes a standard PvP deathmatch mode as well as a scavenger mode where one team must collect supplies while the other tries to stop them and an escort style mode where one team must transport supplies to a specific point on the map.</p>
<p>The multiplayer might occupy you for two or three hours at best but seriously, go into this game expecting a great single player experience, not a multiplayer one.</p>SymSteam Beta 2.1 Releasedhttps://alexj.org/03/symsteam-beta-2-1/
Sun, 31 Mar 2013 12:32:00 +0000alex@alexj.org (Alex Jackson)https://alexj.org/03/symsteam-beta-2-1/This is a very small update for SymSteam that fixes two bugs you probably didn&rsquo;t even know existed. The first, a simple spelling mistake in an error message. The second, a cock-up with pointers that meant that if an error occurred while deleting an old symbolic link an empty error message would be displayed. Not particularly helpful.
<p>This is a <em>very</em> small update for SymSteam that fixes two bugs you probably didn&rsquo;t even know existed. The first, a simple spelling mistake in an error message. The second, a cock-up with pointers that meant that if an error occurred while deleting an old symbolic link an empty error message would be displayed. Not particularly helpful.</p>
<p></p>
<p>Code wise, SymSteam should be easier to translate into other languages because I&rsquo;ve changed all the user interface strings so that they&rsquo;re created using <code>NSLocalizedString()</code> and are stored in a strings file. If anyone wants to go ahead and translate SymSteam into another language please do.</p>
<p>You should be prompted to install the update if you already have SymSteam installed. If not, you can view the changelog and download it from SymSteam&rsquo;s <a href="https://alexj.org/projects/symsteam/">project page</a>. As always, you can find the source code for SymSteam on <a href="https://github.com/alexjohnj/symsteam/">GitHub</a>.</p>S3 Deployment Script Mk 2https://alexj.org/02/s3-deployment-script-mk-2/
Sun, 17 Feb 2013 16:16:00 +0000alex@alexj.org (Alex Jackson)https://alexj.org/02/s3-deployment-script-mk-2/Since releasing the first version of the script I use to deploy this blog to S3, I&rsquo;ve iterated on the script a little bit and made a few changes. Most of the changes in version 2 of the script are syntax changes to the script itself that make it a little bit easier to read1 however there are a couple of functionality changes.
<p>Since releasing the first version of the script I use to deploy this blog to S3, I&rsquo;ve iterated on the script a little bit and made a few changes. Most of the changes in version 2 of the script are syntax changes to the script itself that make it a little bit easier to read<sup class="footnote-ref" id="fnref:1"><a rel="footnote" href="#fn:1">1</a></sup> however there are a couple of functionality changes.</p>
<p></p>
<p>The biggest change is the introduction of command line flags. Three flags have been added, <code>-b</code>, <code>-s</code> and <code>-n</code>. These tell the script to not minify sass files, not compile sass files and to perform a dry run respectively. The first two flags speak for themselves while the third, the dry run flag, simply means that the site will be generated as usual but it won&rsquo;t be deployed to S3. It&rsquo;s akin to running <code>s3cmd sync --dry-run src/ s3://bucket</code>.</p>
<p>Another new ‘feature’ is a countdown that is performed before deploying to S3. After generating the site, the script waits three second before pushing the generated site giving you opportunity to cancel the deployment if you forgot to pass the <code>-n</code> flag or realise that you&rsquo;re (somehow) deploying to the wrong bucket. I&rsquo;m sure some people aren&rsquo;t going to like this but seriously, what&rsquo;s waiting 3 seconds compared to the time it&rsquo;d take to fix the mess after deploying your testing site to the wrong bucket?</p>
<p>A couple of the smaller changes to the script relate to Python 3 compatibility. I&rsquo;ve removed the dependency on PyYaml since it isn&rsquo;t compatible with Python 3 and it was a bit of an overkill to get just one line out of the <code>_config.yml</code> file. In addition, I&rsquo;ve fixed a crash that would occur when gzipping files and the script is run under Python 3.</p>
<p>The updated script is below and you can also find the script as a <a href="https://gist.github.com/alexjohnj/4559517">gist on GitHub</a>.</p>
<div class="highlight"><pre style="background-color:#f0f3f3;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-python" data-lang="python"><span style="color:#09f;font-style:italic">#! /usr/local/bin/python3</span>
<span style="color:#069;font-weight:bold">import</span> <span style="color:#0cf;font-weight:bold">gzip</span>
<span style="color:#069;font-weight:bold">import</span> <span style="color:#0cf;font-weight:bold">os</span>
<span style="color:#069;font-weight:bold">from</span> <span style="color:#0cf;font-weight:bold">subprocess</span> <span style="color:#069;font-weight:bold">import</span> PIPE, check_call, CalledProcessError
<span style="color:#069;font-weight:bold">from</span> <span style="color:#0cf;font-weight:bold">sys</span> <span style="color:#069;font-weight:bold">import</span> <span style="color:#366">exit</span>
<span style="color:#069;font-weight:bold">from</span> <span style="color:#0cf;font-weight:bold">time</span> <span style="color:#069;font-weight:bold">import</span> sleep
<span style="color:#069;font-weight:bold">import</span> <span style="color:#0cf;font-weight:bold">argparse</span>
<span style="color:#069;font-weight:bold">def</span> <span style="color:#c0f">get_s3_bucket_name</span>():
<span style="color:#069;font-weight:bold">with</span> <span style="color:#366">open</span>(<span style="color:#c30"></span><span style="color:#c30">&#34;_config.yml&#34;</span>) <span style="color:#069;font-weight:bold">as</span> f:
<span style="color:#069;font-weight:bold">for</span> line <span style="color:#000;font-weight:bold">in</span> f:
<span style="color:#069;font-weight:bold">if</span> line<span style="color:#555">.</span>split(<span style="color:#c30"></span><span style="color:#c30">&#39;:&#39;</span>)[<span style="color:#f60">0</span>] <span style="color:#555">==</span> <span style="color:#c30"></span><span style="color:#c30">&#34;s3bucket&#34;</span>:
<span style="color:#069;font-weight:bold">return</span> line<span style="color:#555">.</span>strip(<span style="color:#c30"></span><span style="color:#c30">&#34;s3bucket:&#34;</span>)<span style="color:#555">.</span>strip()
<span style="color:#366">exit</span>(<span style="color:#c30"></span><span style="color:#c30">&#34;Error: No bucket was found in the site&#39;s _config.yml file&#34;</span>)
<span style="color:#069;font-weight:bold">def</span> <span style="color:#c0f">compile_sass</span>(input_file, output_file, minify<span style="color:#555">=</span>True):
command <span style="color:#555">=</span> <span style="color:#c30"></span><span style="color:#c30">&#34;sass &#34;</span> <span style="color:#555">+</span> path_to_sass_file <span style="color:#555">+</span> <span style="color:#c30"></span><span style="color:#c30">&#34;:&#34;</span> <span style="color:#555">+</span> sass_compile_path
<span style="color:#069;font-weight:bold">if</span> minify:
command <span style="color:#555">=</span> command <span style="color:#555">+</span> <span style="color:#c30"></span><span style="color:#c30">&#34; --style compressed&#34;</span>
<span style="color:#069;font-weight:bold">try</span>:
check_call(command, shell<span style="color:#555">=</span>True)
<span style="color:#069;font-weight:bold">except</span> CalledProcessError:
<span style="color:#069;font-weight:bold">print</span>(<span style="color:#c30"></span><span style="color:#c30">&#34;Something went wrong compiling sass files.&#34;</span>)
<span style="color:#069;font-weight:bold">def</span> <span style="color:#c0f">generate_site</span>():
<span style="color:#069;font-weight:bold">try</span>:
check_call([<span style="color:#c30"></span><span style="color:#c30">&#34;jekyll&#34;</span>, <span style="color:#c30"></span><span style="color:#c30">&#34;--no-auto&#34;</span>], stdout<span style="color:#555">=</span>PIPE)
<span style="color:#069;font-weight:bold">except</span> CalledProcessError:
<span style="color:#366">exit</span>(<span style="color:#c30"></span><span style="color:#c30">&#34;Something went wrong generating the site with Jekyll.&#34;</span>)
<span style="color:#069;font-weight:bold">def</span> <span style="color:#c0f">gzip_files</span>():
<span style="color:#069;font-weight:bold">for</span> root, dirs, files <span style="color:#000;font-weight:bold">in</span> os<span style="color:#555">.</span>walk(<span style="color:#c30"></span><span style="color:#c30">&#34;_site/&#34;</span>): <span style="color:#09f;font-style:italic"># Traverse the _site/ directory</span>
<span style="color:#069;font-weight:bold">for</span> f <span style="color:#000;font-weight:bold">in</span> files:
<span style="color:#069;font-weight:bold">if</span> os<span style="color:#555">.</span>path<span style="color:#555">.</span>splitext(f)[<span style="color:#f60">1</span>] <span style="color:#000;font-weight:bold">in</span> [<span style="color:#c30"></span><span style="color:#c30">&#39;.html&#39;</span>, <span style="color:#c30"></span><span style="color:#c30">&#39;.css&#39;</span>, <span style="color:#c30"></span><span style="color:#c30">&#39;.js&#39;</span>]:
current_path <span style="color:#555">=</span> os<span style="color:#555">.</span>path<span style="color:#555">.</span>join(root, f)
<span style="color:#069;font-weight:bold">with</span> <span style="color:#366">open</span>(current_path, <span style="color:#c30"></span><span style="color:#c30">&#39;rb&#39;</span>) <span style="color:#069;font-weight:bold">as</span> f_in:
<span style="color:#069;font-weight:bold">with</span> gzip<span style="color:#555">.</span><span style="color:#366">open</span>(current_path <span style="color:#555">+</span> <span style="color:#c30"></span><span style="color:#c30">&#39;.gz&#39;</span>, <span style="color:#c30"></span><span style="color:#c30">&#39;wb&#39;</span>) <span style="color:#069;font-weight:bold">as</span> f_out:
f_out<span style="color:#555">.</span>writelines(f_in)
os<span style="color:#555">.</span>replace(current_path <span style="color:#555">+</span> <span style="color:#c30"></span><span style="color:#c30">&#39;.gz&#39;</span>, current_path)
<span style="color:#069;font-weight:bold">def</span> <span style="color:#c0f">deploy_to_s3_bucket</span>(bucket, dry_run<span style="color:#555">=</span>False):
<span style="color:#069;font-weight:bold">if</span> dry_run:
<span style="color:#069;font-weight:bold">print</span>(<span style="color:#c30"></span><span style="color:#c30">&#34;Doing a dry run!&#34;</span>)
<span style="color:#069;font-weight:bold">try</span>: <span style="color:#09f;font-style:italic"># Upload all uncompressed files</span>
command <span style="color:#555">=</span> <span style="color:#c30"></span><span style="color:#c30">&#34;s3cmd sync -P --exclude &#39;*.html&#39; --exclude &#39;*.js&#39; --exclude &#39;*.css&#39; _site/ &#34;</span> <span style="color:#555">+</span> bucket
<span style="color:#069;font-weight:bold">if</span> dry_run:
command_ls <span style="color:#555">=</span> command<span style="color:#555">.</span>split()
command_ls<span style="color:#555">.</span>insert(<span style="color:#555">-</span><span style="color:#f60">2</span>, <span style="color:#c30"></span><span style="color:#c30">&#34;--dry-run&#34;</span>)
command <span style="color:#555">=</span> <span style="color:#c30"></span><span style="color:#c30">&#39; &#39;</span><span style="color:#555">.</span>join(command_ls)
check_call(command, shell<span style="color:#555">=</span>True, stdout<span style="color:#555">=</span>PIPE)
<span style="color:#069;font-weight:bold">except</span> CalledProcessError:
<span style="color:#366">exit</span>(<span style="color:#c30"></span><span style="color:#c30">&#34;Something went wrong deploying the site to s3.&#34;</span>)
<span style="color:#069;font-weight:bold">try</span>: <span style="color:#09f;font-style:italic"># Upload all compressed files and add an appropriate header</span>
command <span style="color:#555">=</span> <span style="color:#c30"></span><span style="color:#c30">&#34;s3cmd sync -P --add-header=&#39;Content-Encoding: gzip&#39; --exclude &#39;*.*&#39; --include &#39;*.html&#39; --include &#39;*.js&#39; --include &#39;*.css&#39; _site/ &#34;</span> <span style="color:#555">+</span> bucket
<span style="color:#069;font-weight:bold">if</span> dry_run:
command_ls <span style="color:#555">=</span> command<span style="color:#555">.</span>split()
command_ls<span style="color:#555">.</span>insert(<span style="color:#555">-</span><span style="color:#f60">2</span>, <span style="color:#c30"></span><span style="color:#c30">&#34;--dry-run&#34;</span>)
command <span style="color:#555">=</span> <span style="color:#c30"></span><span style="color:#c30">&#39; &#39;</span><span style="color:#555">.</span>join(command_ls)
check_call(command, shell<span style="color:#555">=</span>True, stdout<span style="color:#555">=</span>PIPE)
<span style="color:#069;font-weight:bold">except</span> CalledProcessError:
<span style="color:#366">exit</span>(<span style="color:#c30"></span><span style="color:#c30">&#34;Something went wrong setting the content encoding on the files deployed to s3&#34;</span>)
<span style="color:#069;font-weight:bold">try</span>: <span style="color:#09f;font-style:italic"># Remove any files that have been deleted</span>
command <span style="color:#555">=</span> <span style="color:#c30"></span><span style="color:#c30">&#34;s3cmd sync -P --delete-removed _site/ &#34;</span> <span style="color:#555">+</span> bucket
<span style="color:#069;font-weight:bold">if</span> dry_run:
command_ls <span style="color:#555">=</span> command<span style="color:#555">.</span>split()
command_ls<span style="color:#555">.</span>insert(<span style="color:#555">-</span><span style="color:#f60">2</span>, <span style="color:#c30"></span><span style="color:#c30">&#34;--dry-run&#34;</span>)
command <span style="color:#555">=</span> <span style="color:#c30"></span><span style="color:#c30">&#39; &#39;</span><span style="color:#555">.</span>join(command_ls)
check_call(command, shell<span style="color:#555">=</span>True, stdout<span style="color:#555">=</span>PIPE)
<span style="color:#069;font-weight:bold">except</span> CalledProcessError:
<span style="color:#366">exit</span>(<span style="color:#c30"></span><span style="color:#c30">&#34;Something went wrong removing files from the bucket&#34;</span>)
<span style="color:#069;font-weight:bold">if</span> __name__ <span style="color:#555">==</span> <span style="color:#c30"></span><span style="color:#c30">&#34;__main__&#34;</span>:
parser <span style="color:#555">=</span> argparse<span style="color:#555">.</span>ArgumentParser(description<span style="color:#555">=</span><span style="color:#c30"></span><span style="color:#c30">&#34;Deploy a Jekyll site to Amazon S3&#34;</span>)
parser<span style="color:#555">.</span>add_argument(<span style="color:#c30"></span><span style="color:#c30">&#39;-s&#39;</span>, <span style="color:#c30"></span><span style="color:#c30">&#39;--no-sass&#39;</span>, help<span style="color:#555">=</span><span style="color:#c30"></span><span style="color:#c30">&#34;Don&#39;t compile Sass files&#34;</span>, action<span style="color:#555">=</span><span style="color:#c30"></span><span style="color:#c30">&#39;store_true&#39;</span>)
parser<span style="color:#555">.</span>add_argument(<span style="color:#c30"></span><span style="color:#c30">&#39;-b&#39;</span>, <span style="color:#c30"></span><span style="color:#c30">&#39;--beautiful-sass&#39;</span>, help<span style="color:#555">=</span><span style="color:#c30"></span><span style="color:#c30">&#34;Don&#39;t minify Sass files&#34;</span>, action<span style="color:#555">=</span><span style="color:#c30"></span><span style="color:#c30">&#39;store_false&#39;</span>)
parser<span style="color:#555">.</span>add_argument(<span style="color:#c30"></span><span style="color:#c30">&#39;-n&#39;</span>, <span style="color:#c30"></span><span style="color:#c30">&#39;--dry-run&#39;</span>, help<span style="color:#555">=</span><span style="color:#c30"></span><span style="color:#c30">&#34;Perform a dry run when deploying to S3 (akin to running s3cmd with the --dry-run flag)&#34;</span>, action<span style="color:#555">=</span><span style="color:#c30"></span><span style="color:#c30">&#39;store_true&#39;</span>)
args <span style="color:#555">=</span> parser<span style="color:#555">.</span>parse_args()
path_to_sass_file <span style="color:#555">=</span> <span style="color:#c30"></span><span style="color:#c30">&#34;assets/styles/sass/styles.scss&#34;</span> <span style="color:#09f;font-style:italic"># Change to your path</span>
sass_compile_path <span style="color:#555">=</span> <span style="color:#c30"></span><span style="color:#c30">&#34;assets/styles/css/styles.css&#34;</span> <span style="color:#09f;font-style:italic"># Change to your path</span>
<span style="color:#069;font-weight:bold">if</span> args<span style="color:#555">.</span>no_sass <span style="color:#555">==</span> False:
<span style="color:#069;font-weight:bold">print</span>(<span style="color:#c30"></span><span style="color:#c30">&#34;Compiling Sass Files...&#34;</span>)
compile_sass(path_to_sass_file, sass_compile_path, minify<span style="color:#555">=</span>args<span style="color:#555">.</span>beautiful_sass)
<span style="color:#069;font-weight:bold">print</span>(<span style="color:#c30"></span><span style="color:#c30">&#34;Running Jekyll...&#34;</span>)
generate_site()
<span style="color:#069;font-weight:bold">print</span>(<span style="color:#c30"></span><span style="color:#c30">&#34;Gzipping File...&#34;</span>)
gzip_files()
<span style="color:#069;font-weight:bold">print</span>(<span style="color:#c30"></span><span style="color:#c30">&#34;Getting Bucket Name...&#34;</span>)
bucket_name <span style="color:#555">=</span> get_s3_bucket_name()
<span style="color:#069;font-weight:bold">for</span> i <span style="color:#000;font-weight:bold">in</span> <span style="color:#366">reversed</span>(<span style="color:#366">range</span>(<span style="color:#f60">1</span>,<span style="color:#f60">4</span>)):
<span style="color:#069;font-weight:bold">print</span>(<span style="color:#c30"></span><span style="color:#c30">&#34;</span><span style="color:#c30;font-weight:bold">\r</span><span style="color:#c30">Deploying to {0} in {1}&#34;</span><span style="color:#555">.</span>format(bucket_name, i), end<span style="color:#555">=</span><span style="color:#c30"></span><span style="color:#c30">&#39;&#39;</span>)
sleep(<span style="color:#f60">1</span>)
<span style="color:#069;font-weight:bold">print</span>(<span style="color:#c30"></span><span style="color:#c30">&#34;</span><span style="color:#c30;font-weight:bold">\n</span><span style="color:#c30">Deploying...&#34;</span>)
deploy_to_s3_bucket(bucket_name, dry_run<span style="color:#555">=</span>args<span style="color:#555">.</span>dry_run)
<span style="color:#069;font-weight:bold">print</span>(<span style="color:#c30"></span><span style="color:#c30">&#34;Successfully Deployed Site!&#34;</span>)</code></pre></div><div class="footnotes">
<hr />
<ol>
<li id="fn:1">At the same time, I&rsquo;ve removed half of the comments in the script because most of them were <code>#increment i by one</code> style comments.
<a class="footnote-return" href="#fnref:1"><sup>[return]</sup></a></li>
</ol>
</div>Deploying This Jekyll Site to S3https://alexj.org/01/deploying-this-jekyll-site-to-s3/
Thu, 17 Jan 2013 21:22:00 +0000alex@alexj.org (Alex Jackson)https://alexj.org/01/deploying-this-jekyll-site-to-s3/If you’re the type of person who likes to read the footers of websites (who doesn’t?) you’ll have seen that this website is &ldquo;powered” by Jekyll. In case you haven’t heard, Jekyll is a static site generator that is especially useful for generating static blogs. That is, you run the Jekyll program on a computer, point it at a “source” directory for your website and let it generate a load of HTML files that you can upload to practically any web server that serves files. There’s no need to install PHP or Rails and no need to get a fancy server that can run them. Jekyll is a really awesome utility and that is a terrible description of what it does. You’re better off checking out the GitHub page and seeing how that describes Jekyll.
<p>If you’re the type of person who likes to read the footers of websites (who doesn’t?) you’ll have seen that this website is &ldquo;powered” by Jekyll. In case you haven’t heard, Jekyll is a static site generator that is especially useful for generating static blogs. That is, you run the Jekyll program on a computer, point it at a “source” directory for your website and let it generate a load of HTML files that you can upload to practically any web server that serves files. There’s no need to install PHP or Rails and no need to get a fancy server that can run them. Jekyll is a really awesome utility and that is a terrible description of what it does. You’re better off checking out the <a href="https://github.com/mojombo/jekyll">GitHub page</a> and seeing how that describes Jekyll.</p>
<p></p>
<p>The purpose of this post isn’t to describe what Jekyll is though, it’s to tell you how I deploy this blog that is built with Jekyll to Amazon S3. As a lot of people have written, Amazon S3 is a great place to host small Jekyll blogs. It’s cheap, it’s fast and it has an exceptionally good uptime.</p>
<p>Deploying a Jekyll blog to Amazon S3 is relatively straightforward by using a tool called <a href="http://s3tools.org/s3cmd">s3cmd</a>. s3cmd is a powerful tool that provides a good, command line method for synchronising a directory with a bucket on Amazon S3. While running s3cmd on your generated site will produce a website that’s hosted on S3 (once you’ve set up permissions, DNS etc.) there’s a few things that can be done to optimise your website and make it a bit faster.</p>
<p>You can run gzip to compress all your CSS, HTML &amp; JavaScript files but in order to serve these files, you’ll need to specify the correct content encoding on the compressed files otherwise browsers won’t render your pages. You can also run CSS &amp; JavaScript minification, heck, you can even run HTML minification if you’re desperate to squeeze some speed out of your site. The problem is, running all of these processes requires you to remember a lot of different and complicated commands. Even if you have the memory of a <a href="http://newscientist.com/article/dn2960-sea-lion-scores-top-for-memory.html">sea lion</a>, running all these commands makes deploying your site slow and tedious. I’ve gone ahead and written a script that combines all the commands I need for deploying my website and I thought I would share it with the world.</p>
<p>The script is written in Python because I don’t know any other scripting languages that well. I don’t know Python that well too but it’s the scripting language I’m most confident in. The script does a couple of things. The first thing it does is compile any sass files that need to be compiled and minifies the resulting CSS file. This is (possibly) quite specific to my website since not all Jekyll sites are going to use sass (though I do recommend it) and not all sites are going to compile just one sass file<sup class="footnote-ref" id="fnref:1"><a rel="footnote" href="#fn:1">1</a></sup>. After compiling the sass files, the <code>jekyll</code> command is run, building the site. I’ve added a plugin to Jekyll to minify HTML<sup class="footnote-ref" id="fnref:2"><a rel="footnote" href="#fn:2">2</a></sup> so that gets done when the site is generated rather than by using another package. Once the site is generated, I run the <code>gzip</code> command to compress all HTML, CSS &amp; JavaScript files. Finally, the generated website is uploaded to an Amazon S3 bucket with the gzipped files having the appropriate content header set so that they will be loaded by browsers.</p>
<p>The script basically wraps up five or six commands into one simple <code>python _deploy.py</code> command. Any way, enough waffle. The script:</p>
<div class="highlight"><pre style="background-color:#f0f3f3;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-python" data-lang="python"><span style="color:#09f;font-style:italic">#! /usr/local/bin/python3</span>
<span style="color:#069;font-weight:bold">import</span> <span style="color:#0cf;font-weight:bold">yaml</span>
<span style="color:#069;font-weight:bold">import</span> <span style="color:#0cf;font-weight:bold">gzip</span>
<span style="color:#069;font-weight:bold">import</span> <span style="color:#0cf;font-weight:bold">os</span>
<span style="color:#069;font-weight:bold">from</span> <span style="color:#0cf;font-weight:bold">subprocess</span> <span style="color:#069;font-weight:bold">import</span> PIPE, check_call, CalledProcessError
<span style="color:#069;font-weight:bold">from</span> <span style="color:#0cf;font-weight:bold">sys</span> <span style="color:#069;font-weight:bold">import</span> <span style="color:#366">exit</span>
<span style="color:#069;font-weight:bold">def</span> <span style="color:#c0f">get_s3_bucket_name</span>():
<span style="color:#069;font-weight:bold">try</span>:
<span style="color:#069;font-weight:bold">with</span> <span style="color:#366">open</span>(<span style="color:#c30"></span><span style="color:#c30">&#34;_config.yml&#34;</span>) <span style="color:#069;font-weight:bold">as</span> f:
config_file <span style="color:#555">=</span> yaml<span style="color:#555">.</span>load(f)
<span style="color:#069;font-weight:bold">try</span>:
<span style="color:#069;font-weight:bold">return</span> config_file[<span style="color:#c30"></span><span style="color:#c30">&#34;s3bucket&#34;</span>]
<span style="color:#069;font-weight:bold">except</span> <span style="color:#c00;font-weight:bold">KeyError</span>:
<span style="color:#366">exit</span>(<span style="color:#c30"></span><span style="color:#c30">&#34;Error, no S3 bucket was found in _config.yml.&#34;</span>)
<span style="color:#069;font-weight:bold">except</span> <span style="color:#c00;font-weight:bold">IOError</span> <span style="color:#069;font-weight:bold">as</span> e:
<span style="color:#366">exit</span>(<span style="color:#c30"></span><span style="color:#c30">&#34;I/O error({0}): {1}&#34;</span><span style="color:#555">.</span>format(e<span style="color:#555">.</span>errno, e<span style="color:#555">.</span>strerror))
<span style="color:#069;font-weight:bold">def</span> <span style="color:#c0f">compile_sass</span>(input_file, output_file, minify<span style="color:#555">=</span>True):
command <span style="color:#555">=</span> <span style="color:#c30"></span><span style="color:#c30">&#34;sass &#34;</span> <span style="color:#555">+</span> path_to_sass_file <span style="color:#555">+</span> <span style="color:#c30"></span><span style="color:#c30">&#34;:&#34;</span> <span style="color:#555">+</span> sass_compile_path
<span style="color:#069;font-weight:bold">if</span> minify:
command <span style="color:#555">=</span> command <span style="color:#555">+</span> <span style="color:#c30"></span><span style="color:#c30">&#34; --style compressed&#34;</span>
<span style="color:#069;font-weight:bold">try</span>:
check_call(command, shell<span style="color:#555">=</span>True)
<span style="color:#069;font-weight:bold">except</span> CalledProcessError:
<span style="color:#069;font-weight:bold">print</span>(<span style="color:#c30"></span><span style="color:#c30">&#34;Something went wrong compiling sass files.&#34;</span>)
<span style="color:#069;font-weight:bold">def</span> <span style="color:#c0f">generate_site</span>():
<span style="color:#069;font-weight:bold">try</span>:
check_call([<span style="color:#c30"></span><span style="color:#c30">&#34;jekyll&#34;</span>, <span style="color:#c30"></span><span style="color:#c30">&#34;--no-auto&#34;</span>], stdout<span style="color:#555">=</span>PIPE)
<span style="color:#069;font-weight:bold">except</span> CalledProcessError:
<span style="color:#366">exit</span>(<span style="color:#c30"></span><span style="color:#c30">&#34;Something went wrong generating the site with Jekyll.&#34;</span>)
<span style="color:#069;font-weight:bold">def</span> <span style="color:#c0f">gzip_files</span>():
<span style="color:#069;font-weight:bold">for</span> root, dirs, files <span style="color:#000;font-weight:bold">in</span> os<span style="color:#555">.</span>walk(<span style="color:#c30"></span><span style="color:#c30">&#34;_site/&#34;</span>): <span style="color:#09f;font-style:italic"># Traverse the _site/ directory</span>
<span style="color:#069;font-weight:bold">for</span> f <span style="color:#000;font-weight:bold">in</span> files:
filename, extension <span style="color:#555">=</span> os<span style="color:#555">.</span>path<span style="color:#555">.</span>splitext(f) <span style="color:#09f;font-style:italic"># Get the extension of the current file</span>
<span style="color:#069;font-weight:bold">if</span> extension <span style="color:#555">==</span> <span style="color:#c30"></span><span style="color:#c30">&#34;.html&#34;</span> <span style="color:#000;font-weight:bold">or</span> extension <span style="color:#555">==</span> <span style="color:#c30"></span><span style="color:#c30">&#34;.css&#34;</span> <span style="color:#000;font-weight:bold">or</span> extension <span style="color:#555">==</span> <span style="color:#c30"></span><span style="color:#c30">&#34;.js&#34;</span>: <span style="color:#09f;font-style:italic"># Check to see if it&#39;s a compressible extension</span>
<span style="color:#069;font-weight:bold">with</span> <span style="color:#366">open</span>(os<span style="color:#555">.</span>path<span style="color:#555">.</span>join(root, f), <span style="color:#c30"></span><span style="color:#c30">&#39;r&#39;</span>) <span style="color:#069;font-weight:bold">as</span> f_to_compress: <span style="color:#09f;font-style:italic"># Open the file</span>
<span style="color:#069;font-weight:bold">with</span> gzip<span style="color:#555">.</span><span style="color:#366">open</span>(os<span style="color:#555">.</span>path<span style="color:#555">.</span>join(root, f) <span style="color:#555">+</span> <span style="color:#c30"></span><span style="color:#c30">&#34;.gz&#34;</span>, <span style="color:#c30"></span><span style="color:#c30">&#39;wb&#39;</span>) <span style="color:#069;font-weight:bold">as</span> f_compressed: <span style="color:#09f;font-style:italic"># Open a new gzip file</span>
f_compressed<span style="color:#555">.</span>writelines(f_to_compress) <span style="color:#09f;font-style:italic"># Write the original file into the gzip file</span>
os<span style="color:#555">.</span>remove(os<span style="color:#555">.</span>path<span style="color:#555">.</span>join(root, f)) <span style="color:#09f;font-style:italic"># Remove the original file.</span>
os<span style="color:#555">.</span>rename(os<span style="color:#555">.</span>path<span style="color:#555">.</span>join(root, f) <span style="color:#555">+</span> <span style="color:#c30"></span><span style="color:#c30">&#34;.gz&#34;</span>, os<span style="color:#555">.</span>path<span style="color:#555">.</span>join(root, f)) <span style="color:#09f;font-style:italic"># Rename file to original</span>
<span style="color:#069;font-weight:bold">def</span> <span style="color:#c0f">deploy_to_s3</span>(bucket, dry<span style="color:#555">=</span>False):
<span style="color:#069;font-weight:bold">if</span> dry:
<span style="color:#069;font-weight:bold">print</span>(<span style="color:#c30"></span><span style="color:#c30">&#34;DOING DRY RUN&#34;</span>)
<span style="color:#069;font-weight:bold">try</span>: <span style="color:#09f;font-style:italic"># Upload all uncompressed files</span>
command <span style="color:#555">=</span> <span style="color:#c30"></span><span style="color:#c30">&#34;&#34;</span>
<span style="color:#069;font-weight:bold">if</span> <span style="color:#000;font-weight:bold">not</span> dry:
command <span style="color:#555">=</span> <span style="color:#c30"></span><span style="color:#c30">&#34;s3cmd sync -P --exclude &#39;*.html&#39; --exclude &#39;*.js&#39; --exclude &#39;*.css&#39; _site/ &#34;</span> <span style="color:#555">+</span> bucket
<span style="color:#069;font-weight:bold">else</span>:
command <span style="color:#555">=</span> <span style="color:#c30"></span><span style="color:#c30">&#34;s3cmd sync -P --exclude &#39;*.html&#39; --exclude &#39;*.js&#39; --exclude &#39;*.css&#39; _site/ --dry-run &#34;</span> <span style="color:#555">+</span> bucket
check_call(command, shell<span style="color:#555">=</span>True, stdout<span style="color:#555">=</span>PIPE)
<span style="color:#069;font-weight:bold">except</span> CalledProcessError:
<span style="color:#366">exit</span>(<span style="color:#c30"></span><span style="color:#c30">&#34;Something went wrong deploying the site to s3.&#34;</span>)
<span style="color:#069;font-weight:bold">try</span>: <span style="color:#09f;font-style:italic"># Upload all compressed files and add an appropriate header</span>
command <span style="color:#555">=</span> <span style="color:#c30"></span><span style="color:#c30">&#34;&#34;</span>
<span style="color:#069;font-weight:bold">if</span> <span style="color:#000;font-weight:bold">not</span> dry:
command <span style="color:#555">=</span> <span style="color:#c30"></span><span style="color:#c30">&#34;s3cmd sync -P --add-header=&#39;Content-Encoding: gzip&#39; --exclude &#39;*.*&#39; --include &#39;*.html&#39; --include &#39;*.js&#39; --include &#39;*.css&#39; _site/ &#34;</span> <span style="color:#555">+</span> bucket
<span style="color:#069;font-weight:bold">else</span>:
command <span style="color:#555">=</span> <span style="color:#c30"></span><span style="color:#c30">&#34;s3cmd sync -P --add-header=&#39;Content-Encoding: gzip&#39; --exclude &#39;*.*&#39; --include &#39;*.html&#39; --include &#39;*.js&#39; --include &#39;*.css&#39; --dry-run _site/ &#34;</span> <span style="color:#555">+</span> bucket
check_call(command, shell<span style="color:#555">=</span>True, stdout<span style="color:#555">=</span>PIPE)
<span style="color:#069;font-weight:bold">except</span> CalledProcessError:
<span style="color:#366">exit</span>(<span style="color:#c30"></span><span style="color:#c30">&#34;Something went wrong setting the content encoding on the files deployed to s3&#34;</span>)
<span style="color:#069;font-weight:bold">try</span>:
command <span style="color:#555">=</span> <span style="color:#c30"></span><span style="color:#c30">&#34;&#34;</span>
<span style="color:#069;font-weight:bold">if</span> <span style="color:#000;font-weight:bold">not</span> dry:
command <span style="color:#555">=</span> <span style="color:#c30"></span><span style="color:#c30">&#34;s3cmd sync -P --delete-removed _site/ &#34;</span> <span style="color:#555">+</span> bucket
<span style="color:#069;font-weight:bold">else</span>:
command <span style="color:#555">=</span> <span style="color:#c30"></span><span style="color:#c30">&#34;s3cmd sync -P --delete-removed --dry-run _site/ &#34;</span> <span style="color:#555">+</span> bucket
check_call(command, shell<span style="color:#555">=</span>True, stdout<span style="color:#555">=</span>PIPE)
<span style="color:#069;font-weight:bold">except</span> CalledProcessError:
<span style="color:#366">exit</span>(<span style="color:#c30"></span><span style="color:#c30">&#34;Something went wrong removing files from the bucket&#34;</span>)
<span style="color:#069;font-weight:bold">if</span> __name__ <span style="color:#555">==</span> <span style="color:#c30"></span><span style="color:#c30">&#34;__main__&#34;</span>:
path_to_sass_file <span style="color:#555">=</span> <span style="color:#c30"></span><span style="color:#c30">&#34;assets/styles/sass/styles.scss&#34;</span>
sass_compile_path <span style="color:#555">=</span> <span style="color:#c30"></span><span style="color:#c30">&#34;assets/styles/css/styles.css&#34;</span>
<span style="color:#069;font-weight:bold">print</span>(<span style="color:#c30"></span><span style="color:#c30">&#34;Compiling Sass Files...&#34;</span>)
compile_sass(path_to_sass_file, sass_compile_path, minify<span style="color:#555">=</span>True)
<span style="color:#069;font-weight:bold">print</span>(<span style="color:#c30"></span><span style="color:#c30">&#34;Running Jekyll...&#34;</span>)
generate_site()
<span style="color:#069;font-weight:bold">print</span>(<span style="color:#c30"></span><span style="color:#c30">&#34;Gzipping File...&#34;</span>)
gzip_files()
<span style="color:#069;font-weight:bold">print</span>(<span style="color:#c30"></span><span style="color:#c30">&#34;Getting Bucket Name...&#34;</span>)
bucket_name <span style="color:#555">=</span> get_s3_bucket_name()
<span style="color:#069;font-weight:bold">print</span>(<span style="color:#c30"></span><span style="color:#c30">&#34;Deploying to </span><span style="color:#a00">%s</span><span style="color:#c30">...&#34;</span> <span style="color:#555">%</span> bucket_name)
deploy_to_s3(bucket_name, dry<span style="color:#555">=</span>False)
<span style="color:#069;font-weight:bold">print</span>(<span style="color:#c30"></span><span style="color:#c30">&#34;Successfully Deployed Site!&#34;</span>)</code></pre></div>
<p>There’s a few prerequisites for the script. You’ll need to install the <a href="http://pyyaml.org/wiki/PyYAML">PyYaml</a> library for Python, as well as the <a href="http://sass-lang.com">sass</a> &amp; <a href="http://s3tools.org/s3cmd">s3cmd</a> packages. You’ll also need to modify your website’s <code>_config.yml</code> file so that it has the name of the s3 bucket you want s3cmd to upload your website to:</p>
<div class="highlight"><pre style="background-color:#f0f3f3;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-yaml" data-lang="yaml">s3bucket:<span style="color:#bbb"> </span>s<span style="color:#f60">3</span>://bucketname</code></pre></div>
<p>If you don’t need to compile any sass files, go ahead and comment out<sup class="footnote-ref" id="fnref:3"><a rel="footnote" href="#fn:3">3</a></sup> the 6th line of the <code>__main__</code> method (that’s where it says <code>compile_sass(path_to_sass_file, sass_compile_path, minify=True)</code>). If you do need to compile sass files, modify the <code>path_to_sass_file</code> and <code>sass_compile_path</code> variables so that they point to where the main sass file is and where you want it to be compiled to.</p>
<p>And that’s it. It’s not the most general script in the world but I can see it coming in handy for one or two people who have similar deployment processes to me. If you want to leave some feedback on the script, I’ve created a <a href="https://gist.github.com/4559517">Gist on GitHub</a> for the script with some more extensive documentation.</p>
<div class="footnotes">
<hr />
<ol>
<li id="fn:1">By one sass file I don’t mean I’ve got all of my sass in one file, I just compile lots of different sass files into one CSS file.
<a class="footnote-return" href="#fnref:1"><sup>[return]</sup></a></li>
<li id="fn:2">I know HTML minification isn’t the safest or best way to boost a site’s performance, you don’t need to tell me.
<a class="footnote-return" href="#fnref:2"><sup>[return]</sup></a></li>
<li id="fn:3">To comment a line out in Python just add a <code>#</code> to the start of the line.
<a class="footnote-return" href="#fnref:3"><sup>[return]</sup></a></li>
</ol>
</div>Fixing Slow Wireless Speeds in Ubuntu 12.10https://alexj.org/12/fixing-slow-wiereless-speeds-in-ubuntu/
Mon, 31 Dec 2012 00:00:00 +0000alex@alexj.org (Alex Jackson)https://alexj.org/12/fixing-slow-wiereless-speeds-in-ubuntu/After building a new computer recently I went ahead and installed Ubuntu 12.10 on it alongside Windows. Since the computer doesn&rsquo;t have a wireless card and isn&rsquo;t anywhere near a router, I bought a cheap Wireless USB adapter so that I could connect to my wireless network. I actually bought the adapter several years ago and used it on a computer running Ubuntu 10.04 that was in a similar situation. The adapter I bought was a Belkin F5D8053, the v6 revision. I bought this adapter because I&rsquo;d been told that it had good compatibility with Linux and I remember it working perfectly well in Ubuntu 10.04. I was surprised to find then that when I used the adapter with my new installation of Ubuntu 12.10 it was very unreliable. The adapter worked but after arround five minutes of usage, the connection speed would drop substantially and anything, be it on the internet or my local network, was incredibly slow.
<p>After building a new computer recently I went ahead and installed Ubuntu 12.10 on it alongside Windows. Since the computer doesn&rsquo;t have a wireless card and isn&rsquo;t anywhere near a router, I bought a cheap Wireless USB adapter so that I could connect to my wireless network. I actually bought the adapter several years ago and used it on a computer running Ubuntu 10.04 that was in a similar situation. The adapter I bought was a <a href="http://www.amazon.co.uk/gp/product/B001HO3ZTQ/ref=as_li_ss_tl?ie=UTF8&amp;camp=1634&amp;creative=19450&amp;creativeASIN=B001HO3ZTQ&amp;linkCode=as2&amp;tag=simpl06-21">Belkin F5D8053</a>, the v6 revision. I bought this adapter because I&rsquo;d been told that it had good compatibility with Linux and I remember it working perfectly well in Ubuntu 10.04. I was surprised to find then that when I used the adapter with my new installation of Ubuntu 12.10 it was very unreliable. The adapter worked but after arround five minutes of usage, the connection speed would drop substantially and anything, be it on the internet or my local network, was incredibly slow.</p>
<p></p>
<p>I set about trying to figure out what was up. The first thing I thought was that maybe the driver used for the adapter had been messed up somehow between Ubuntu 10.04 and 12.10. Running <code>lsusb</code> revealed that the adapter used a RTL8191SU chipset by Realtek so I went to Realtek&rsquo;s website and downloaded the source to compile the driver for the adapter. Turns out, something changed in version 3.4 of the Linux Kernel that made compiling these drivers impossible without some minor modifications. Version 3.5 of the Kernel broke even those modifications so compiling new drivers wasn&rsquo;t an option any more.</p>
<p>Some more Googling produced some interesting information. Apparently, there&rsquo;s a <a href="https://bugs.launchpad.net/ubuntu/+source/linux/+bug/621265">bug</a> in network-manager, the package used by Ubuntu to connect to networks, that results in the connection speed slowing down after a few minutes of use. The solution, install an alternate to network-manager and disable network-manager. I went ahead and installed <a href="https://launchpad.net/wicd">wicd</a> and disabled network-manager and so far, in the past 36 hours of use (around 12 hours continuous use over 3 days), I&rsquo;ve had no drop in connection speed. It would seem that the drop in connection speed is due to network-manager which means that people having similar problems with connection speed could find that replacing network-manager will solve their problems.</p>
<h2 id="the-fix">The Fix</h2>
<p>The fix is quite simple, install wicd and disable network-manager. The steps for doing this are outlined below:</p>
<p>First, install the wicd package:</p>
<div class="highlight"><pre style="background-color:#f0f3f3;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">sudo apt-get intall wicd</code></pre></div>
<p>Next, disable network-manager and stop it from starting on startup too:</p>
<div class="highlight"><pre style="background-color:#f0f3f3;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">sudo stop network-manager
sudo mv /etc/init/network-manager.conf /etc/init/network-manager.conf.off</code></pre></div>
<p>Now start the wicd daemon and bring up the GUI tool so you can connect to your wireless network:</p>
<div class="highlight"><pre style="background-color:#f0f3f3;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">sudo /etc/init.d/wicd start
wicd-client</code></pre></div>
<p>And that&rsquo;s it, assuming that network-manager was your problem, you should now have a far more stable wireless connection and wicd should start on login too. If you want to get wicd in Unity&rsquo;s system tray, you&rsquo;ll need to run the following command:</p>
<div class="highlight"><pre style="background-color:#f0f3f3;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">gsettings <span style="color:#366">set</span> com.canonical.Unity.Panel systray-whitelist <span style="color:#c30">&#34;[&#39;wicd&#39;]&#34;</span></code></pre></div>
<p>Then logout and log back in, you should now have a (fairly ugly) tray icon for wicd. There&rsquo;s replacement icons available, just Google for them.</p>
<p>Once you&rsquo;re certain that wicd has solved your problem and you don&rsquo;t need network-manager anymore, you can go ahead and remove nework-manager. First, revert the changes made to network-manager&rsquo;s upstart job and then remove the package:</p>
<div class="highlight"><pre style="background-color:#f0f3f3;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">sudo mv /etc/init/network-manager.conf.off /etc/init/network-manager.conf
sudo apt-get remove --purge network-manager</code></pre></div>
<p>That solved the problem for me. If it does for you, be sure to file a bug report so that this issue hopefully gets fixed in network-manager.</p>SymSteam Beta 2 Releasedhttps://alexj.org/12/symsteam-beta-2-released/
Mon, 31 Dec 2012 00:00:00 +0000alex@alexj.org (Alex Jackson)https://alexj.org/12/symsteam-beta-2-released/It may have taken nearly 9 months but beta 2 of SymSteam is finally available for download. This is a huge update for SymSteam that completely changes how it works and fixes many bugs as a result. SymSteam no longer manages drives based on their names, rather, it relies on the UUID of a drive to determine if the drive is the Steam drive. This makes SymSteam more reliable in situations where you have drives with the same name but it does introduce a new requirement. The drive you&rsquo;re storing your games on must have a UUID which essentially means that the drive must be HFS+ formatted1.
<p>It may have taken nearly 9 months but beta 2 of SymSteam is finally available for download. This is a <em>huge</em> update for SymSteam that completely changes how it works and fixes many bugs as a result. SymSteam no longer manages drives based on their names, rather, it relies on the UUID of a drive to determine if the drive is the Steam drive. This makes SymSteam more reliable in situations where you have drives with the same name but it does introduce a new requirement. The drive you&rsquo;re storing your games on must have a UUID which essentially means that the drive must be HFS+ formatted<sup class="footnote-ref" id="fnref:1"><a rel="footnote" href="#fn:1">1</a></sup>.</p>
<p></p>
<p>In addition to this major change, lots of small changes have also been made that make SymSteam easier to use and more reliable. The error correction performed on your Steam folders when SymSteam is launched is far more reliable now and SymSteam can fix incorrect folder setups in many more cases, reducing the number of situations where SymSteam will fail to work. The setup process has been rewritten to make it much simpler to use and also to make it less likely to fail. The preferences window has been expanded upon too, providing more in-depth options for notifications and an option to start SymSteam on login. Oh, SymSteam finally has an icon too! It&rsquo;s not amazing but it&rsquo;s better than the generic app icon that SymSteam had before the update.</p>
<p>The full changelog for beta 2 can be found <a href="http://alexjohnj.github.com/symsteam/changelog.html">here</a>.</p>
<p>SymSteam now has some fairly extensive documentation available on its new <a href="http://www.alexj.me/projects/symsteam/">project page</a>. The new documentation includes information on setting up SymSteam and some troubleshooting information too. The documentation can be accessed <a href="http://www.alexj.me/projects/symsteam/documentation/">here</a>.</p>
<p>If you already have SymSteam installed then it will prompt you to update (assuming you&rsquo;ve allowed it to). If not, you can download beta 2 of SymSteam <a href="http://www.alexj.me/projects/symsteam/">here</a>.</p>
<div class="footnotes">
<hr />
<ol>
<li id="fn:1">There are other filesystems that assign drives a UUID but I don&rsquo;t think any of these have native support in OS X.
<a class="footnote-return" href="#fnref:1"><sup>[return]</sup></a></li>
</ol>
</div>Recent Projectshttps://alexj.org/06/recent-projects/
Wed, 13 Jun 2012 00:00:00 +0000alex@alexj.org (Alex Jackson)https://alexj.org/06/recent-projects/It would seem that pretty much the only thing I use this blog for is announcements. Guess what&rsquo;s in this post, some more announcements, specifically regarding some new projects that I&rsquo;ve started in the past month (and a bit).
<p>It would seem that pretty much the only thing I use this blog for is announcements. Guess what&rsquo;s in this post, some more announcements, specifically regarding some new projects that I&rsquo;ve started in the past month (and a bit).</p>
<p></p>
<p>Now that I&rsquo;ve got a lot more free time on my hands, I&rsquo;ve managed to start two new Cocoa projects for the Mac, one of which I&rsquo;ve been intending to do for several months. They&rsquo;re both free applications and they&rsquo;re both open source, with the source code being available off of my <a href="https://github.com/alexjohnj">GitHub</a> page. If you were to categorise both of these projects, they&rsquo;d both fall into two categories that are totally new to me in terms of development. One of the projects is a game and another is an utility aimed at developers.</p>
<h2 id="memtester-mac">MemTester ( - Mac)</h2>
<p>MemTester is the game. I&rsquo;ve never made a game before so this was/is quite a fun little project to work on. MemTester is a very simple memory testing game (surprise, surprise) that tests your ability to memorise an increasingly lengthy sequence of numbers, letters or symbols. The game has three difficulties, easy (just numbers), medium (just lowercase letters) &amp; hard (nearly all possible ASCII characters) and has amazing features like a high scores table &amp; fancy animations (/sarcasm). I started working on MemTester as a port of a similar game that a friend of mine made. <a href="http://code.google.com/p/mem-tester">My friend&rsquo;s version</a> was written in Java and was very un-Mac like so I decided to make a native Cocoa port of the game for fun. He wasn&rsquo;t best pleased.</p>
<p>So far, version 1.0 of MemTester has been released and there&rsquo;s been no further development since then (though I do have a couple of things planned). Development for MemTester will be on and off, but you can watch <a href="https://github.com/alexjohnj/memtester-mac">the project</a> on GitHub. You can also download the latest version from <a href="https://github.com/alexjohnj/memtester-mac/downloads">here</a>.</p>
<h2 id="appcastr">Appcastr</h2>
<p>Appcastr is the development tool. It&rsquo;s quite possibly my most ambitious project to date and so far, developing it has been a joy and I&rsquo;ve learnt a lot of new things working on it. Appcastr is a tool for developers who use the Sparkle update system, that&rsquo;s the update system used by 99% of Mac applications that aren&rsquo;t in the Mac App Store, that makes it easier &amp; quicker for developers to create and maintain appcast files by providing a GUI to edit them with. Appcast files are just RSS files with a special <code>&lt;enclosure&gt;</code> element in them that allows them to include information on the latest version of an application and where to get it from. The appcast file is downloaded by the Sparkle update framework and then parsed to see if there&rsquo;s a new version of the application available.</p>
<p>Since appcast files are just XML files, it&rsquo;s not exactly hard to edit the files by hand but it&rsquo;s a lot faster to use a GUI application and I plan on adding a couple of handy features that will make distributing an update significantly faster if the developer chooses to use Appcastr.</p>
<p>I&rsquo;m a bit concerned working on a project like Appcastr. Given that it&rsquo;s aimed at developers, it&rsquo;s much more likely that the source code will be viewed by, and possibly edited by, other developers than my other projects. This means the quality of my code is a lot more important and will probably receive some judgment. Make no mistake, I really want other developers to look at my code and tell me where to improve it. Given that I&rsquo;ve taught myself to program, I&rsquo;m certain that my code is rife with malpractice and things that&rsquo;d probably make more experienced developers cry. I&rsquo;d love to hear some constructive criticism about the quality of my code.</p>
<p>Appcastr version 0.1 was released just yesterday and version 0.1.1 was released this morning. I&rsquo;m going to work diligently on this project so expect frequent updates. You can get the bleeding edge version of Appcastr by visiting the <a href="https://github.com/alexjohnj/appcastr">project&rsquo;s GitHub page</a> and checking for the branch which is the most commits ahead (at the time of writing, version 0.2). Be warned though, things could be broken or buggy in that branch. The &ldquo;master&rdquo; branch will have more stable code and (should) be a representation of the most recent build available off of the project&rsquo;s <a href="https://github.com/alexjohnj/appcastr/downloads">downloads page</a>.</p>
<hr />
<p>So they&rsquo;re the two new projects that I&rsquo;ve launched recently. My third project, <a href="https://github.com/alexjohnj/symsteam">SymSteam</a>, hasn&rsquo;t received much love recently. It&rsquo;s been stuck on beta 1 for a while. To be honest, I&rsquo;ve been using the application day-in-day-out for several months now and haven&rsquo;t noticed any bugs in my usage so I&rsquo;m tempted to make an icon for the application and release it as version 1.0. Laziness FTW!</p>Thoughts on WWDC 2012https://alexj.org/06/thoughts-on-wwdc/
Tue, 12 Jun 2012 00:00:00 +0000alex@alexj.org (Alex Jackson)https://alexj.org/06/thoughts-on-wwdc/Yesterday (June 11th) marked the first day of Apple&rsquo;s famous WWDC event. As per usual, Apple opened the event with the only part of the event that isn&rsquo;t under NDA (and hence the only part that I&rsquo;ve actually been able to see so far), the keynote. The keynote was a blast with lots of new, exciting things announced. Here&rsquo;s my thoughts on a couple of those things that were announced.
<p>Yesterday (June 11th) marked the first day of Apple&rsquo;s famous WWDC event. As per usual, Apple opened the event with the only part of the event that isn&rsquo;t under NDA (and hence the only part that I&rsquo;ve actually been able to see so far), the keynote. The keynote was a blast with lots of new, exciting things announced. Here&rsquo;s my thoughts on a couple of those things that were announced.</p>
<p></p>
<h2 id="updated-macbook-airs-http-www-apple-com-macbookair"><a href="http://www.apple.com/macbookair/">Updated MacBook Airs</a></h2>
<p>The updated MacBook Airs are really nice. They&rsquo;re a lot faster now thanks to both a new generation of Ivy Bridge processors and faster SSD technology. I&rsquo;d really like to get one but I&rsquo;ve just splashed out on a last generation MacBook Air, so can&rsquo;t afford the new generation any time soon. The graphical performance of the new Airs has been improved by “up to 60%” which really excites me. The Airs still have an integrated graphics card but it&rsquo;s an Intel HD 4000 series card, which is a surprisingly beefy integrated card and performs respectably at many modern games. The price of the Airs has been dropped a bit too. Here in the UK, the prices have gone down enough that the low end 13 inch model costs the same as the previous generation low end 11 inch model. Nice.</p>
<p>The MacBook Pros also got an update, just a small bump in specs, nothing too exciting. Apple seems to have deprecated the 17 inch MacBook Pro though which&rsquo;ll annoy about ten people.</p>
<h2 id="macbook-pro-with-retina-display-http-www-apple-com-macbook-pro"><a href="http://www.apple.com/macbook-pro/">MacBook Pro With Retina Display</a></h2>
<p>Wow. Just wow. This thing is awesome. This isn&rsquo;t the 15 inch Air that everybody was hoping for but I think it&rsquo;s better. The new MacBook Pro has a completely redesigned case which is stunning to look at. What&rsquo;s even more stunning to look at though is that new display. It has over 5 million pixels in it. I haven&rsquo;t seen one of these yet but I know from the numbers, that display is gorgeous. The new MacBook Pro has really excited me, it represents the start of a revamp of Apple&rsquo;s line of computers. I envision new designs &amp; retina displays coming to most of Apple&rsquo;s computers throughout the next couple of years.</p>
<h2 id="os-x-mountain-lion-http-www-apple-com-osx"><a href="http://www.apple.com/osx/">OS X Mountain Lion</a></h2>
<p>Mountain Lion was probably my favourite piece of news from the WWDC keynote. True, most of what Apple talked about in the keynote had already been posted on their website but there was still some interesting new features that they announced. The new “Power Nap” feature is pretty neat, allowing you to download updates to your Mac while it&rsquo;s in sleep mode. It&rsquo;ll also keep all of your iCloud stuff in sync while your Mac sleeps which is handy. If Apple includes support for updating your (App Store) applications while in sleep mode too then that&rsquo;d just be fantastic.</p>
<p>The inclusion of speech-to-text processing in Lion too is pretty cool. If the processing is as good as iOS&rsquo;s speech-to-text then I can see this feature actually being really useful for dictating long text documents. Apple says that the dictation works in any text field too, so no need to wait for developers to update their applications. The only saddening part was that there was no mention of a speech API, something which I would love to play around with.</p>
<p>There were a couple of other tidbits in 10.8 that looked interesting. The new version of Safari seems pretty good and I&rsquo;ll probably switch back to it from Chrome when it is released. GPU accelerated scrolling was also mentioned, which would make scrolling a lot smoother in OS X and would help make OS X <em>feel</em> even faster. The fact that Apple seems to have “fixed” full screen mode on external displays is fantastic too. Full screen mode might actually be useful in 10.8 now.</p>
<h2 id="ios-6-http-www-apple-com-ios-ios6"><a href="http://www.apple.com/ios/ios6/">iOS 6</a></h2>
<p>iOS 6 was probably the most disappointing of all the announcements at WWDC this year. There were good aspects to the announcement but overall I felt unsatisfied with the new features that had been announced. Siri was updated with support for getting information on sports &amp; movie, a feature which I doubt will be used much. She also got some new voice commands, a few of which will be useful. She finally gained support for obtaining local business information outside of the US, something which I&rsquo;ve been waiting for since the iPhone 4S launched back in October. There&rsquo;s still no API for Siri though which is really annoying. I like to control my music using Siri (saves getting the phone out of my pocket) but I don&rsquo;t use the built in music app. It would be nice if I could use music voice commands in other apps like Rdio, something which would only be possible with an API.</p>
<p>Unfortunately, there was no UI refresh in iOS 6 which was the main thing I was hoping for. Well, I say there was no UI refresh but really there was a mixture of UI updates which seems to have removed a lot of consistency in the iOS&rsquo;s UI. Different shades of colours have been changed throughout the UI. The status bar, for example, is now a silvery blue instead of grey which is an interesting colour choice. There seems to be a slightly different shade of blue being used in navigation bars too. The new maps app has been given the silver UI treatment. It doesn&rsquo;t look out of place in the OS but it certainly isn&rsquo;t consistent with the rest of the OS&rsquo;s UI. I don&rsquo;t see why Apple would update parts of the UI in one application without updating the rest of the OS. It really doesn&rsquo;t play nice with the consistency of the user interface throughout the operating system.</p>
<p>As expected, Apple updated the maps app and they&rsquo;re now using their own custom mapping service rather than Google Maps. The new maps (as in the actual maps) look a lot nicer and cleaner when compared to Google&rsquo;s and Apple&rsquo;s included some swanky 3D mode in the maps which looks pretty awesome. The new maps application also includes support for turn by turn directions which is pretty neat. I don&rsquo;t have any use for it (yet) though.</p>
<p>There were tons of other new features in iOS 6. The phone application (yeah, I&rsquo;d forgotten about that too) got some nice updates which could come in handy for gracefully rejecting phone calls. There&rsquo;s also a new Passbook application which looks like a virtual wallet for different types of tickets. I think it&rsquo;ll be <em>really</em> awesome but I doubt it&rsquo;s going to get much use outside of the US for a long time which is a crying shame. Such an application could be really useful.</p>
<p>The major disappointment with iOS 6 is its lack of backwards compatibility. Apple&rsquo;s saying the update is compatible with the iPhone 3GS and onwards, the second &amp; third generation iPad &amp; the fourth generation iPod Touch. I don&rsquo;t understand why the 3rd generation iPod Touch or 1st Generation iPad aren&rsquo;t on the list though since they&rsquo;re basically identical to the iPhone 3GS and iPhone 4 respectively in terms of processing power. Maybe I can understand the 1st Generation iPad not making the shortlist, it is quite slow to use with iOS 5 at the moment, but the 3rd generation iPod Touch, that represents a sizeable chunk of the iOS market and it&rsquo;s pretty much the same as the 3GS. Strange.</p>
<p>Overall, this year&rsquo;s WWDC keynote has been very impressive. Lots of new products that are very exciting. I&rsquo;m really looking forward to Mountain Lion (due in July) and I think it&rsquo;s going to be a good all around update to OS X. iOS 6 will be pretty good too though, for me, it&rsquo;s not as exciting as Mountain Lion. The thing I&rsquo;m waiting for now is the release of the actual development sessions from WWDC, they&rsquo;re probably the best part of the whole week for me.</p>SymSteam Beta 1 Releasedhttps://alexj.org/04/symsteam-beta-1-released/
Wed, 11 Apr 2012 00:00:00 +0000alex@alexj.org (Alex Jackson)https://alexj.org/04/symsteam-beta-1-released/Good news! Just the other day, SymSteam, my small pet project, received a pretty major update. In fact, this update is so major, I&rsquo;ve labelled it Beta 1. Pretty much everything to do with SymSteam has changed.
<p>Good news! Just the other day, SymSteam, my small pet project, received a pretty major update. In fact, this update is so major, I&rsquo;ve labelled it Beta 1. Pretty much everything to do with SymSteam has changed.</p>
<p></p>
<p>Beta 1 brings numerous new features and changes to the application. A list of the changes is available on SymSteam&rsquo;s new website <a href="http://alexjohnj.github.com/symsteam/changelog.html">here</a> but in this post I&rsquo;d just like to elaborate on some of the features and the work that&rsquo;s gone into beta 1 of SymSteam.</p>
<p>Development on SymSteam 0.2 began back in February with the simple aim of adding support for Growl notifications and fixing some bugs to make SymSteam more usable. Growl support was added pretty quickly but I had the idea of rewriting the underlying logic of SymSteam which helped to remove a substantial number of bugs. The rewrite took the best part of a day and made SymSteam far easier to use. It simplified the setup procedure and helped make SymSteam less likely to fail in difficult situations. After this rewrite, I rewrote the scanning system for detecting the SteamApps folder. I changed it so that SymSteam performed first a shallow scan (only scanning top level directories) and then it performed a deep scan, should it not find the SteamApps folder when performing the shallow scan. This change in the scanning mechanism helped to significantly reduce the time it took for SymSteam to detect the SteamApps folder when a drive was plugged in, in around 90% of cases.</p>
<p>After making all these changes to the scanning system however, I decided to endulge on another rewrite, completely changing the way SymSteam functions. SymSteam no longer scans all drives that are connected for the SteamApps folder, rather it will resolve the symbolic link you point it to and only scan at that directory, performing a simple check to see if the folder exists at the symbolic link or not. If the correct drive is connected, the folder will exist and SymSteam can update the SteamApps folders so that Steam loads its games off of the external hard drive. If the folder doesn&rsquo;t exist however, then life carries on as normal and nothing changes. This is <em>a lot</em> faster than scanning each drive that is connected and SymSteam can now work in a split second rather than a few seconds.</p>
<p>After this rewrite, I attempted to write a startup method that would run when SymSteam is launched that would attempt to fix any naming problems with the SteamApps folders that may arise when SymSteam is quit without being given the ability to rename the SteamApps folders so that the local folder is active. This error prevention method seems to work with limited success and I&rsquo;ll continue to develop it in future versions to make it more successful.</p>
<p>I decided to update the preferences window in SymSteam too, using the MASPreferences framework to provide a proper preferences window. I wrote about how to use MASPreferences and my experiences with it on SimpleCode <a href="http://simplecode.me/2012/04/08/preferences-window-in-cocoa-maspreferences/">here</a>.</p>
<p>There were several other changes within SymSteam, however I feel that these were the most substantial. Other changes include a vastly simplified setup procedure (which I briefly touched upon when talking about the rewrite), a new tool to help ease the creation of symbolic links and a new autoupdate system too, which will make pushing updates much easier in the future.</p>
<p>SymSteam beta 1 is available now and I&rsquo;ve already got plans for the next version of SymSteam, beta 2. SymSteam now has its own website, so you can get access to SymSteam beta 1 and the source code via <a href="http://alexjohnj.github.com/symsteam">http://alexjohnj.github.com/symsteam</a>.</p>SymSteam 0.1.5 Releasedhttps://alexj.org/02/symsteam-0-1-5-released/
Sat, 18 Feb 2012 00:00:00 +0000alex@alexj.org (Alex Jackson)https://alexj.org/02/symsteam-0-1-5-released/SymSteam, my small project I released just a few weeks ago, received its first major update today. Version 0.1.5 was pushed to the GitHub repo a few hours ago and with it came an important new feature and some bug fixes.
<p>SymSteam, <a href="https://alexj.org/02/symsteam">my small project I released just a few weeks ago</a>, received its first major update today. Version 0.1.5 was pushed to the GitHub repo a few hours ago and with it came an important new feature and some bug fixes.</p>
<p></p>
<p>The most important new feature is a new preferences window which allows you to change the where your symbolic and local SteamApps folders are located. This is pretty handy since, previously, the only way to change these paths was to delete SymSteam&rsquo;s plist file. Under the hood, SymSteam&rsquo;s got a new system for managing connected drives so that it knows what drives are connected and, of those connected drives, which one is actually a Steam drive. This should remove a couple of bugs related to having multiple connected drives. It could, however, introduce some new ones. Watch out. One more thing to note, scanning drives for SteamApps folders should be a little bit faster now. Not massively, but a little bit.</p>
<p>To download the latest version of SymSteam, head over <a href="https://github.com/alexjohnj/SymSteam/downloads">here</a>. If you&rsquo;re interested in the source code, you can check out the code <a href="https://github.com/alexjohnj/SymSteam">here</a>. The code in the <code>master</code> branch should be reasonably in sync with the latest version of SymSteam available to download. Most major new features will get their own branch while they&rsquo;re being developed.</p>
<h2 id="0-2">0.2</h2>
<p>I also started working on version 0.2 today. The plan for version 0.2 is to add support for <a href="http://growl.info/">Growl</a> notifications, improve the error handling logic for missing folders and add the ability to specify a single drive and path to scan for a SteamApps folder, improving performance greatly. So far, basic support for Growl has been added but not tested.</p>
<p>If you want to see and (hopefully) contribute towards the development of the latest build of SymSteam, you can look at the <code>symsteam-2.0</code> branch <a href="https://github.com/alexjohnj/SymSteam/tree/symsteam-2.0">here</a> (I know, that should be <code>symsteam-0.2.0</code> but I wasn&rsquo;t thinking when I named the branch). Be warned, stuff will likely be unstable and broken in that branch.</p>Moving from 1Password To LastPass to 1Password Againhttps://alexj.org/02/1password-to-lastpass-to-1password/
Tue, 14 Feb 2012 00:00:00 +0000alex@alexj.org (Alex Jackson)https://alexj.org/02/1password-to-lastpass-to-1password/In the past few weeks I&rsquo;ve had a bit of an epiphany. I&rsquo;ve become incredibly security and privacy conscious. I&rsquo;ve closed my Facebook account, started moving away from Google and begun using far stronger, unique passwords. In the past, for websites, I&rsquo;ve had one strong password which would be impossible to guess and then used that on every website (except my bank, which doesn&rsquo;t allow special characters in a password). I know, shoot me. That&rsquo;s the worst thing you can do in terms of passwords next to having 123456 as your password. Every website had the same password and email and (normally) username. If you got the password to one website, you had it to all of them. I&rsquo;ve realised this security flaw and over the past couple of weeks, changed all of my passwords so that they are unique to each website and totally unintelligible to humans. 30 characters of random, well, characters. How the hell was I meant to remember them? I used a password manager. In the past, I&rsquo;d been using 1Password to “manage” my passwords. I&rsquo;d really been using 1Password, not because I couldn&rsquo;t remember my passwords, but rather to reduce the number of keystrokes needed when entering a password.
<p>In the past few weeks I&rsquo;ve had a bit of an epiphany. I&rsquo;ve become incredibly security and privacy conscious. I&rsquo;ve closed my Facebook account, started moving away from Google and begun using far stronger, unique passwords. In the past, for websites, I&rsquo;ve had one strong password which would be impossible to guess and then used that on every website (except my bank, which doesn&rsquo;t allow special characters in a password). I know, shoot me. That&rsquo;s the worst thing you can do in terms of passwords next to having 123456 as your password. Every website had the same password and email and (normally) username. If you got the password to one website, you had it to all of them. I&rsquo;ve realised this security flaw and over the past couple of weeks, changed all of my passwords so that they are unique to each website and totally unintelligible to humans. 30 characters of random, well, characters. How the hell was I meant to remember them? I used a password manager. In the past, I&rsquo;d been using <a href="https://agilebits.com/onepassword">1Password</a> to “manage” my passwords. I&rsquo;d really been using 1Password, not because I couldn&rsquo;t remember my passwords, but rather to reduce the number of keystrokes needed when entering a password.</p>
<p></p>
<p>Now that I was using impossible to remember passwords, a password manager was no longer a convenience, it was a necessity. After updating all my passwords in 1Password, everything was fine for a few days. 1Password is an excellent piece of software and is incredibly simple to use. Three days after changing all my passwords though, I hit a roadblock. I was on a public computer and needed to login to a website. Normally I&rsquo;d just use 1Password but this wasn&rsquo;t any computer. a) It didn&rsquo;t have 1Password installed &amp; b) It ran Linux. 1Password doesn&rsquo;t run on Linux. It&rsquo;s Mac &amp; Windows only. I had a problem. To be fair to the 1Password developers, I could actually access my 1Password database from the computer via Dropbox. The 1Password data file includes a small web application that allows you to view your 1Password data from any web browser, without the main application being installed. The problem is, this requires my Dropbox account to have a memorable, and therefore insecure password, something I wasn&rsquo;t comfortable doing. When I was back on my own computer, I started looking into a cross platform solution (since I use non Mac computers a lot) and came across the famous <a href="https://lastpass.com/index.php">LastPass</a>. Reading through the feature list, the free version seemed to cover most of my needs and the incredibly cheap premium version would cover the rest (mobile support). Best of all, LastPass was cross platform, since it is only a web service and browser extension.</p>
<p>I signed up to LastPass and installed its extension to my (at the time) browser of choice, Chrome (now Firefox). I was initially quite impressed. Setup was simple. LastPass offered to import my passwords from 1Password (though this did require me to export the passwords to a plaintext format) and even scanned them to tell me if there were any duplicate passwords or other potential security risks. Functionality wise, LastPass was incredibly impressive. It wasn&rsquo;t anywhere near as aesthetically pleasing as 1Password but it had far more functions. After installing LastPass on my Mac and Linux boxes I carried on as normal, with the intention of replacing 1Password and purchasing a premium subscription to it after a few days. Within a few hours though, I began to become concerned about my security with the service though.</p>
<p>Typically, peoples concern with LastPass&rsquo; security comes from the fact that the service stores all their passwords on a server (for synchronisation). This wasn&rsquo;t my concern as, before signing up, I&rsquo;d done extensive research into the service&rsquo;s security. LastPass&rsquo; password storage is <em>very</em> secure. LastPass can&rsquo;t access your passwords, they can only see the encrypted file. The passwords themselves are only decrypted on your computer. I wasn&rsquo;t concerned about somebody accessing my passwords remotely. I was concerned about someone getting them from my computer.</p>
<p>The LastPass extension works like this. You login to your LastPass account and all of your passwords are synchronised to your computer. When you visit a site, the extension offers to autofill the password for you. If you allow it to, it will continue to do so in the future. 1Password has a similar extension. With 1Password, you visit a site and press a key combination. Up pops a window asking you to unlock your password with a master password. The extension then fills in the username &amp; password and will optionally submit the login for you. When you revisit the website again, you must do the same action. At first glance, 1Password&rsquo;s method of autofilling logins seems to be slow(er), requiring several steps. LastPass is far more simple, automatically filling in the form when you visit a site. You don&rsquo;t need to log back in or unlock your passwords. LastPass just assumes that it&rsquo;s you using the computer and not, say, someone who&rsquo;s just stolen your computer. That&rsquo;s my security concern with LastPass. By default, <strong>you&rsquo;re never logged out of the extension.</strong> That&rsquo;s one hell of a major security flaw. Even worse is the fact that it automatically fills in passwords for you. With 1Password, even if your password vault is still unlocked (it doesn&rsquo;t actually lock until after 5 minutes; you tell it; or some event happens like closing the laptop&rsquo;s lid), you have a small layer of security in terms of a key combination to fill in the password. Your common laptop thief isn&rsquo;t going to know what buttons to press to activate the 1Password extension. With LastPass, they don&rsquo;t need to know any buttons. It&rsquo;ll do it for them.</p>
<p>Again, in the interest of fairness, LastPass does provide two options in its settings menu to</p>
<ol>
<li>Automatically logoff when all browsers are closed for x minutes.</li>
<li>Automatically logoff when idle for x minutes.</li>
</ol>
<p>The option&rsquo;s there but I&rsquo;m extremely concerned by the fact that these two options aren&rsquo;t enabled by default. Enabling these options then throws up an annoying usability problem. When the LastPass extension logs you out automatically and you visit a site, the extension doesn&rsquo;t prompt you to login to autofill the password. This can result in a bit of head scratching as you try and work out why the extension isn&rsquo;t filling in your passwords. 1Password has this problem too, but it&rsquo;s alleviated slightly by the fact that the key combination to autofill passwords becomes a reflex action and so you ultimately end up being prompted for your password anyway.</p>
<p>That&rsquo;s my main problem with the LastPass extension. While this was annoying, it was fixable and so I continued using the service and, ultimately, ended up signing up for the premium service solely for the ability to access my passwords on mobile devices, in my case, an iPhone. This is where the service became sickeningly bad.</p>
<p>A years subscription to LastPass premium cost £7.49 ($12) which, in terms of coffee pay is maybe 3 and a bit coffees? Either way, it&rsquo;s not going to break the bank. I downloaded the iPhone(/iPad) app and went through the setup. As expected, the UI was pretty rough. I&rsquo;d come to expect this, given LastPass&rsquo; track record with the browser extensions. After logging in, you&rsquo;re presented with a list of your sites according to their groups. If you haven&rsquo;t set up any groups, you&rsquo;ll just get a list of sites under a group called “none”. Tapping on a site presents a modal list of options including the ability to copy a password or username to the clipboard. Counter intuitively, the button to cancel the list is at the top, whereas it&rsquo;s normally at the bottom in iOS. This is just one of the many user interface and design flaws in the application. The most frustrating of these flaws is the option (or lack thereof) to logout on close.</p>
<p>The mobile application, like its desktop counterpart, likes to keep you logged in for as long as it can. If you close the app so that it enters the background, you stay logged in until the application is killed full stop. As soon as the application is killed, everything&rsquo;s nice and secure. Digging around in the settings, there&rsquo;s an option called “log out on close”. Logic foretells that enabling this will log you out of the application when you close the application, even if it&rsquo;s still running in the background. Oh no. It does nothing. At all. At least, as far as I can tell it does nothing. The app continues to keep you logged in until you kill the application. This is a <strong>major</strong> security flaw, especially on a mobile device. Having to remember to logout of a mobile application is just stupid, especially one with as sensitive data as this. Mr iThief could happily take my phone and, even if I haven&rsquo;t launched LastPass in a while, it could still be running in the background and Mr iThief could easily get my passwords.</p>
<p>Again, In the interest of fairness, 1Password (Touch) does a similar thing and can stay logged in indefinitely as long as it&rsquo;s running in the background. Whether it does this by default I can&rsquo;t remember but it does provide some fairly extensive options to configure auto locking. Currently, my copy of 1Password requires a pin as soon as it is enters the background, requiring the master password after 5 minutes of inactivity. I think this is pretty secure and works nicely.</p>
<p>Thanks largely to the terrible iOS application (it has so many problems), I&rsquo;ve stopped using LastPass for now and switched back over to 1Password. I&rsquo;ve also sent a message to LastPass asking for a refund, I <em>should</em> get one. It&rsquo;s going to be annoying on my Linux machines trying to use 1Password but, in terms of design and local security, 1Password feels a lot safer since it doesn&rsquo;t leave me logged in for indefinite periods of time. LastPass is an excellent product assuming you only use the browser extensions with automatic log out enabled. Otherwise, despite the excellent security LastPass takes in storing your passwords, it fails miserably at keeping your passwords safe on your devices, especially mobile ones.</p>
<p><strong>Update</strong> Within minutes of writing this post and a few hours of requesting a refund, I&rsquo;ve received an email from LastPass confirming a refund for the premium service. Ultimately, no harm done.</p>
<p><strong>Update 2</strong> The other night (14/02/12), I got two emails from Joe at LastPass in response to the issues I raised in this post. Here&rsquo;s what he had to say:</p>
<h3 id="email-1">Email 1</h3>
<blockquote>
<p>For windows we force you to choose if you want to be logged out or stay logged in, the fact that we don&rsquo;t have this option on OS X / Linux prompting you by default is something we&rsquo;ll rectify.</p>
<p>For iOS, we have the option to logout on close, and to pin prompt if you&rsquo;ve left LastPass logged in the background &ndash; did you miss this in the &lsquo;more&rsquo; menu?</p>
<p>Best,</p>
<p>Joe</p>
</blockquote>
<h3 id="email-2">Email 2</h3>
<blockquote>
<p>I should also mention that you might want to try LastPass Icon -&gt; Preferences -&gt; whatever 1password key combo for fill in next site to get that behavior.</p>
<p>Joe</p>
</blockquote>
<p>Nice to see a response from someone at LastPass! So it would seem I missed a setting in the iOS application. Apparently, enabling pin prompt in LastPass (along with logout on close) will solve my security concern on the iOS app. I didn&rsquo;t realise that both of these settings had to be enabled, the app didn&rsquo;t (but should) point this out. I can&rsquo;t actually verify that this would solve my security concern since I don&rsquo;t have a premium subscription (and hence access to the mobile application) anymore but I trust the guys and girls at LastPass and don&rsquo;t see why they&rsquo;d lie.</p>
<p>I&rsquo;m pleased to see that LastPass are aware of the issue of remaining logged in indefinitely to the browser extension on Mac OS X (and, it would seem, Linux). Judging by the email, the Windows version asks the user if they should remain logged in during setup, which I think is a pretty good implementation as I know it would annoy some users if they where being logged out of the extension all the time.</p>
<p>Finally, in response to using a keyboard combination to fill in site login info, while using a custom keyboard combo is handy, LastPass continues to offer to autofill passwords after enabling the keyboard shortcuts (as expected). After experimenting a bit, I&rsquo;ve found that, in order to get the extra layer of “security through obscurity” that the 1Password extension offers, it&rsquo;s necessary to change a few other preferences. You must also disable the “Automatically Fill Login Information” preference (LastPass Prefs &gt; General) and the “Show Fill Notifications” preference (LastPass Prefs &gt; Notifications). This way, LastPass wont throw up an alert telling you that it can autofill a login form and it wont attempt to automatically fill a login form either. The only way that the form can be filled is by you explicitly telling the extension to do so, hopefully via a slightly obscure shortcut that someone couldn&rsquo;t guess.</p>
<p>In light of this information, I&rsquo;m going to reconsider using LastPass since it really is a fantastic service and cross platform compatibility is <em>so</em> useful to me. It would just seem that LastPass requires some tweaking in order to get its local security to levels which I feel comfortable with.</p>SymSteamhttps://alexj.org/02/symsteam/
Sun, 05 Feb 2012 00:00:00 +0000alex@alexj.org (Alex Jackson)https://alexj.org/02/symsteam/I&rsquo;ve just released a new project on GitHub. It&rsquo;s called SymSteam and it&rsquo;s for anybody who likes to play Steam games on their MacBook Air (or any other Mac for that matter). MacBook Airs are reasonably powerful machines, not gaming machines but with the Intel HD graphics inside of them they can handle many of the games on OS X without too much difficulty. The problem is, games are big and SSDs are small. The baseline MacBook Air only has a 64GB SSD and, while the top of the line model has a 256GB SSD, that still isn’t a lot of space for your games once you’ve got all of your other stuff on there too. The solution to this storage problem that most people use is to put their games on an external hard drive and create a symbolic link to them where Steam would expect to find them. This way, you can play games off of your external hard drive when you’ve got the hard drive with you. And there’s the problem, it’s sort of an all or nothing solution. You can either sacrifice some portability, convenience and speed and have all of your games on an external hard drive or you can have your games on an internal hard drive, just not that many. What if you want to play a quick game of Plants vs Zombies while you’re out but don’t have your hard drive with you? That’s not a huge game, it’d only take up maybe 100MB on your hard drive. That game would be fine on your internal hard drive but if you choose to put all your games on an external hard drive you won’t be able to play it off of your internal drive without doing a bit of messing around with folders. This is where SymSteam comes in.
<p>I&rsquo;ve just released a new project on GitHub. It&rsquo;s called <a href="https://github.com/alexjohnj/symsteam">SymSteam</a> and it&rsquo;s for anybody who likes to play Steam games on their MacBook Air (or any other Mac for that matter). MacBook Airs are reasonably powerful machines, not gaming machines but with the Intel HD graphics inside of them they can handle many of the games on OS X without too much difficulty. The problem is, games are big and SSDs are small. The baseline MacBook Air only has a 64GB SSD and, while the top of the line model has a 256GB SSD, that still isn’t a lot of space for your games once you’ve got all of your other stuff on there too. The solution to this storage problem that most people use is to put their games on an external hard drive and create a symbolic link to them where Steam would expect to find them. This way, you can play games off of your external hard drive when you’ve got the hard drive with you. And there’s the problem, it’s sort of an all or nothing solution. You can either sacrifice some portability, convenience and speed and have all of your games on an external hard drive or you can have your games on an internal hard drive, just not that many. What if you want to play a quick game of Plants vs Zombies while you’re out but don’t have your hard drive with you? That’s not a huge game, it’d only take up maybe 100MB on your hard drive. That game would be fine on your internal hard drive but if you choose to put all your games on an external hard drive you won’t be able to play it off of your internal drive without doing a bit of messing around with folders. This is where SymSteam comes in.</p>
<p></p>
<h2 id="enter-symsteam">Enter SymSteam</h2>
<p>SymSteam runs in the background. It doesn&rsquo;t have a dock icon or a menu bar icon. It doesn&rsquo;t have any windows apart from a setup window. It&rsquo;s not going to get in your way. SymSteam watches for when you plug in a USB storage device. It then scans said device to see if it can find a SteamApps folder. If it doesn&rsquo;t, nothing happens. If it does though, it will configure your Steam folder so that Steam will load games off of the device you just plugged in. Unplug the device and you’re playing games off of your internal hard drive. It’s seamless, when it works.</p>
<p>SymSteam is really immature at the moment. It works, but only just. I&rsquo;m running it on my system because it&rsquo;s handy and I&rsquo;ll continue to work on it for now. Currently, I want to get some sort of preferences window and Growl notifications implemented. There&rsquo;s also a lot of bugs that need fixing.</p>
<p>If you&rsquo;re a developer, or want the latest, cutting edge build, you can get SymSteam from its GitHub repository <a href="https://github.com/alexjohnj/symsteam">here</a>.</p>
<p>If you&rsquo;re just interested in downloading a ready to use, reasonably/partly/just about stable version, get version 0.1 from <a href="https://github.com/alexjohnj/symsteam/downloads">here</a>.</p>