rjq: Use Ruby to query JSON on the CLI

In my day-to-day work, I spend a lot of time working with JSON, and and one of my favourite tools for working with JSON is jq. Jq is an excellent tool for working with JSON on the command line … however, I can never remember what arcane syntax I need to use to accomplish the simplest of queries. So, as any mediocre programmer, I built my own jq in my favourite language, Ruby.

Favourite photos of 2020

At the beginning of 2020 I had planned to focus on my landscape photography a lot more, This was going to include dedicated days off work just for photography around where I live, some nice holidays abroad, and maybe some new kit. Well … holidays, remember them?

So, lockdown happened, and that kind of put an end to all my plans for the year. However, even during global pandemics, and the extreme restrictions required to beat the virus, there have been a few opportunities for some photography.

Using mind mapping software for project development

One of the plans for this year, a part from staying at home reminiscing of what travel used to like, was to focus on building this site and expanding the features that it provides. First, a little background. This site is 100% custom, it's not an 'off the shelf' template. everything you see here has been built, and designed by me. Over the years, I've tried a many different approaches to keeping track of things that need to be done, or ideas to implement, and bugs that need to be squashed.

Now, there are many project management tools available, that would fit this purpose, from simple task lists, to full blown tools providing reporting, gantt charts, agile stories, and kanban boards. For many projects, these tools can be very helpful, but for just me and this site, every one of them has always been overkill. I've tried to use these tools, but the complexity has just got in the way. I always kept finding myself going back to using a plain text file (well, actually an Apple Notes file for easy syncing between devices).

The problem of using text files

Text files are great for many things. They are simple, they can have their own structure. You can mix bullet points with text. They work everywhere. But, they have their downsides too, it's very hard to provide context within the document. Ideas that might be connected, can be separated into different sections, and loose context of how they relate to the wider subject.

Using mind mapping to keep track of things

I've always been intrigued by the idea of mind mapping. Connecting thoughts with links and hierarchies, and using colours to disguise intent behind each idea. But unfortunately, I've never had a good subject to play with them properly. It's very hard to just pickup and use a new piece technology without a good reason to need to use it.

When I first saw Mindmeister being demoed at a Ruby conference in Vienna, I suddenly had the thought that this could be a really good way to finally have a process to keep track of my plans for maniacalrobot.co.uk.

Infrared Photography

Bright sunny summers days are not typically great for landscape photographers. Harsh shadows, and bright direct light don't typically make for good photographic conditions. Sunrises and sunsets offer the best light, but here in the UK, at midsummer, that means very early starts or late finishes. However, Infrared photography is a great approach to making the most of these challenging bright conditions without sacrificing too much sleep.

Use a short domain

Choosing a name for your website, your online identity, the thing you'll need to say to people all the time is very important. Ideally, you should choose a name that is short, unique, easy to remember and easy to spell. A good domain should be unambiguous, for example, stationary.com and stationery.com sound the same when spoken, but have very different meanings when written. It also helps to avoid ambiguity with numbers and characters that look or sound similar.

Favourite photos of 2019

2019 has been a great year for my photography. I started the year by upgrading from my EOS-M, which has served me very well, to an EOS-M5. Apart from the improvement in image quality and resolution, 18 megapixels to 24 megapixels, the extra manual controls have made using the camera much more natural, and the boost in image quality was so big, that I quite quickly decided to add some new lenses to make the most of all those new megapixels. I'm quite a frugal buyer, so I wanted to maximise performance for the best possible cost. Up until now, I've been using wide-angle zooms and standard primes, so I went all in and got a 70-200 F4 L, the base 'L' lens in the 70-200 range, but the image quality on a tripod is simply excellent. In addition to this, I also purchased a second hand 24-105 F4 L IS, the 'kit' lens from Canons pro camera bodies. For the price, this is also an excellent lens, sharp and versatile, but on the negative side, heavy and prone to chromatic aberration, but nothing that can't be fixed in post-processing.

New kit aside, this year also marked a return to simply going out with a tripod and taking my time to compose landscapes. Recently, most of my photography has been from walking and holidays. It's been quite satisfying to just take my time without any pressures or time contraints.

