Air Conditioner control via Apple HomeKit and desktop app

Summer is a good time to work a bit on DIY smart-home air conditioner (AC) controls.

If you happen to have WiFi enabled Cooper&Hunter and/or Gree ACs – you’re lucky, because those support an easy to integrate with protocol, details of which one can find here:

In order to do so using Java I’ve implemented my own library:

And using that library I’ve created two solutions for AC control – a desktop app that works great, and a HomeKit automation that is in a Proof-of-Concept state right now because of limitations and connectivity issues I’ve encountered using HAP (HomeKit Accessory Protocol).

Here’s how they look:

ACControl on macOS.png
Continue reading

ZSH completions for teamocil/itermocil

I’ve noticed that even with installed OhMyZSH I don’t get proper completions for an itermocil in Z-shell (ZSH) terminal – proper completions being list of names of files from ~/.teamocil folder, sans extensions.

I’ve looked at OhMyZSH plugins and wrote my own for itermocil – a file ~/.oh-my-zsh/plugins/itermocil/itermocil.plugin.zsh with this content:

_itermocil () {
  compadd -- `ls -1 ~/.teamocil/ | rev | cut -d "." -f 2- | rev`

compdef _itermocil itermocil

And added it to plugins environment variable in .zshrc.

However, while doing so I’ve noticed that my .zshrc already contained this line:

compctl -g '~/.teamocil/*(:t:r)' teamocil

Googling a bit revealed that (:t:r) modifier to * wildcard are the basename sans extension modifiers for wildcard expansion in ZSH.

Which meant all I really needed was the same line in my .zshrc again, only this time with itermocil at the end instead of teamocil.

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