Writing an Open-Source Android Library
(and possibly regretting it..)

So you decided to write an open-source library, and here you are. What have you got yourself into now, and what’s that header image got to do with anything? Well that lovely header picture up top is a photo I took from my desk of a seagull caring for its young; it has just vomited up some slugs that it collected earlier, and the fledgling gulls are hoovering it all up as if it’s…not a disgusting pile of slugs because they don’t know more delicious things exist in the world, because they’re still too young to even fly off and find food for themselves.

And that, in a metaphor, is a third-party open-source library. End of article.

I’m joking, but I’m only half joking, because that is a pretty good metaphor for some OS-libs I’ve seen, and I still have more software-development-flavoured snark to deliver before my desire to write wanes and I go back to swearing at the habitual, almost wilful, illogic of Facebook SDK developers, under my breath of course – as they still kinda pay the bills for me these days..

So you might be wondering at this point when I’ll just get to the code dump that you can copy-paste somewhere, and rename awesome-omni-util-lib, so that you can become the next Jake Wharton, well hold your horses there young buck. First in order to decide whether or not we should even be making such a library, we must do a little exercise I like to call, the Super Fun Dunning Kruger Stage Self-Assessment Quiz Fun Quiz!

Here ’tis:

1. Are you writing this library because you actually need it? Or because you think that you or someone else might need it at some point, maybe?

If the latter. Abort. You are wasting your time. YAGNI alert! At very least you should need this library that you are creating right now, because the only way that you “shake down” a dependency is when it’s used. In addition, if nobody uses it (not even you), nobody finds the bugs, and the dependency remains rubbish and unusable. Just search the sea of single-commit library repos on GitHub that are tagged android-library to see what I mean.

2. Have you been using the techniques that are in heavy rotation in this library for more than a couple of weeks?

Let’s assume that your library will be a great success, and used by thousands in the first few months. Congratulations! Your repo will be acquired by Google in no time, and your future Silicon Valley career path is a sure thing! Think of all of the people looking at and scrutinising your code in great detail, and adding that unique flavour of warm, supportive and constructive feedback that the internet is known for. Take some time to think about that one for a while and ask yourself if you really want to open up that door.

Do you really want this thing out in the open? Or could it live quite happily as a project-scoped library module, ugly in form and absent in test coverage, but works fine on your machine so who cares?

3. Does a similar thing already exist, written by a developer people have actually heard of/has done a conference talk or two so has dev clout (not to be confused with dev competence, as they are very different things – see Facebook SDK comment above..)

If your library is insufficiently niche, someone else will have already done it better, or is about to. You will never be the smartest person around, and if you think otherwise you, padawan, are so far left on the holy curve of Dunning Kruger that you should stop reading right now and go and do a hard thing that you will fail at, because the world has more opportunities for failure and moments of humility to dish out than you could ever dream of, and if you haven’t fallen hard on your face and had your code quality ego unceremoniously stripped from you, you are missing a crucial lesson in life in general. Certainly one in software development. So you should go and experience said humiliation such that you can be a better, more modest and balanced developer on the other side of that formative experience.

Un-requested life lesson segue aside, do you want to write a second, tenth, or fiftieth best library that does a common thing that other people have done a better version of? To compete with people whose dev clout attracts hundreds of stars and tens of genuinely helpful PRs, which add technological distinctiveness to their own, and makes them look like a competent leader of devs, even if they’re just Developer Advocates who couldn’t hack an actual production-code writing job so retreated to telling other people how to do it, like a school careers advisor – like, dude. Look at yourself. What advice do you have to give me?

4. Do you seek to boil the ocean with a library of such full-functionality that it will serve all purposes?

Everyone who grew up coding, has at some point had that thought – when they were about 13 years old, and the optimism of youth, blissful ignorance of feature creep has yet to rob the ambition from them: I’m going to write my own Operating System! Very, and I mean very few ever actually got something useful working. I’d go as far to say that if you managed to load a hardware driver and get something to work from a line of interpreted code, you’re in the 1%.

Bear in mind that it’s 2020, and there are still only three viable OS’ for personal desktop use – Windows, MacOS and Linux, and that last one is still for nerds, and the guy who “wrote” the first one stole it anyway; come on Bill you’re fooling nobody here, we know you Zuckerberged it. Come clean!

