Building kube-state-metrics from source

Today I had to build kube-state-metrics Kubernetes extra metrics exporter for Prometheus monitoring system. I wanted to build it for specific Linux (kernel) version (in my case it was Alpine Linux 3.4), and I also wanted to build a specific version of kube-state-metrics – latest stable, which is 1.3.1 currently.

I didn’t want to get latest version from master as I was not sure about it’s stability and I would have hard time re-creating the build since master would move on over time, so simply making “go get” wasn’t an option.

The process turned out to be a bit tricky – I wanted to use docker to have proper version of Go lang for Alpine Linux 3.4 while I’m on a macOS myself, but the makefile of kube-state-metrics also uses docker (for whatever silly reason that is), so I needed to build it using go build.

As it turned out, I had to do two things – install Go into Alpine 3.4 (which took some copypasting from where they have Dockerfile for Alpine 3.7 – contents of which I used) and then get the paths right for GOPATH in order to build kube-state-metrics.

Here’s the resulting Dockerfile: Continue reading


Drawing lots online

As a member of Toastmasters club I sometimes lead so-called Table-Topics in which I need to give participants tasks from a list of tasks – randomly, without repeats (unique task per participant).

I’ve used a free iPhone app in which I could configure the texts of tasks and which returned a random result on shaking phone. But I wasn’t satisfied with it. First of all it had a fixed amount of item slots so I had to leave blanks for non-used slots, and often got blank instead of a result. And I was getting results that were already used – repeats – so I had to shake more and more until I got valid result. The number of slots was big enough though, but still it was also theoretically possible to have a need for more tasks than the slots in the app. So 3 downsides in total.

So I spent several hours to quickly code my own solution – in HTML+JS+CSS, so I could use it on desktop and on mobile easily.

Here it is:;;two;;three…

It’s all single file HTML+JS+CSS, no external libs are used, so it can be cached locally and used offline. All the data (list of items to choose from) is going into URL. This imposes a limit on total text length unfortunately, but for me that’s not a problem – hopefully won’t be a problem for you either. Otherwise storing data in URL only makes it very convenient – again, you can use it offline, and there’s no need for a server-side storage, which makes it all work faster.

I also tried to make UI touch-friendly, and tested it on my good old iPhone 4.

The source code is on GitHub:

A couple of screenshots from iPhone: Continue reading

BASH script and regexp of the day

Here’s my BASH script and regexp of the day.
I’m not particularly proficient in BASH scripting (in fact, not that proficient at all), so sorry if there are some obvious improvements to be made. But I suppose you can find the script useful anyway.

The purpose of the script is to get  values of a column of a CSV file by column name. The CSV file is comma-separated (not Excel style semicolon separated FYI) and may contain quoted values with commas, and double-quote escaped quotes (i.e “this is a value”,”this is another value with “” (quote) symbol”).

Parameters are: <file name> <column name>. Additional parameters -n or -u can be used to either output line numbers or output only unique values. Note: you can’t use both at the same time, -u takes precedence.

Also the script will output you the number of the column.

The script was written/tested against GNU grep (version 2.12 in particular). It doesn’t work correct for column #1 on OS X due to weird way BSD grep treats condition “^x{1}”. Installing GNU grep for OS X from sources like Rudix or Homebrew is recommended for Mac users.

You’re welcome (-:


for p in "$@"
     if [ "$p" == "-u" ]
     if [ "$p" == "-n" ]

colMatch=$(head -n 1 $1 | grep -E "(,|^).*$2[^,]*" -o)

if [ "$colMatch" == "" ]
	echo "Column not found."
	colNumber=$(head -n 1 $1 | grep -E "(,|^).*$2[^,]*" -o | grep "," -o | wc -l | grep -E "[0-9]+" -o)
	echo "Column number: $colNumber. Column name: $(head -n 1 $1 | grep -o -E "^((\"[^\"]*\")*,|[^,\"]*,){$colNumber}((\"[^\"]*\")*|[^,\"]*)" | grep -o -E '(^|,)((\"[^\"]*\")*|[^,\"]*)$')"

	if [ "$unique" == "true" ]
		tail -n "+2" $1 | grep -o -E "^((\"[^\"]*\")*,|[^,\"]*,){$colNumber}((\"[^\"]*\")*|[^,\"]*)" | grep -o -E '(^|,)((\"[^\"]*\")*|[^,\"]*)$' | sort | uniq
		tail -n "+2" $1 | grep -o -E "^((\"[^\"]*\")*,|[^,\"]*,){$colNumber}((\"[^\"]*\")*|[^,\"]*)" | grep $addp -o -E '(^|,)((\"[^\"]*\")*|[^,\"]*)$'

Example of usage with results (tested on Ubuntu linux):
Continue reading

Screen area to Animated GIF

Recently I’ve discovered that there is a plethora of platform-specific utilities that can repeatedly capture region of the screen and then save the resulting images as an animated GIF. To me this sounds like a perfect task for JVM, since JVM includes support for screen capturing and creating animated GIF images, and all this comes with cross-platformness.

Thus I took the time to implement such utility. And here it is:
Executable JAR of first complete release can be downloaded here:

Let’s start with the demo right away!
(UPD: see demo on Raspberry Pi at the end of the post)

Here is the GIF that shows the utility in action. This gif was produced by second instance of the utility capturing the screen part where the demoed instance was displayed. Nice, huh? I ran screen capturing while I ran screen capturing so I could capture screen while I capture screen (-;

Continue reading

Liferay 6 (5): get portlet content programmatically in hooked JSPs

Sometimes it is necessary to obtain a content of the portlet programmatically in hooked JSPs, but the APIs do not make it clear at all how to accomplish that.

There are some suggestions on the web on how this can be achieved, but the code seems to be somewhat complex, which makes it a problem to use in hooked JSPs.

For hooks there is a simpler method, but it relies on being executed in hooked JSPs by referring to some classes in portal-impl.jar:
Continue reading

Guitar frets notes map with Codea

Couldn’t find a pic where standard tuned guitar frets would be displayed as black+white piano keys. So I’ve coded a little script/app for that using Codea (IDE+runtime for coding for iPad using Lua):

This is 7-string (electric) guitar in Standard tuning (i.e. just like 6-string + 1 additional string for lower notes), ’cause I have a 7-string one – so I needed that additional string too.

Teh Code:

Yep, it also produces sounds when keys/frets are touched (with multitouch). Codea is fun.

Reinventing the wheel – custom Dates API

I’ve started on the re-implementation of command-line java calendar tool in order to provide support for relative dates and other features, and while working on it I got a bit carried away with implementation of what turned out to be no less that custom dates API+implementation.

It’s pretty basic, and was done more as an exercise than for any particular need, but still I believe some interesting concepts can be looked up from it.

Though not yet complete, the code of JCCal was already committed to GitHub: . The dates API+impl classes can be looked up there already (in package x.mvmn.util.dates). Please also check the README there for general explanations.

I won’t be doing much explanation here, since it would mostly be copy-pasting of the readme for general things, and copypasting of actual code for the details. As someone said, “The truth is in the code” – so I encourage anyone who is interested to actually look up the code.