Tips and Tricks

These posts are little tidbits I’ve picked up over the course of 1.3 decades of programming. Each is listed with the approximate number of hours per year it saves me. I hope they help you too.

Most Recent Tips

Check Braces
Aug 3rd, 2015

algorithms brackets parsing
Annual hours saved: 1

The other day I needed a quick way to check a file for matching braces (and brackets and parentheses). I couldn’t find an easy way to do this on the command-line, so I wrote this simple Java class, and wrapped it into a .jar:

https://gist.github.com/pieman72/3e17b127849d3454f24e

It correctly identifies mismatched, unexpected, and improperly nested brackets (e.g. { ( } )). It is however, completely language agnostic, and will not notice if brackets are in a comment block or string, or are otherwise escaped. It just does a naive count.

Make Limits Java Heap Size on 32-bit Linux
Jul 23rd, 2015

aaaaargh! frustrating java make project management random
Annual hours saved: 2

Here’s a fun one. The following command:

java -Xmx2g Test

works fine when run from the command-line, but not when run from within a make recipe. It errors out with the following message:

Error occurred during initialization of VM
Could not reserve enough space for object heap
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

[Read More]

Terminal Color Support in Makefiles
Jul 21st, 2015

colors frustrating make project management terminal
Annual hours saved: 5

I just spent a good 20 minutes trying to figure out how to have a makefile conditionally color its output depending on the current terminal’s level of color support. Long story short, there were a number of make idiosyncrasies that I wasn’t expecting / had forgotten about. So, for future reference, here’s a quick recap:

  • Conditional syntax requires parentheses when comparing evaluated (i.e. $(...)) values
  • Terminal commands are invoked using the $(shell ...) function
  • The default shell is sh, not bash, so echo evaluates escapes by default
  • During assignment, := evaluates immediately, while = does not
  • As in most terminals, un-assigned variables evaluate without error as empty strings

[Read More]

Hex to ANSI
May 20th, 2015

ANSI colors conversion hexidecimal script terminal
Annual hours saved: 2

Gist – This is a pretty low-tech bash function to convert a hex color code (e.g. #f83a22) to an ANSI foreground or background color (e.g. \e[38;5;202m).

Your E-Sheep:

( change )

Recent Posts:

10/14 - ADHOC Changelog
8/19 - And now… random puppies!
8/3 - Check Braces
7/23 - Make Limits Java Heap Size on 32-bit Linux
7/21 - Terminal Color Support in Makefiles

Search
Top Tags:

aaaaargh! algorithms automatic awesome colors config development environment documentation frustrating java linux make parsing project management random syntax-highlighting terminal types

Random Quote:

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors.
anonymous (variant of original by Phil Karlton)

Powered By:
License:

2017 - Creative Commons 3.0