You can keep the money.

5. Do you have a strong (and justified) opinion about how the thing that you’re making this library to do, should be done?

This might be the most important in this super fun quiz fun. If you don’t have a strong opinion about how to do this arbitrary chunk of logic that you’ve cooked up in your head, you’re going to follow the ruts in the road like a SUV on summer tyres on a crisp January morning in Quebec; getting pulled left and right where the tracks cross, and get sidetracked every new article you read on Medium, RayWenderlich or that YouTube one whose name I always forget. You know, the German guy.

If you want to write a LiveData-based random pun generator that updates a ViewModel and punts it out to a TextView element that only displays Comic Sans text in #F00, then you make that library, kid. Don’t let anyone on the issues tab tell you it should support other typefaces.

To use the metaphor from up-top, instead of giving-in to the baby seagulls demands for juicy slugs that you don’t want to puke up, I suggest that you:

Tell them to fork off and do it themselves

Conclusion

Oh right, that code that you wanted to copy paste so you could actually make an Open-Source Android Library module.

Here you go.

No, I didn’t write it myself, because do you really think I can write an example better than the JitPack team already has? Because I don’t.

Thanks for reading. Good day to you. 👋

A Weekend Away

Girona from the battlements

Just got back from a weekend away, and remembered that I promised myself that I’d post at least something a week… So I’m doing a photo post this week. More words will follow, once brain rested has been enough to right words in put the order. ZzZzZz

Queen Mary

Light Hoose

Bear lamp tho fam

Mediaeval spin

Remember that windless, sunny day when I tool this?...

Stacks yo

Archy

Door

My eyes are overexposed!

Twisties

Aircraft of Canada

Polar Aircraft

I’ve taken A LOT of photos over the past couple of years. Since getting my Nikon D5200 I’ve been habitually taking more photos than I could ever need, primarily due to my theory that if I take a lot, there will be more good ones in the mix due to the sheer probability of the thing. Also, taking more = practice, and practice makes, err, better… I’m a few years clear of the selfie generation that’s currently pressurising the intertubes with oversharing of their day-to-day lives, so I prefer instead to take pictures of what I see that interest me and places I’ve been to that I’d like to capture and recall. I don’t take photos for other people, I take them for me. So I can remember how I felt wherever I was when I took the picture.

This results in a lot of photos of mountains, abstract shapes, to the annoyance of my friends and family back home who seem to want to see pictures of me, in the holiday photo style of standing in-front of a monument or landmark, squeezing out a cheesy smile for the camera as it’s held by a passer by who I’ve just met – I do that occasionally, to keep the fam happy, but that’s just not very me.

One consistent theme however is that I take almost as many photos of metal things with engines in as I do landscapes that I like the look of, including planes. So I’m cheating again this week with the whole “one post a week” challenge; here’s another video. 😛

Mac Software Essentials That You Should Be Using

MacBook Air on a roof terrace in Toronto

Out of the box, a Mac is a thing of beauty, from the clean lines and cool-to-touch aluminium case to the slick, jitter-less OS, I’ve not gone back to a Windows machine from the first time I seriously started using an Apple laptop (which was only a few years ago!). Prior to that I was a staunch PC advocate, but it’s funny how often that coincides with being a student/generally unable to afford to drop a few thousand on a computer that does the same job as much less expensive one, albeit much less stylishly.

But reformed fanboyness aside, if you’re going to use it as a day-to-day machine, there are some things that it could do better. So here are a few of the tools that I use to minimise the number of times a day that I want to throw my lovely slab of Hall-Héroult-refined Bauxite off the apartment balcony.

BeardedSpice

Prevent iTunes from hijacking your media keys, use them for streaming media

As an Android user, I never use iTunes. In fact the only time I see the iTunes app appear on my laptop is when someone else wants to charge their iPhone from my laptop’s USB ports and it pops up trying to sync with the new device, or when I forget that those media buttons don’t do what I expect them to, and I accidentally launch it when trying to pause an audio track or podcast that I’m listening to…

