Clean the Lint Out

One of the nicer tools a developer has is the linter. The linter helps you conform to a clean, unified and easy to read format of your code. When I join a project that has no automated lint set up, adding lint to the flow is one of the first steps I take.

In the past, I used to set up lint on the build server. That way, no pull request (PR) would get merged which breaks the formatting rules of the project. However, this had a few flaws. First, unless squashed, your git history had lint fix commits all over. Second, it would really slow you down as a developer. You’d create a PR, and then wait for a few minutes – only for the build server to tell you your formatting is wrong.

It was only fairly recently that I learned about git hooks. In a project I joined, they were using them in the pre-push step to prevent you from pushing code that was not properly linted. Pretty cool. But we could do better. If we moved linting to the pre-commit step, you couldn’t even commit a file that was not linted. Now, you don’t even need a separate commit for the lint fixes.

The linting script on that project was also scanning the whole project. This works really well when your project is already linted. However, if you’re setting this up on an existing project, you could never commit anything without fixing the whole project. To fix that, I rewrote the lint script to only iterate just over the newly staged files. For Macs, the script looks like this:

#!/bin/bash

echo "Running lint..."

git diff --name-only --cached | grep "\.kt" | while read fn; do ktlint "${fn}"; done
RESULT_KTLINT=$?

[ $RESULT_KTLINT -ne 0 ] && exit 1
exit 0

For Windows, it looks like this:

#!C:/Program\ Files/Git/usr/bin/sh.exe

echo "Running lint..."

git diff --name-only --cached | grep "\.kt" | while read fn; do ktlint "${fn}"; done
RESULT_KTLINT=$?

[ $RESULT_KTLINT -ne 0 ] && exit 1
exit 0

The above examples run ktlint, for Kotlin projects. You should be able to port them to any other language fairly easily.

There’s still one problem. Every developer has to copy the relevant script manually to their .git/hooks folder (and name them “pre-commit”). This can be solved by automating the copying task. In gradle, it can be done by updating your app build.gradle like so:

task installGitHook(type: Copy) {
    def suffix = "macos"
    if (Os.isFamily(Os.FAMILY_WINDOWS)) {
        suffix = "windows"
    }
    from new File(rootProject.rootDir, "automation/scripts/pre-commit-$suffix")
    into { new File(rootProject.rootDir, '.git/hooks') }
    rename("pre-commit-$suffix", 'pre-commit')
    fileMode 0775
}

tasks.getByPath(':app:preBuild').dependsOn installGitHook

And voila! The first time a developer builds the project, the appropriate git hook gets installed. Don’t you just love automation?

What is That Bulge in Your Pocket?

For years I’ve walked around with a standard manly wallet. I had two problems with it. The first – it was made of leather. I’m not a fan. I try to avoid leather products when I can. The second – it was bulky. Whether I kept it in my front jeans pocket or the back one – it was absurdly noticeable. So I started looking for alternatives.

The Klips. Why
would you get that?

Kickstarter is the source of many interesting innovations. It is also the source of absurd ideas (in my humble opinion, of course) such as Klips, pictured on the right… Klips was never funded. Not all Kickstarter wallets are bad, though…

And then I came across the Dash wallets. I pledged to their Kickstarter project in October, 2018. It was $18 at the time for an early bird. By late January, 2019 I had my wallet in hand. It was everything I hoped it would be. Extremely slim. With good storage for my cash and cards, I was perfectly happy. Oh, and no leather! Nice. I also liked the pull tab to access the cards and the RFID protection.

Now this is what I’m talking about.

In February this year (2020), I pledged to their second iteration. The price was the same, and at $18 I was happy to have a second wallet. I even bought a couple for my dad and brother. The second iteration introduced silicone grip dots to hold your cash better.

I’m such a fan I even got one of their third iteration models, which arrived late July. This time, they introduced a stacked card mechanism to the pull tab (see below). With the pandemic, I haven’t had a chance to enjoy it much. But I’m looking forward to! Honestly, I could not recommend this wallet enough.

Behold… Stacked cards!

Out of the Darkness Comes Light

One topic I’ll probably be writing about a lot is batteries. I believe I may be a bit obsessed about the matter. I keep my devices charged whenever possible. I’m constantly aware they are living on borrowed time.

I recently switched back from using MacBook Pros to Windows 10 on a Dell XPS. I found out Microsoft removed the option to automatically dim your screen on battery. Since I haven’t used Windows in a while, this was a surprise to me.

