Bash: Underscore a String

I find it weird that I did not find a ready made script for this immediately through a google search. So this is what I arrived at after some digging:

#!/usr/bin/env bash
read input
str="$(echo $input | tr '[:upper:]' '[:lower:]')"
printf ${str// /_}

Use it with stdin:

echo "Underscore Me" | underscore
underscore_me

I use this in TextMate when I need to convert normal english string/text into a parameter/key.

Automate everything

To automate everything, even the smallest things (scripts), is a lesson I continuously learn while doing programming.

Let’s take MySQL and setting up replication for example. For years I would rely on googling and then copy and pasting the same few SQL commands to configure the master, slave and start the replication. Forward to around now, while crafting the Percona Docker Container I finally decided to encapsulate the process into 2 simple to use and remember commands.

Now, I can just exec into my MySQL container and type:

replication_master_sql

To get the SQL to execute on the master, tailored for the particular configuration. Once I execute this SQL on the master, I finish the whole “process” and start the replication with something like:

start_replication mysql-bin.000001 107

Where the last two arguments are the binlog position of where to start the replication.

When I first used this in production, the experience was like night and day compared to looking up the correct queries and then modifying them according to my setup. Thus—automate everything. It pays of every time you need it afterwards.

Recent projects

A few days ago I’ve launched a new website for the Equal Money System project. The project is about a complete social and economic change, worldwide.

I really enjoyed doing the graphic design and I am satisfied with how it turned out. The feedback of the community is also very positive. Programming wise it was nothing advanced – it’s backed by the excellent WordPress, which I am again “falling in love” with.

Equal Money For All