That was until I discovered BeardedSpice! It sits in your menu bar and performs the seemingly simple task of making whichever media source is playing in one of your browser tabs respond to the input from those little Mac media keys, instantly making three little pieces of black plastic that I’ve been carrying around with me actually useful for the first time. It works with sites I regularly use; YouTube, Pocket Casts, Spotify (web), and even Subsonic – a bit of a niche media streamer, but one I’ve been a daily user of for the past five years or more.

It supports loads of others too, here look, and the icon looks like me. So that’s nice too.

Icon showing a little bearded dude wearing sunglasses, and over-ear headphones. Icon for Bearded Spice for Mac.
Basically me

Alfred

You thought Spotlight was good? Let me explain you a thing..

I was blown away by OS X’s inbuild Spotlight omnibar when I first got a Mac. For the first time in my computing life, a GUI interface gave me a way to search for things on my computer without having to wait ~20mins for my hard-drive to be re-indexed, then something crashes, then it slows the whole system down, then something else happens. Then I have to reboot and leave the laptop running on the passenger seat of my car because it wont turn off until I run those updates, which takes half an hour or more, and then…ah I’m sorry. The trauma of owning a Windows machine all those years can bubble to the top of my consciousness sometimes, I’ll get  back on topic…

Alfred does everything that Spotlight does, but it adds additional features that I use so often that it must’ve saved me hours of my life in the long-run. For example, say you want to find a document called important_biznis_dok.txt, and you know at least part of its name, just type:

'impo

and it’ll probably show up, and the path will be shown beneath it. Decide that you want to open the folder its in rather than the file itself? Just hold ⌘, and below the filename it’ll let you know that selecting it will now open it in Finder.

Ok, that’s sort of what Finder does, which is still cool. But the really useful stuff it can do includes inline calculator commands, for instance to get the square root of 4397 and copy it to clipboard:

Alfred Calculator for Mac.
You can make it dark-themed too. Because h4x0r.

jump to Google Maps search directly:

maps barrio gotic barcelona

has the ability to jump straight to a Wikipedia page on a topic:

wiki Antikythera mechanism

and basically takes out the intermediate steps of:

Open Browser → Type web address → Get web address wrong → Click on “did you mean” suggestion → Go to site → Start doing what you actually wanted to do five steps ago

Once you learn the keywords, you’ll be flying.

Arq

Save the intelligence services some time, upload all your base to the cloud

This beloved Mac slab is not just the conduit through which the world receives photographic evidence of my questionable culinary judgement, but it’s also the centre of my working life, and the primary tool that I use to run my business. For that reason the information on it is more than a little important to me, so I have backups. In fact I have three redundant forms of full-system backup, the most recent edition being that provided by Arq. Given how much I travel about, I became increasingly worried that one day I might become the victim of external hard-drive failure, baggage loss or theft, or a combination of those things (it happens) and that all my base would be lost… So I looked into various ways to back up my data to cloud storage. I already had in place a system which backed up all of my stuff on a server that I build myself at a site in the UK, but as I’m rarely in the same place as that machine and it’s getting on a bit, I wanted someone else to handle the maintenance of the server itself and just let me worry about the backing up “bit”.

So I found Arq, a product that works much like Apple’s Time Machine, but rather than putting your backup on an external drive you provide it with cloud storage credentials, and a super-long encryption key, and an end-to-end encrypted backup of the directories that you specify are stored off board and synced automagically – just like Time Machine.

There are other options out there, but I liked the fact that it could use Amazon Cloud Drive, which for US$60/year can be upgraded to unlimited cloud storage; bargain! Unfortunately, being from the UK, that unlimited storage option is not available. 🙁

Which brings me to…

Tunnel Bear for Mac

Dodge region-locking on websites

I’m a British Citizen, I pay taxes and have a TV licence, so I want to be able to watch iPlayer wherever I am. Unfortunately the BBC, much like other nationalistic media outlets around the world, lock down the ability to view iPlayer content to UK IP addresses only. The only way around it is to set up a VPN tunnel to an IP address that you have access to, and to browse the net via that IP address instead.

Tunnel Bear dialog box from OS X. VPN tunnelling tool for Mac.
The “Rawr!” on connection sound effect is sadly lacking from the OS X version (so I make it myself)