I started dimming the screen manually every time I unplugged my laptop. Then setting the brightness back up when plugging in. This did not always work for me. Sometimes I forgot to do it. The rest of the times just felt… Repetitive.

So I thought to myself – surely this could be automated. I did a little bit of digging. Guess what – it CAN be. I’ll save you the trouble of investigating this yourself. You will need a little (very little, I promise) technical knowledge.

  1. Download NirCmd. You probably want the 64 bit version. You can use another command line tool that can toggle the screen brightness if you prefer.
  2. Move the NirCmd files to C:\Program Files\nircmd.
  3. In that folder, create a new text file and name it DimScreenToggle.bat.
  4. Open the new file in NotePad or your favorite editor, and paste the following into it:
@echo off
set DimScreen=""c:\Program Files\nircmd\nircmd.exe" setbrightness 0"
set UndimScreen=""c:\Program Files\nircmd\nircmd.exe" setbrightness 100"
set Scr="%temp%\DimScreenToggler.vbs"
set VB=echo^>^>%Scr%
if exist %Scr% del %Scr%
%VB% Set oWMIService = GetObject("winmgmts:\\.\root\CIMV2")
%VB% Set cItems = oWMIService.ExecQuery("SELECT * FROM Win32_Battery")
%VB% For Each oItem In cItems
%VB% iStatus = oItem.BatteryStatus
%VB% if iStatus = 1 then WScript.echo "On battery" Else WScript.Echo "Mains operation"
%VB% WScript.quit iStatus
%VB% Next
cscript //nologo %Scr%
IF %ErrorLevel% EQU 1 (start /b "Dim Screen" "%DimScreen%") ELSE (start /b "Undim Screen" "%UndimScreen%")

The above creates a script that checks the power source and sets the screen brightness accordingly: to 0 if on battery, or to 100 if plugged in. You can adjust these numbers to fit your preference.

  1. Save the file.
  2. Launch your Event Viewer (Windows Key + R, then type in eventvwr, and click OK.).
  3. On the left of the Event Viewer window, expand Windows Logs and then System.
  4. Next, unplug your laptop. Wait for a second or two, and plug it back in.
  5. From the menu, select Action -> Refresh. You should see two new events at the top. Note the Event ID.
  6. Right click on one of the two events, and then on Attach Task To This Event.
  7. In the new Create Basic Task Wizard window, fill in a name for your task (Toggle screen brightness by power source would work). Click Next.
  8. Click Next again on the following screen (When an event is Logged).
  9. In Action, keep the selection on Start a program. Click Next.
  10. Click Browse, then find the DimScreenToggle.bat file you created earlier. Select it and click Open.
  11. Leave the rest as is, and click Next.
  12. Tick the Open the Properties dialog for this task when I click Finish checkbox. Click Finish.
  13. In the properties window that opened, go to the Triggers tab.
  14. Click on New… to add a new trigger.
  15. In the Begin the task dropdown, select At startup.
  16. Tick Delay task for, and set the time to 5 seconds.
  17. Click OK to dismiss the new trigger window.
  18. Under Conditions, make sure Start the task only if the computer is on AC power is unticked.
  19. Click OK to dismiss the properties window. You’re done!

To test your new setup, try unplugging your laptop. It should dim the screen almost immediately. Plug it back in to see the screen brighten up.

With this setup, expect a significant boost to your battery life. Let there be light!

Take My Money! (Part 2 of 2)

In my previous post, I mentioned figuring out what I want to buy early helped. In short, it let me wait longer for the right price. There is another reason why figuring it out early helps. It also means I may be able to order it for much less directly from China.

It’s surprising how many products on sale you can find for a fraction the price on AliExpress.com. AliExpress is kind of like a Chinese Amazon. You can find virtually anything there. And it’s CHEAP. The catch? You often have to wait for about a month before you get your order.

Since 2013, we have another alternative. You probably encountered it already. It’s called Wish, and it is American. Similarly to AliExpress, you can find almost anything you can think of there (and something you would never think of!). And similarly, it’s dirt cheap and takes up to a month to ship. If you use my link above, both you and I will receive money in credit.

At some point I’ll highlight some of the more useful products I found on AliExpress. So stay tuned! Oh, and feel free to share your finds in the comments section.

I may get commissions for purchases made through links in this post.

