The Struggle of Breaking Habits

Lately, I've been realizing that while I enjoy drinking beer, the pros don't outweigh the cons. When I've got beer around the house, I tend to drink it. It was becoming a habit and I would drink a few beers every day after work. It was an activity that I spent too much time and energy on, rather than being a nice treat. Now, instead of buying beer I just keep a few cans of seltzer in the fridge. They're cheaper than beer and have a lot less calories. I find that I am able to sleep better also, without my brain being clouded by liquor.

When I first started trying to break the beer habit, I had a really hard time sticking to it. I like beer, and it's very easy to make excuses that allow me to justify drinking. I had to come up with some techniques to motivate myself to really knuckle down and quit the sauce.

The Sobriety Counter

I found that if I were to count how long it has been since I had a drink, it makes it easier to maintain my good habits. Counting the days without drinking ends up acting like a "high score" that I want to beat. I decided to write a little program that would remind me how many days I've been sober for. I use Unix, so I decided I'd stick this program in my profile so whenever I open a new terminal, I get a reminder. It looks like this:

Screenshot of the sobriety counter

Here's the source code, in C. Feel free and use it however you like. I am still tinkering around with the program from time to time, so I'll try and keep it updated but no promises.

		/* Dinky little timer */
		#include <stdio.h>
		#include <time.h>

		/* Define the eight ANSI colors and the reset sequence.

		#define BLK   "\x1B[30m"
		#define RED   "\x1B[31m"
		#define GRN   "\x1B[1;32m"      /* the 1; sets the mode to bold. */
		#define YEL   "\x1B[33m"        /* I only changed it in one place because */
		#define BLU   "\x1B[34m"        /* this program only uses one color. */
		#define MAG   "\x1B[35m"        /* TODO: move color definitions into a sub */
		#define CYN   "\x1B[36m"
		#define WHT   "\x1B[37m"
		#define RESET "\x1B[0m"

		int main(int argc, char *argv[])
		        /* August 30, 2016. I think this one'll stick! */
		        struct tm start = {
				.tm_year = 116,
				.tm_mon  = 7,
				.tm_mday = 30,
			time_t beginning = mktime(&start);
			time_t now = time(NULL);
			double diff;
			diff = difftime(now, beginning);
			printf("It's been " GRN "%.0f" RESET " days.\n", diff/86400);