This used to be a time-consuming, rubbish thing that required copy-pasted terminal commands and a modicum of technical knowledge. Well, not since Tunnel Bear came along and commoditised that process! Now with a couple of clicks, you can choose from the range of countries that they support, and use any regionally-locked service that you like. Making the internet how it should have always been in the first place – a level playing field, open and equal for everyone to use. Their Grizzly Bear unlimited data package is very reasonably priced, and fast enough to stream the Christmas Special of Sherlock to the South of Spain. Or…sign up for an unlimited data subscription to Amazon Cloud Drive from a US IP address, and back up your system with the aforementioned backup tool. Just saying. 😉

It’s not just for Mac either, there is a version for Android and iOS too; you can use the same account with all three.

Transmit

Like FileZilla, but way better

I’m increasingly becoming an adherent of Amazon Web Services, and have a few EC2 instances now running server back-ends and maintenance control panels. The convenience of being able to get a server provisioned and up and running with out the bleeding knuckles that used to result from manually assembling server racks brings me a little frisson of joy each time I do it; especially when I do it from the Android app! If you’ve no idea what I’m on about, you can basically run virtual computers and have virtual hard disks on Amazon’s cloud, and use them as if they were in the same room, connected directly to your Mac. It’s brilliant, we’re living in the future!

Anyway these virtual drives can’t exactly be picked up and plugged into a laptop, so you need to either run a load of terminal commands to mount and send/receive files from the drive, or use a sweet GUI client like Transmit to mount your S3 volumes. Once you enter your credentials and get a drive set up, you can mount it as if it was an external drive sitting on your desk, and copy files over as you would any other removable drive on your Mac. It’s magic!

Bear in mind however that you’re charged for usage on AWS, so copying your entire BlueRay backup collection in case you lose or scratch any of them, might cost you more than just buying them again!

f.lux

Avoid the blues…

As anyone who knows me can tell you, I am not a morning person. I would far rather stay up until 4 or 5am and wake up at noon, than be up at 5am. Despite that, I try to force myself to do the opposite, mainly because whilst my body wants to be a night-owl, I feel like I get more for my money out of any given day if I get up early.

That late-worker tendency does mean however that I am using my laptop long after the sun has gone down, and if recent studies are correct in suggesting that the blue light from computer screens inhibits melatonin production, then finding a way to minimise the blueness going into my faceballs late at night should help me get a restful night’s sleep.

I’ve been using f.lux for some time on my MacBook (and Twilight for my Android devices, including Android Wear!) to reduce the brightness and blueness of my display after dark, and placebo or not, my sleep tracker indicates that it helps me to recharge more fully overnight. I definitely suffer less from the inability to drift off these days. It runs in the background, and works by tinting your entire screen gradually as the night goes on. It picks up sunrise/sunset time from your current location, and you can set a wake-up time and goal sleep duration so it will give you a reminder if you’re working a little late and should really be getting your head down.

Just remember to pause it when you watch a film on your Mac, otherwise…

“Hmm, this film is really orange. Maybe the Director of Photography is making some statement about… Ohhh! Right!”

Keeping it Clean

I made a conscious decision to just use a laptop as my main machine back in 2004, so for more than a decade now I’ve been living without a PC “tower” as part of my essential kit. Whilst the advantages of being able to carry around your main machine with you all day every day are clear, one of the major disadvantages of a portable computer is storage space.

I have two external drives that I use to back up the machine and to keep important things like my photos backed up in duplicate between bulk uploads to my main backup server, but carrying those around with me in the same bag as the laptop is sort of defeating the point of having a backup…so I don’t. You shouldn’t either. I keep them locked away wherever I happen to be staying, and just take the aluminium slab with me. That means day-to-day I only have half a terabyte of storage space to play with, which used to be a lot…but once upon a time people said the same thing about half a megabyte; it’s a fact of digital life that data bloats.

I’ve accumulated a few tools over the years that I always come back to when keeping my MacBook tidy, here’s the rundown:

CleanMyMac 2

Screen Shot 2015-07-19 at 09.36.06If you only want to use one tool to keep your mac clean, this is the one I’d recommend. I got it in a MacHeist bundle a while back and since then have used it a couple of times a week without fail. Its ease of use is what keeps me using it, along with the reminder that you can enable that tells you when there’s a load of crap that you probably don’t need any more.