Take My Money! (Part 1 of 2)

Well, actually… Don’t. I’d rather keep as much of it as I can to myself, if you don’t mind. This time, I’m talking about buying stuff online.

I’ve learned one important thing about shopping online. Prices fluctuate – sometimes quite drastically. So, it seems the best strategy is to figure out what you want to buy as soon as possible. Ideally, figure out what you want to buy long before you actually need it. The sooner you figure it out, the longer you can wait for the price to drop.

Naturally, as my list of things I want to buy grows longer, I can’t keep checking Amazon every day for their price. Along come a few websites that actually help you keep track of price drops.

The first, and my personal favourite, is camelcamelcamel.com. This website offers a free service of tracking prices for you. You simply paste in a link to the product you’re interested in. You then set your target price and start tracking. You can even see how the price of the product fluctuated over time.

Another helpful service here in the UK and in some of Europe is pricespy.co.uk. PriceSpy is another free service. It tracks products for you, just like camelcamelcamel. But it also compares prices between different stores. So even if you can’t wait with your buy, PriceSpy is there to help you find the best price.

I’m sure you get the idea by now. If we use a free service to track products, we can get them when the price drops. This can actually save us a lot of money.

Away With the Boilerplate!

About a year and a half ago, I audited an Android project for a client. One of the glaring observations was that the test coverage was quite poor.

To improve the test coverage, I had to write a lot of code. A lot. Since I’ve written plenty of unit tests before, and knew I’d be writing a lot more after, I made a decision. Given how every unit test followed the same pattern, I decided to automate the process. TestIt was born. I’ve never looked back since.

TestIt is a unit test boilerplate generator for Kotlin. It analyses the code for you, finds testable code and generates a set of Given/When/Then test templates for it. All you have to do is fill in the logic of the underlying code.

The project is open sourced, so feel free to contribute to it. Maybe it will inspire you to develop a similar one for another language. If it does, let me know!

Untangling My Cables

I spent more time than I’d like to admit choosing the topic I’d share with you first.

There is a broad range of topics I’d like to cover in this blog. But A journey of a thousand miles begins with a single step and yada yada. So here we are. The first step.

Let’s start with something too technical. I’ll share with you a small optimisation that keeps giving me great satisfaction. I’m talking, of course, of not having to deal with tangled cables in my backpack.

As a developer, specifically a mobile developer, I end up with quite a few cables in my bag. USB to USB-C, USB-C to USB-C, earphones (I don’t always want the hassle of pairing my wireless headphones. Sometimes plugging in a cable is quicker and simpler). So, what happens is, the cables become a tangled mess. They used to, anyway. Then I discovered the magic of cable organisers.

The one I’ve used right up until the pandemic was the GiBot Cable Organiser. I cannot recommend this organiser enough. It has plenty of space for all your cables and even a portable charger. My backpack has never been tidier. I must say, using it at the office and taking out the cables I needed has drawn quite a lot of positive attention. I’ve already recommended it to a few of my colleagues.

Now, I’m not crazy about it not being more rigid. But, that does mean it’s easier to stick in the backpack, and it is really quite slim.

The BUBM Traveler Case. I have recently replaced the GiBot for another, somewhat similar organiser. Since I’ve been home from early in the pandemic, I never had the opportunity to try it out. I do like how it’s got compartments for everything, and the BUBM is rigid, unlike the GiBot. On the flip side, it also takes up more space. So I’m definitely not parting with my GiBot just yet. I got it after a lot of online research, so I expect it won’t let me down. I’ll update this post when I formed an opinion.

I may get commissions for purchases made through links in this post.

Introduction

Hi. My name is Eran and I’m a software consultant since I can remember myself. But this blog is not about me. It’s about something I care deeply about and want to share my experience of with you.

This blog is about how I’m endeavouring to optimise my life. Hopefully some of my experiences will apply to your life as well.

So, what do I mean by optimising my life? Quite a few things, really. I mean automating menial tasks so that I don’t have to spend time and the cognitive drain that ensues. I mean improving my experience when menial tasks are unavoidable. I also mean improving myself so that I can do things better, both at work and at home.

Now, these will be my personal experiences I’ll be sharing with you. I don’t believe there’s a one-fits-all solution to our daily problems. I’m hopeful some of my advice will be relevant to yours. If any of it is – I’ve achieved my goal.

Enjoy your read!

Want to reach out? You can find me on LinkedIn.