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

dwc_otg.speed=1

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

Fix Finder’s contextual “Services” menu

I sometimes add or remove “services” to my ~/Library/Services directory. Unfortunately this alone doesn’t make the changes being reflected in the menu…

It might be caused by the fact that I keep things I want to have on all machines in a Dropbox folder and link to it. Or it may be due to some other reasons. In any case. I am not alone as this old hint shows. It was posted in the times of the OSX version 10.6. At the time of writing I use 10.9 and the problem remains. Luckily almost the same solution applies. The only difference is that one has to add an option to the command:

/System/Library/CoreServices/pbs -flush

should do the trick and bring your “Services” menu back to what you want it to be.

From the

$ man pbs

pbs is an agent for the Services menu.  It scans for and vends available Services, to populate the Services menu [and] is NOT related to the pasteboard.

Who would have guessed?

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

HTTP query strings in Laravel routes

So you read the documentation back and forth, and again, and even more again. And you still can’t make your

Route::get('myroute?querystring=myquerystring', function()

work?

Well – you don’t find it in the docs but what you have to do is:

Route::get('myroute', function()
{
    $myvariable = Input::get('myqueryparameter');
    // do whatever you want with the variable now
});
Posted in Coding | Leave a comment

Why git is sometimes more gitty than any other git you are ever about to encounter…

So you work on a project which is version controlled and moreover it is version controlled by the almighty git himself. No matter whether you just got around all the teething problems and a steep learning curve of using git or you are a seasoned git professional – at one point or another you may find yourself in a situation where you want (or need) to:

No problem – you say? Sure – no problem as you can see if you follow the links above – nobody has ever got any problem with any of those operations. And no – using

$ git --follow

is not a solution either. Neither one knows when/where to try using some extra command line switches nor can one do it with non-command-line interfaces.. And no, unless you are a git geek, don’t even try to follow the discussions on those topics out there. The closest to something, which I felt could somehow work were a few discussions involving “filter-branch” command of git but God only knows what those dudes were really talking about. You know, this single big PITA alone can make one scream “GIVE ME MY SUBVERSION BACK!!!”

And you think there are no heroes anymore these days, don’t you? I tell you – There ARE! This awesome dude somehow made something out of this whole pile of conflicting, half-truth, semi-baked, scruffy-looking “advices” or just studied the matter on his own😉 and came up with a shell script, which does the hardest part for you. I tried it. Sure I made a fresh pull to be up to date as action zero. Then backup of the whole directory first, then –dry-run second, then

$ git-mv-with-history myfile=mysubdirectory/

Rewrite cbb1a3111387949c0efde1540aa4565918f12f9b (1/117)

Rewrite ebb01ba7b2454a83f4e1b916384735a76cea15f9 (2/117)

[...]

Rewrite 18222fce98839724338fcdc833f3e307875eb6eb (115/117)

Rewrite 0b229d7fefa417f5b2e4975a87ea5ae69a2ebfe0 (116/117)

Rewrite e1ea07ce21b4a7ec6ba8e28dc1f5baba512bdbf2 (117/117)

Don’t forget the trailing slash if you want to move the file to a subdirectory or you may end up with your file being renamed into what you wanted a directory to be named!

I eyeballed all the files (checking them against the original clone of the repository) and the git status results..

silverdr$ git status

On branch master

Your branch and 'origin/master' have diverged,

and have 110 and 110 different commits each, respectively.

(use "git pull" to merge the remote branch into yours)

DON’T! DO! IT! I meant don’t “use git pull to merge the remote branch into yours”! Unless you want to ask for trouble, that is. Don’t try to simply push the changes either (but since your push will be most probably rejected anyway – it shouldn’t at least do much harm if you insist and try anyway). Now – what I did and it worked (but remember: YMMV!!) was:

silverdr$ git push --force origin master

Counting objects: 428, done.

Delta compression using up to 8 threads.

Compressing objects: 100% (398/398), done.

Writing objects: 100% (409/409), 562.33 KiB | 0 bytes/s, done.

Total 409 (delta 154), reused 0 (delta 0)

To https://github.com/yourowner/yourrepository.git

+ e1ea07c...8879fe2 master -> master (forced update)

silverdr$

YES – there are still heroes. Even these days…

Posted in Coding, Git, Rants | Tagged , | 3 Comments