Results from promoting an Instagram post

How do some seemingly bland Instagram posts get so many likes, and why to all 'repost' accounts have so many many followers?

The answer is likely to be many and varied, involving gaming the Instagram algorithms, and upping your search engine optimisation, but the primary tool in Instagrams armoury is promoting posts. Unsurprisingly, they make it very easy for you to promote your own posts, so I thought I'd give it a go.

Bucket List

A shortlist of hopes and dreams, things to achieve, and memories to make.

  • Visit Svalbard
  • Learn to draw
  • Visit Iceland
  • Return to Japan
  • Visit Australia
  • See the Northern Lights
  • See The Milky Way from a dark sky site
  • Get my Photography published

Write a Weekly ToDo list

Keeping on top of all the tasks of modern life can be tricky. How many times have you got to the end of another weekend and ever wondered what you achieved in the week? Well, this happened to me all the time, until I started to keep a weekly todo list. The idea is simple:

  1. Get an A4 notepad.
  2. At the start of each week, on a new page, note the week number, and write down all of your tasks you want to get done.
  3. Keep referring to the list during the week, and tick off tasks as you complete them.

So, pretty obvious right? However, I’ve found this method really helps me because of a really simple thing: dedicating a whole, new, A4 notepad page to each week. Now, I generally only have a 5 or 6 tasks jotted down for each week, which means there’s a lot space on the page left over, perfect for making notes throughout the week, and it’s this act of making further notes throughout the week, that keeps you coming back to your task list.

Vancouver Island

A recent trip to Canada provided an excellent opportunity to photograph the beautiful landscapes around Vancouver Island. With outlying islands, dense old growth rainforests, rocky shorelines, and long sandy beaches; Vancouver Island has a treasure trove of photogenic scenes.

Starting from Vancouver city, just getting to the island is a fantastic experience, either take the 15 minute flight, or the 2 hour ferry, both offer great views.

New: Calculators!

I’ve been busy building a new section of the site dedicated to Calculators!.

Calculators are interesting things, especially when you can quickly change variables and see the result set update.

Calculators will become an important section for growth going forward. The first calculator to be released is a Compound Interest Calculator, illustrating the amazing effects of compounding interest in savings accounts. The calculator gives you access to all the data as the interest rolls up each year, as well as graphing the accumulation curve.

Making calculators as interactive as possible is one of the goals. In addition, all calculators will have a full API for programmatically accessing the result sets, or for creating direct links with starting parameters for the calculator to pre-populate the calculator. For example, Here’s a link to illustrate how £10,000 can become £34,582.51 over 10 years, and if you want to access the data directly, you can use a command line tool like cURL:

curl https://maniacalrobot.co.uk/calculators/compound_interest.json?capital=10000.0&frequency=quarterly&monthly_deposit=100.0&rate=6.0&term=10

Simply appending .json to the path will automatically give you a JSON result set, which you can then use with other programs.

Can you make money completing online surveys?

At the beginning of December 2018, I’ve signed up to https://www.prolific.ac, to see if it’s possible to use online surveys as a reliable additional income source.

Prolific specialise in providing a platform for academic research, with typical surveys taking around 10 minutes, and an aim to pay around £8 per hour. Surveys are reserved on a first-come-first-served approach, meaning you need to have the survey's webpage open, or you'll miss out. Most of the time, there won’t be any surveys, with a handful of surveys appearing per day. I wasn’t continuously checking as I have my main job with Salesforce during the day, so I was very much checking Prolific during breaks and evenings. This would have reduced my potential to pick up all available surveys.

So, how much did I make? Over 1 month, I was successfully paid for completing 28 surveys, 2 surveys are pending payment, and 2 surveys failed to complete. Below are the successfully completed surveys that have paid out:

Reward Bonus Time
£1.00 £0.00 00:10:59
£0.42 £0.00 00:07:09
£0.95 £0.00 00:14:13
£0.20 £0.00 00:02:37
£0.42 £0.80 00:04:11
£0.60 £0.00 00:02:06
£0.13 £0.00 00:01:43
£0.52 £0.00 00:05:46
£1.20 £0.00 00:15:36
£2.00 £0.00 00:06:45
£0.40 £0.00 00:01:43
£0.20 £0.00 00:02:40
£2.10 £0.00 00:26:53
£1.50 £0.00 00:14:59
£1.30 £0.00 00:14:50
£0.70 £0.00 00:13:47
£1.25 £0.00 00:11:05
£1.09 £0.00 00:13:45
£1.00 £0.00 00:06:19
£0.37 £0.00 00:07:53
£1.20 £0.00 00:04:03
£1.10 £0.00 00:12:19
£1.00 £0.00 00:05:44
£0.75 £0.08 00:11:43
£0.50 £0.00 00:05:52
£0.61 £0.00 00:03:20
£0.20 £0.00 00:03:52
£2.10 £0.00 00:15:08

Together, over a month, this is a total of 4 hours and 7 minutes of work and paid a total income of £25.69, which works out to just over £6 per hour … not great. However, one thing that surprised me about this experiment was how engaging some of the surveys were. Although there were some pretty boring questions, there were some genuinely interesting questions, likely due to the academic nature of the surveys, but this was a small positive that I was not expecting.

Could I recommend this is a main income source? No, unfortunately from my brief time, I just cannot see how this would make a decent income. From what I can tell, surveys are a numbers game, the only way to make more money is to complete more surveys, which at £6 per hour is too little for the effort. Assuming you could complete surveys all day, a 10 hour day would only pay £60, with costs still to factor in.

Could I recommend this as an additional income source? Although it's only a small amount, Yes. However, you might need to consider any tax implications. Technically you should be paying tax on these earnings, which could decimate your potential for making any income, although the UK government have recently announced that you do not need to declare the first £1000 of non-employment income. Which means you’re unlikely to need to worry about this unless you have multiple non-employment income streams.

As a future experiment, I Might try running multiple survey sites in tandem, to see if better payouts are available.

The active income equation

Hourly Wage x Hours Worked = Active Income

This simple equation can be used to demonstrate the importance of understanding the value of your own time. As you can see, Active Income is directly affected by either how long you work, or by how much you're paid; increasing each of these will increase your total Active Income.

The first way to increase your Active Income is to increase the number of hours worked. This is probably the easiest to achieve, as your job might allow you to work additional hours, work overtime, or have a second job. However, there is only so many additional hours you can work, firstly, everyone needs time away from work to relax and enjoy, and secondly, it's impossible to work more than 24 hours in a day. because of these 2 constraints, increasing hours worked will only ever yield small improvements in your Active Income.

The second, and better approach is to increase your hourly wage. Unfortunately, many people greatly underestimate the value of their time. The sky is the limit when increasing your hourly wage. However, achieving a higher hourly wage is obviously harder to achieve, as this will require you to learn new skills and be willing to progress your career, or even change your career entirely. A quick method of increasing your hourly wage is to simply change companies. This can be hard, as you may have loyalty to companies, but in this game, you have to look after yourself, and if you feel there are better opportunities at another company you can often negotiate a higher salary and expectations of promotion.

Active Income will always be constrained by these 2 factors. If you're really interested in boosting your total income, you'll need to start making your money work for you. And this is called Passive Income.

Selling photos on Picfair

As a keen photographer, I take lots of photos. It's not uncommon for me to shoot upwards of 500-600 photos in a weeks' holiday, and sometimes I like to feel that I've come home with some pretty good shots. I've tried my hand at submitting shots to the bigger stock libraries, but the process always seemed very complex, and the returns were never in your favour and also preferred top quality silly expensive hardware produced images. Canon 5D Quality, thousands of pixels by thousands of pixels, and shot with expensive prime lenses. Not that these requirements are unrealistic, they do charge top rate for their images, and they're all very high quality, but this meant my "hobbyist" shots were out of the running.

Then along came a UK startup Picfair.

Swift style conditionals in Ruby

The Swift programming language has a neat feature that guarantees the presence of optional values in conditionals.