You needn’t define which files you want to keep or what you don’t upfront, it provides guidance about the common places to tidy things up; the trash can being a common and obvious one, but less obvious are unused large files that you might have forgotten about, browser and OS extensions that aren’t enabled, and even photos kept in iPhotos recycle bin!

You can also use it to cleanly remove apps that don’t support the Mac standard “drag to bin” method of uninstallation, and also makes it easy for you to reset an app to a clean install setting without having to actually reinstall it (I found this handy for resetting Eclipse after various rogue plugins ruined my setup, before I ditched it entirely for Android Studio!).

The last cool little feature, is that it keeps a running total of how much space it’s freed up since you started using it; my count is well over 3 terabytes now! Feels good.

CleanMyMac from MacPaw

 

DiskInventoryX

Screen Shot 2015-07-19 at 10.01.29This tool ventures a little into the realm of geekery in terms of its aesthetic and ease of use, it’s certainly not as pretty and straightforward as CleanMyMac. I sought out this tool following my original cleansing pilgrimage away from the poisonous gospel of Microsoft Windows, where I travelled into the remote mountains on a brain debugging retreat to cleans the last of the carcinogenic digital toxins left by years of traumatic spontaneous BSODs and the generalised corruption of my workflow by Visual Basic’s bastardised Hungarian System notation…

Too dramatic? Well I used to use a tool called WinDirStat for visualising hard disk space, and wanted the equivalent for my Mac. That tool is DiskInventoryX, and is very similar in style to WinDirStat in that it gives you colour-coded visual representations of whichever storage volumes that you have plugged into your machine, thereby making it easier to find and remove the bloaters. I cannot stress how useful it is to be able to see blocks of different sizes rather than just numbers in a list; it directly led to me moving all of my VMs (I can’t unfortunately completely escape Windows…) to external drives when I saw that the files that Windows creates when it suspends running state were bigger than my entire documents folder!

It’s somehow more meaningful when you see a big pink tumour of wasted space.

Disk Inventory X by Tjark Derlien

 

Dupe Guru

Screen Shot 2015-07-19 at 10.23.50I download a lot of stuff. Code, documents, images, screencasts of bugs, all sorts of things, all day as and when I need them. As soon as I’ve viewed them I immediately forget where they are, if I’ve seen it before and whether I’ve already deleted it. When they all end up in the same folder, then it’s easy – the little (1) gives me the clue that I already have that file, but what if like me you tend to use different folders on different drives for different projects and clients? That’s when it gets tricky. Fortunately I stumbled upon DupeGuru at some point in the past year and since then those issues have vanished for me.

It’s low-weight, fast and super easy to use. You can select individual folders or even entire disks. Hit scan, wait for it to do its stuff, and choose an action to take either individually or in bulk. As I wrote this section on dupeGuru, I set it off scanning an external drive with just under 2TB of data on it. By the time I’d finished writing, and at some point between then and me going to make a second coffee for myself, it had created me a list of stuff I could get rid of. Manually trawling the same folders would’ve taken hours (a conservative estimate) to do manually.

dupeGuru from Hardcoded Software

 

Finally, sometimes the simplest things…

Sometimes all of these fancy GUIs can blur the real issue at hand. If you’re not scared of the odd terminal command or bash script, check this, the simplest of simple Terminal commands, out:

mv ~/Downloads/* ~/.Trash/

I set this up as a shortcut when I got my first MacBook Air, and still use it to this day. All it does is move the contents of the current user’s Downloads folder to Trash. You can even automate it on login/logout, and CleanMyMac will collect it next time it runs.

Create a shortcut to it on your tray, or if you’re brave set it up to run automatically, and you’ll start to think more carefully about whether you should leave the single copy of that important document in your Downloads folder next to the cat memes in future. Because they’ll all end up in the digital landfill together!

This is why I exercise at 5am

The roads are empty but for a few buses, delivery trucks and sweepers. There are other crazy people running and cycling to delay the reaper, and the city feels like it’s taking a deep breath before sprinting back into the rat race. It’s peaceful, and it kickstarts the day.

This morning, the sun was peeking above the Biosphere on Saint Helen’s Island when I got to the Old Port. It took my camera today, and I’m glad I did, so here (in black and white, I’m going through a phase…) is what Montréal looked this morning.

botesrgud dome early lockitdown park squirrel water