One – liner to batch rename files with regex-remove part of the filename

Don’t read this post. It’s only for me so that I don’t forget it ūüėČ

After a long fight with bash, find, sed, … Here is the one – liner:

for i in $(find -E . -regex '(.*[a-zA-Z]{3}[0-9]{3}[a-zA-Z]{3}_[0-9]{9})(\.[0-9])(\.[jJ][pP]([eE])*[gG])') ; do mv -v $i $(echo $i | sed -E 's/(.*[a-zA-Z]{3}[0-9]{3}[a-zA-Z]{3}_[0-9]{9})(\.[0-9])(\.[jJ][pP]([eE])*[gG])/\1\3/') ; done

Given a set of JPEG files, which contained duplicates with .1¬†thrown-in before the final dot and the ending of the filename, replacing the original with the newer ones (those with .1‘s) seemed like a trivial task‚Ķ until I tried to actually do this. In the end it came to using “modern regex” with matching groups and refer to those groups I wanted to retain. These are \1¬†and \3¬†concatenated in the \1\3¬†part of the sed¬†replace pattern. Group \2¬†(the .1) didn’t make it there.


Posted in bash, Coding | Tagged , , , , | Leave a comment

One-bash-liner to get rid of .WMV container

For reasons known probably to only a very few, selected ones – videos contained in the “.WMV” container seem to have occasional problems with seeking and positioning when played back with XBMC (or “Kodi” if you adapted to the brave new name). To alleviate the problem I eventually wrote a one-liner that copies all video and audio streams from “.WMV” files into Matroska containers:

SAVEIFS=$IFS; IFS=$(echo -en "\n\b"); for i in $( ls *.wmv ) ; do ffmpeg -i "$i" -c copy "${i%.*}".mkv ; done ; IFS=$SAVEIFS

CD into the directory with the video files you want to process and go. Obviously you need to have a working ffmpeg installation first.

Posted in Video | Tagged , , , | Leave a comment

Rails derailed again (and again)

Executive summary (aka TL;DR)

  1. Rails docs suck… erm, no. I mean they are great but most probably written by people who never actually had to use them.
  2. If you want to follow Rails Guides and install a fresh Rails environment on a vanilla Ubuntu 16.04LTS you need at least the following dependencies installed before you start:
    • ruby-dev
    • zlib1g-dev
    • libsqlite3-dev
    • gcc
    • make
    • g++

Continue reading

Posted in Rails, Rants | Tagged , , , , | 4 Comments

PHP’s “associative array”: removing blacklisted or keeping whitelisted keys

Yup, if there is one language I loathe more than PHP, it’s Javascript‚Ķ but this here is about PHP and how to either remove unwanted keys from an “associative array” (as they call it in PHP world) or leave only those, which you want to stay – in one shot.

Remove unwanted keys:

$my_cleaned_array = array_diff_key($my_dirty_array, array_flip($array_of_blacklisted_keys));

Keep welcome keys:

$my_cleaned_array = array_intersect_key($my_dirty_array, array_flip($array_of_whitelisted_keys));
Posted in Coding, php | Tagged , | Leave a comment

openvpn inactivity timeout (–ping-restart) restarting

So, there’s a nicely configured OpenVPN server, there is the client config that is proven to work with all your colleagues around and everything “just works” … or maybe, rather “just needs more work”? was it?

If you happen to suffer from irregular but painful unreliability of your OpenVPN connection on a perfectly reliable network link and in the logs you regularly happen to see something like:

 [server] Inactivity timeout (--ping-restart), restarting

chances are that you have fallen into the same trap as me, and another OpenVPN user. What trap? I happily tried to use the same config (including my certificate) on three¬†machines… nothing wrong you say? Sure, I can use it on both my desktop and laptop and everything should be fine! True, I thought so too. Until I left my work desktop on and connected in the office, I connected my desktop at home and then, since thing didn’t look nicely I tried on the laptop too… then I went to the office to check how it works there (hint: stopped working too) and…

Yes, as one user called ‘krzee’ wrote:

your clients are fighting each other for the right to be [your CN]
there is a command to let the same cert connect multiple times… but it was only intended for testing purposes, or when using username auth in addition to certs. making certs for each client will fix your problem

So – if you use the same certificate on multiple clients, be sure to disconnect before leaving the machine unattended. Or – better – create and sign different certificates for every client / machine you intend to connect from.

Posted in Coding, DevOps | Tagged | Leave a comment

How come this crap creeps in for so many years?!

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
 LANGUAGE = (unset),
 LC_ALL = (unset),
 LC_CTYPE = "UTF-8",
 LANG = "en_US.UTF-8"
 are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory

First of all I really have a hard time getting around the fact that I see this on every default installation of Ubuntu (I bet I saw this on Debian too) for so many years and versions…

And I’ve seen a number of useless suggestions on how to fix it. dpkg-reconfigure this, dpkg-reconfigure that, install this, remove that. Generate this, edit that. And so on.

$ sudo echo 'LC_ALL="en_US.UTF-8"' >> /etc/environment

fixed the crap at last… at least for me… YMMV…

P. S. You can possibly use other values, like “C” or whichever locale you are using instead of “en_US.UTF-8”, which may make some more sense your particular environment.

Posted in Coding, GNU/Linux, Rants | Tagged , , , , | 3 Comments

Raspberry Pi, hub USB 3.0, error -71

If you have a USB 3.0 hub connected to your Pi and devices plugged into this hub are not configured properly, you check the logs and you see something like

device descriptor read/64, error -71

around USB activity – chances are that you ran into the same problem as several people, including the author of these words.

The conclusion is that USB 1.1 devices, connected to USB 3.0 hub are not working correctly in such configuration, due to a bug here or there, even if the very same hub, with the very same devices works well when connected to something else than Raspberry Pi. A workaround to this is to add an entry inside /boot/cmdline.txt


which forces the whole bus to 12Mbit/s USB 1.1 speed and lets you configure and use the devices.

Posted in GNU/Linux | Tagged , , , , | Leave a comment