Feb 18, 2015

Getting OS X keychain password from terminal

Sometimes I have to run curl queries in the terminal for hosts that have password protection. If I do not remember a [usually random] password or forget that the site is protected, I get a 401 response:

Atlas:~/Projects/**** [development] $ curl  -I 'http://host.example.com/'
HTTP/1.1 401 Authorization Required
Date: Wed, 18 Feb 2015 09:41:18 GMT
Server: Apache
WWW-Authenticate: Basic realm="Preview"
Vary: Accept-Encoding
Content-Type: text/html; charset=iso-8859-1

Than I have to go to my keychain to look up the password. Thanks to Alfred, it is easy to invoke the keychain but it means switching applications and entering the password for the keychain. I looked for the way to do this from terminal.

Here is the command:

rsnapshot, anyone?

Recently I came across rsnapshot as a backup solution that can do hourly, daily and monthly backups. I am interested in any experience but it is hard to find except for this.

Does anybody have experience with it?

Feb 13, 2015

bash completions for my "Projects" directory

Linux bash shell has a nice feature called “completions”. You type a command and you press a TAB key. This will bring you a list of options that the command supports for completions. You type the first letter of any option and press TAB again. Now the list is reduced only to options starting from that letter. And so on.

I use terminal quite a lot. All projects for my work are located under ~/Projects/Snowflake (I work for snowflake productions gmbh). To quickly go to that projects from terminal I added the following to my ~/.bash_profile:

alias "cds=cd ~/Projects/Snowflake; cd "

Now I can just type cds projectname and get to ~/Projects/Snowflake/projectname. But I have to remember project names. Many of them are German and it is hard to remember for me. Why not use autocompletion for that? So I made a new file in /opt/local/bash_completion.d:

Feb 12, 2015

GIT: show log since the branch was created

Quite often I have to use a git log command to show what was made in the branch:

git log development...feature/add-solr-news-search

One thing that I'd like to know is about using short notations. If I am on feature/add-solr-news-search, than I can use this:

git log development...

Git will be smart enough to figure out that it is about the current branch. Sadly it is not smart enough for this:

git log ...

I hoped it will figure out that I want a log from the parent branch to the current branch...

How good are you at Git?

Find out using Git Game! You need to clone the repository and look at README.md for the next clue. Ten levels, getting more difficult with each level.

Can you pass?

Feb 11, 2015

Quality is no compromise

When it comes to the code quality, there are no compromises. You either write good code or bad code. There is nothing in the middle.

Many years ago I read an excellent book about code quality named “Clean Code”. That book goes to extreme and not all recipes are acceptable but I read and re-read, thought again and again until I set my own rules to writing code.

I think I have a certain advantage over people, who start using PHP as their first programming language. I started with Pascal and used assembler in parallel during my first five years of programming. Neither allows compromises. Pascal is very strict and assembler is just a razor sharp to errors: one minor error and your head is off. Next I used C++, which was more relaxed but than coded in Java for a couple of years, which was also very strict programming.

PHP is very relaxed when it comes to quality standards. You can assign a string to a variable and compare it to the number or to virtually anything else. You can assign any type to any variable, return anything from the function or do not return anything at all. If the programmer did not have good practice with other languages, he may start writing code, which is not that good. It is not necessarily true but it happens.

These things came to me today when I tried to use my TYPO3 extension named sentry. This extension automatically catches all kind of PHP warnings and exceptions (that you do not normally see) into a centralised repository when warnings and exceptions for various projects can be viewed, analysed and processed:

Details screen for the first warning looks like:

Feb 10, 2015

SVN one-liner

Using SVN command on the old host to find modified files:

svn st | grep '[^MAD\?]'

Looks mad? ;)