// possibleName is an optional variable, it maybe hold a name, or it may be nil
if  (name = possibleName} {
  // name is guaranteed to not be nil
  // name is also declared as a constant, so it will always be available.

This method of exacting the optional value into a local constant for use inside the conditional state is a first class construct.

In Ruby you can use these same constructs to a similar effect, although there are pitfalls to using this pattern. You can assign to variables in the conditional check, however, unlike Swift, in Ruby you can only declare throwaway variables, which opens up the possibility of the value mutating later in the code. The new name variable also exists outside the scope of the conditional, polluting the namespace.

In Ruby

if name = possibleName
  # assuming name is not reassigned, it will be a value
  puts name
  # However, as name is a variable, we can reassign it
  name = 123
  puts name
# name is still available outside
puts name

Using Tap

A Ruby solution to this would wrap the conditional in a block, that would provide the variable to only the block. Object#tap does exactly this, but unfortunately, this approach does not protect us from the possibleName being nil, so we'd still need to check that possibleName has a value.

possibleName.tap do |name|
  puts name if name != nil
puts name # NameError

Write your own

Because Ruby is the awesome language that it is, we can extend the behaviour of the Object class. Here, I've defined an Object#plug method, like Object#tap it yields itself to the supplied block, unlike Object#tap, it won't yield if 'self' is nil. In hindsight, a better method name could have been Object#tap!

class Object
  def plug
    yield self if block_given? && self != nil

"Some string".plug do |name|
puts name
# => Some string

nil.plug do |name|
puts name
# this does nothing

This gets us pretty close to the swift unboxed value example. The harder part is making this temporary variable immutable, and that's a problem for another day.

The Great Bulgarian Adventure

It's been a year since we lived our Great Bulgarian adventure, 6 months spent living and working in the capital Sofia.

We arrived in mid february to a cold city, and a very unfriendly looking front door to our apartment building, our minds starting to wonder if this was such good idea after all. However, within a couple of hours, and short walk into the city centre for our first meal, our worries had been removed. We would get used to the broken paving tiles and the graffiti. Now we're back in the UK, we miss it, the friendly nature of the local Bulgarians, the great food and the months of blue skies.

Most of time in Bulgaria was spent surrounded by the historical buildings in the centre of the Sofia.

Capturing and processing photos on the iPhone

They say the best camera, is the camera you have with you, and for most of us, that will also be your phone. With an 8 megapixel sensor, the iPhone5 is already a pretty capable camera, then consider that modern smartphones are pretty powerful computers that allow you to do most

A recent snowboarding trip to Austria was a great opportunity to test out if just an iPhone was enough to capture some great images.

All of these photos were taken with an iPhone5 and processed on the phone with camera+. View the whole set on flickr

Building Astro Runner part 1

Like most software engineers, I've always got a few part-time side projects that work on, most start from what at the time seed like great ideas, most are started with great enthusiasm, most never see the light of day.

This is the story of side project that shipped.

It all started much the same as usual, have and idea, spend an evening playing around with it. Only this time I got a lot further than usual. I've been using X-Code, Objective-C and the iPhone frameworks with the iPhone simulator for other projects, so the tools are famililiar to me. My fulltime job at Kyan is mainly spent programming in Ruby, so the jump to Objective-C is quite straight forward.

My plan was to build a faux-3D endless runner game. I'd recently stumbled across a reference to how to use the UIKit framework to transform simple UIViews into 3D space. From there, I'd figure I could use some very simple animation and some collision detection, and I'd have the basis for the game. It couldn't really be that easy could it?

3 hours later

The Apple iOS frameworks are excellent. There really is no other way to say it. Within a very short space in time, I had the basic 3D environment built, animating 'obstacles', a space ship with movement controls and collision detection. This is half the game built, and although I some major refactoring as I've learnt more, these core parts of the game have remained largly untouched.

The game engine that astro runner uses is 100% Apple UIKit, there are no 3rd party frameworks or toolkits. There are also very little images and graphical assets. Apart from the application icon and the retro typeface, all the graphcial components are drawn in realtime with Core Graphics, this has kept the total download size to kjust under 300Kb, that's tiny compared to many other games, which easily run above 100Mb.

© 2011–2022 Philip Balchin | About | Colophon | RSS | π