Musings of a Programmer

Rarely-used blog of Dan Harper.

Sapling

February 28, 2024

Sapling is the source code tool used at Meta. It started as extensions of top of Mercurial but now has its own identity as Sapling.

Continue reading.

Working with an external API which returns a string union which may grow over time, I wanted to maintain type-safety in my code. When that API does return an unexpected value, I needed to refine it to null so I can better handle it.

Continue reading.

LEGO This is Fine

March 28, 2023

I recently found legotruman's LEGO Ideas project, This is Fine. It's a LEGO version of the classic This is Fine meme.

It's an awesome idea, and the model looks great, but it's obviously not going to get approved – a LEGO model featuring a dog in a burning building is not going to be approved by LEGO.

But... I wanted it. So I got to reverse-engineering the model from the images on the project page, using the BrickLink Studio app.

Continue reading.

Bitmasks

April 16, 2021

Bitmasks, and the bitwise operators, are something I've known about/can recognise, but had never actually needed to use them. The first time was when using Windows C++ APIs, and I tripped up over myself a few times trying to use it... So, here's what I wish I read at the start.

Continue reading.

Just a quick note as I had to go digging to work out the difference between the use of RCTTextField and RCTTextView in React Native iOS.

RCTTextField is used for single-line inputs. RCTTextView is used for multi-line inputs.

Hopefully this shows up in Google search results for someone else wondering the same thing.

Starting March 6th 2017, I'm joining Facebook as a Front End Engineer in London!

Continue reading.

Quick note on getting IDE completion working within IntelliJ IDEA for an Android Cordova plugin.

Right-click on the following directories and go Mark Directory As > Source Root:

  • plugins/PLUGIN_NAME/src/android
  • platforms/android/CordovaLib/src
  • platforms/android/src

Now your IDE will be able to auto-complete all the Cordova .java source files for you to work against.

hub wraps git to add additional commands like hub pull-request or hub browse to manage your repo on GitHub.

I recently accidentally merged a Pull Request into master instead of develop because hub pull-request made the PR against that, even though develop is the default branch on GitHub.

Turns out the default branch is determined when you clone the repo. In my case, when I originally cloned the branch was master.

To change it:

git remote set-head origin develop

Starting from scratch with a brand-new Raspberry Pi 2 and an external USB hard drive, we'll set up an automated always-on torrent box.

You'll be able to:

  • Access the disk from any computer on the network
  • List TV shows you watch, and new episodes will be downloaded as they become available
  • List Movies you want to watch, at a specified minimum quality, and they'll be downloaded as they become available
  • Instruct the Pi to start downloading any other torrent just by dropping the file into a watched directory
  • Receive notifications on your phone when downloads are ready to watch
  • Stream videos over the network to any DLNA-compatible device
  • Continue to use the Pi to do whatever else you'd like it to :)

Let's get started:

  1. Installing Raspbian
  2. Auto-Mounting USB Drives
  3. Transmission
  4. SickBeard
  5. CouchPotato
  6. MiniDLNA
  7. Samba

The SOLID Origins

September 5, 2014

The thread where it all started to take form, in the Spring of 1995.

https://groups.google.com/d/msg/comp.object/WICPDcXAMG8/yM-33R_tdXcJ

It's one of those things which is pretty cool to look back on!

Project Estimations

August 5, 2014

When somebody watches over your shoulder, asking how much longer it will take; when it's three in the morning and you're patching a server; in short when you are under pressure, then you stop solving problems. Your brain is frantically looking for the quickest thing you can do to make the problem go away. You're not considering the whole matrix of solutions and consequences, of costs and benefits.

Mathias Verraes, The Cost of Estimation

With the introduction of custom iOS keyboards, we can now solve the greatest problem facing Project Managers: deciding just how PRIORITY a task is.

Introducing... PM-Keys!

IMAGE NOT FOUND: /blog-images/RadKeys2.gif
generate-image-sizes.

It needs a lick of paint, but don't worry, that's of PRIORITY PRIORITY URGENT importance :)

This video made the rounds in 2005, showcasing how quickly you can create a blog application in this new web framework: Ruby on Rails.

IMAGE NOT FOUND: /content/images/2014/apr/Screen_Shot_2014_04_08_at_14_30_11.png
generate-image-sizes.

Exhibit A: a real final-year group project for University.

Believe me, I tried to teach them Git; but I just ended up with an inbox of .zip files to merge...

By default, when PHP receives data from MySQL, all data is cast as a string - even integers!

You want the MySQL Native Driver for PHP (mysqlnd).

Now PHP recognises MySQL data types and will cast them appropriately :)

Install on Ubuntu: sudo apt-get install php5-mysqlnd. Install on OS X with Brew: brew install php5-mysqlnd.

Update As Jeffrey points out in the comments, there's a much cleaner way of implementing this functionality (without extensions). I'm still interested in ways to manipulate Blade for producing 'DSLs', however.


In order to break looped output into sections, you may write something like the following in Laravel's Blade templating language:

Continue reading.

TextEdit Notes

March 19, 2014

TextEdit can make a great notepad, except for it prompting to save temporary files when you quit.

I don't need to save the notes anywhere, I'd rather OS X just manage them, restoring them when I relaunch.

In System Preferences > Desktop & Dock, uncheck "Close windows when quitting an application". Now TextEdit will close automatically, without a save prompt. When you next open it, all your unsaved windows will be restored :)

Notes galore.

To run Laravel's queue listener in production, you can use something like:

php artisan --env=production --timeout=240 queue:listen

However this process won't be restarted when the process ends (eg. after a restart). We can use Supervisor to keep this queue listener process active at all times. Below are instructions for Ubuntu 13.04.

Continue reading.

PHP 5.5 introduced a new concept called "Generators". Put simply, these allow an ordinary function to "return" multiple times, using the yield keyword.

The go-to example for this, is re-implementing PHP's built-in range(). For example, if you were to call range(0, 1000000) you'd produce a huge in-memory array of one million items before you can iterate through it:

Using generators, it is possible to instead produce the next value only as it's requested, removing the huge memory hog. An example of range re-implemented as a generator named xrange would be:

Continue reading.

Update: Now the preliminary documentation is out for Laravel 4, it seems there is a simple way to throw 404 errors:

<?php

App::abort(404);

You can then catch this error by registering a missing handler in app/start/global.php:

<?php
App::missing(function($exception) {
    return Response::make(
        View::make('errors/404')
    , 404);
});

However, read on through the original post below for examples on how to register custom Exceptions you can throw to improve your application's flow.

Continue reading.

Those Damn Print Headers

December 9, 2012

Those damn print header/footers that browsers put on every page really ruin your appearance sometimes when you need to create a page which looks great when it's printed. Don't you wish you could just turn them off? Well, you can!

The solution is simple:

@page {
  margin: 0.312in 0.312in 0.322in;
}
@media print {
  html {
    margin: 0.1in;
  }
}

@page is a new selector which targets each individual printed page. Setting a margin: 0; for this would remove all the print margins and your design would go right to the end of the page.

But of course you still want a margin. So I've worked out out the maximum margin values you can set before the browser pops in its ugly head.

Continue reading.

Today we're going to create a small realtime web application with FuelPHP on the server, Backbone.js on the client and using the Pusher API for the realtime aspects. The application we'll be building is a modern take on my classic "Shoutbox" PHP demo application I originally wrote six years ago for Nettuts+, and covered again not long after in Ruby on Rails.

This time, it's a Backbone.js take on the application and we're bringing into the year 2012 with live syncing between users without refreshing the page!

View the full article on Tuts+ Premium.

Markdown is a shockingly simple markup language that allows you to write, using an easy-to-read, easy-to-write, plain text format. This format can then, in seconds, be converted into another markup language, such as HTML!

If you're not familiar with it, let me teach you about it today!

View the full article on Nettuts+.

A Look at Popcorn.js

November 11, 2011

Today we're going to take a look at Popcorn.JS, a library from Mozilla which makes it very easy to manipulate a webpage based on the current position of a video. This allows you to create rich "hypermedia" experiences around your video content.

View the full article on Nettuts+.

Nearly two years ago, we published a round-up of the greatest Ruby and Rails learning resources available. Since then, big things have happended in the glorious world of Ruby. Rails 3 brought many fundamental improvements to the framework. So, naturally, our "essential resources" list needed to be updated!

Read on for a round-up of the greatest articles, books, and screencasts to come out of the Ruby community!

View the full article on Nettuts+.

Singing with Sinatra

March 17, 2011

In this Tuts+ Session, we'll be taking a look at Sinatra; a small, yet incredibly powerful DSL for quickly creating Ruby web applications. You'll learn everything from installing the framework, all the way up to building an app.

View the full article on Nettuts+.

In this Premium tutorial and screencast, you'll learn how to turn that old computer you have lying around into a full-featured test bed for your websites. We'll set up a typical LAMP server with Ubuntu Server 10.10, using Apache 2, PHP 5 and MySQL 5.5 and add in support for your Ruby on Rails 3 apps!

View the full article on Tuts+ Premium.

In today's tutorial, you'll learn how to create a small web app to sell digital items (eg. eBooks) securely and accept payments from PayPal.

View the full article on Tuts+ Premium.

Throughout this three-part series, you will learn how to create a website using the latest in web design techniques (HTML5 & CSS3). This series is aimed at those with minimal knowledge of web design.

View the full series on Tuts+ Premium.

The rise of blogs on the web has brought a quick and easy way for anyone to publish their thoughts online without having to get down and dirty with HTML. Just write your content, hit "Publish" and your thoughts are instantly available for the masses to read.

View the full article on Nettuts+.

TextMate Champion

September 2, 2009

TextMate is, by far, the preferred text-editor for most web developers on the Mac. In this Premium screencast, we'll be taking a look at some of the features most developers simply don't use; ones which can massively increase your productivity by allowing you to type less and code more.

View the full article on Nettuts+.

Today, we'll be creating a simple shoutbox using the CodeIgniter PHP framework. We'll then port this exact application, piece-by-piece, to Ruby on Rails!

View the full article on Nettuts+.

In this two-part series, we'll be creating a basic "Jobs Board", similar to "FreelanceSwitch Jobs" and "Smashing Jobs", using the CodeIgniter PHP framework.

View the full article on Nettuts+.

WordPress Master

March 25, 2009

Throughout this six-part beginner-to-master series, we'll be using the advanced features of WordPress to create our own portfolio & blog, complete with an options page, multiple styles and support for the new WordPress 2.7 features.

View the full series on Tuts+ Premium.

Anatomy of GamePress

October 19, 2008

GamePress is a "Gaming News & Reviews" theme for WordPress and currently one of the most popular themes at ThemeForest. It is the most advanced theme I've created so far, and really pushes what the WordPress engine can do!

View the full article on Nettuts+.