Dec 26, 2013

Fix for Apple's Latvian keyboard layout

Programmers, who use Apple computers with Latvian keyboard layout may find it disappointing that the single quote key is made a "dead key". (Dead keys let you type characters that are not usually on the keyboard, such as ā or š). Single quote is often used in programming, so having it back in the Latvian keyboard layout would be an advantage.

I made a little addition to an excellent KeyRemap4MacBook app, which can remap many keys on the keyboard. My additions include:

  • Change dead key (single quote) back to single quote
  • Change backquote to quote (does not work in Terminal unless you deselect "Use option as meta key" in Terminal's Settings>Keyboard)
  • Use tilde key properly
  • Map Option+Shift+2 to produce a euro sign as on the US keyboard (the default Option+Shift+Q) works as well.

The fix is here. You can install it by pasting the relevant part to your private.xml. See  KeyRemap4MacBook for more information about private.xml.

Oct 31, 2013

Three useful Subversion commands

If you still use Subversion, you may want to know these three commands:

svn diff -c revision

This will show you modifications made in the particular revision.

svn diff -c revision --summarize

This will show you what files were modified in the revision but not the content of the change. Useful if you just need a list of files.

svn merge -c revision source_url wc_path

This will make a "cherry-pick" (hello, Git users!): pick up the content of that revision and merge only it into your working copy.

Oct 30, 2013

OS X lid sleep and Google Chrome

Found a problem on Mountain Lion & Mavericks: if you use Google Chrome, you may experience Macbook Pro sleep issues when closing the lid. It may take several minutes until MacBook goes to sleep. Testing if the issue exists is easy: just keep Chrome running (preferably with heavy content, like YouTube) and close the lid. If the sleep indicator does not start to "breath" in 2-3 seconds, you have the issue. Open it, quit Chrome and try again. You will see that MacBook goes to sleep much faster. Apple Safari has no such issue.

Why this can be a problem for you? Because when you are on the move, you need every bit of power you can scrap from the battery. Even though OS X Mavericks increased battery life for me from 4h to 6.5h, I still prefer to save all the power that my battery has.

So I migrated from Safari. Incidentally, it is faster than Chrome in Mavericks.

Oct 27, 2013

Assigning a backtick key as a shortcut to the Safari Reader

Safari includes a nice feature called "Reader". This is a feature very similar to what Readability extension in Google Chrome do: it takes the main content of the page and presents it for easier reading by stripping all other elements of the web site and changing the font to a big nice and easily readable.

All is good but Google Chrome uses a back tick key for invoking Readability while Safari uses Command+Shift+R, which is much less convenient (try that on your keyboard!). Normally you can change this in the OS X Keyboard settings. The problem is: that panel accepts only keys with modifiers (you cannot have anything without a Command, or Alt, to Control). So how to add a back tick there?

Terminal comes to help (this is one line below!):

defaults write NSUserKeyEquivalents -dict-add "Show Reader" "\`"

This command will set the back tick as a reader invoker. Back slash is needed there, it escapes the back tick for the Terminal and will not be a part of the final key sequence.

Jul 7, 2013

"Book license"

Looking through some old, historical software packages, found a very interesting license, called "Book license". No full text anywhere, unfortunately, so just an excerpt:

"You must treat this software just like a book ... [it] may be used by any number of people ... may be freely moved from one computer location to another, so long as there is no possibility of it being used at one location while it's being used at another."

Nice, isn't it?

Jul 6, 2013

Break in using the "signup key"

Today I read several reports about a break in technique that attackers used to compromise user accounts of several large online companies. Two of them, for example, are Facebook and Dropbox. I read also about others because I was interested if there are more cases like this.

The general idea is that the service gives you, a legitimate user, a chance to change access to your account by sending you a link with a profile id and a certain key, which looks like 27934e96d90d06818674b98bec7230fa (this particular key is not random, if you search for it, you will find another interesting information to educate yourself). Next the code takes the key, searches the database for the key. If the key exists, it signs-up/resets/resends/does-whatever-else-to-give-you-the-access to the profile identified by the profile id in the link.

Can you spot the problem in this logic?

The code checks that the key exists but it does not check that it belongs to the profile in question. So if you got the key, you can reset anyone's password and get access to his account only by using a different profile id. This seems like an obvious error. Yet the programmers of many large companies fail to see it and implement the "reset" functionality correctly.

Now you know what to avoid in your implementation. Are you running to patch your code already? You should!

Mar 19, 2013

A PHP client for TYPO3 TER

A useful piece of software from Elmar Hinz: a command line utility for TER, which can upload TYPO3 CMS extensions to TER and do many more, which you cannot do in the TYPO3 Extension Manager.

Get it here.

How to calculate 1+1 using the “nice code™”

use SimplePHPEasyPlus\Number\NumberCollection;
use SimplePHPEasyPlus\Number\SimpleNumber;
use SimplePHPEasyPlus\Number\CollectionItemNumberProxy;
use SimplePHPEasyPlus\Parser\SimpleNumberStringParser;
use SimplePHPEasyPlus\Iterator\CallbackIterator;
use SimplePHPEasyPlus\Operator\AdditionOperator;
use SimplePHPEasyPlus\Operation\ArithmeticOperation;
use SimplePHPEasyPlus\Operation\OperationStream;
use SimplePHPEasyPlus\Engine;
use SimplePHPEasyPlus\Calcul\Calcul;
use SimplePHPEasyPlus\Calcul\CalculRunner;

$numberCollection = new NumberCollection();

$numberParser = new SimpleNumberStringParser();

$firstParsedNumber = $numberParser->parse('1');
$firstNumber = new SimpleNumber($firstParsedNumber);
$firstNumberProxy = new CollectionItemNumberProxy($firstNumber);


$secondParsedNumber = $numberParser->parse('1');
$secondNumber = new SimpleNumber($secondParsedNumber);
$secondNumberProxy = new CollectionItemNumberProxy($secondNumber);


$addition = new AdditionOperator('SimplePHPEasyPlus\Number\SimpleNumber');

$operation = new ArithmeticOperation($addition);

$engine = new Engine($operation);

$calcul = new Calcul($engine, $numberCollection);

$runner = new CalculRunner();


$result = $calcul->getResult();
$numericResult = $result->getValue(); // 2

Example from, thanks to Mathias Schreiber for the link :)

Conclusions? Do not overdo it. Simplicity will save the world. Just do a "1+1", not the framework for calculating it.

Mar 11, 2013

Bad coding

Never code like this:

function hasContentElements($pageId) {
    $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*',
       'pages', 'uid=' . $pageId ...);
    return $rows;

function processContentElements($contentElements) {
    foreach ($contentElements as $contentElement) {

$hasContentElements = hasContentElements($pageId);
if ($hasContentElements) {

Why is this bad? Because:
  • Function name hasContentElements suggests that it only checks that the page has content elements. It should not retrieve them. Imagine if there are 100 elements on the page. How much memory would it take just for a simple check like that?
  • The variable is named improperly too. "has" means a boolean value!
  • Using the variable with such name is misleading here. Unless you see and remember what the function does, you can make wrong assumptions about the logic of the processContentElements function.
When coding, please, choose proper names for all your code elements. If you have to check for existence of database records, do not fetch them, use COUNT(*) instead. That makes a great difference in terms of performance and memory usage.

Showing the current Git branch in a shell prompt

The following commands in ~/.bash_profile will show you on what Git branch you are and if there are dirty files there:

source /opt/local/share/doc/git-core/contrib/completion/git-completion.bash
source /opt/local/share/git-core/
export PS1='\h:\w \[\033[1;36m\]$(__git_ps1 "[%s] ")\[\033[1;37m\]\$ '

This will show the branch in the cyan color and only in the directory, where you checked out the project. If there are dirty files, it will show an asterisk after the branch name.


Atlas:~/Projects/TYPO3/TYPO3_6-0 [issue_46000 *] $

Mar 4, 2013

Quote #1

"There's nothing of any importance in life – except how well you do your work. Nothing. Only that. Whatever else you are, will come from that. It's the only measure of human value."
Francisco d'Anconia

Feb 28, 2013

Blah-blah #3

One wife tells her husband (a programmer): "Go to the shop and buy sausages. If there are eggs, buy ten". The programmer comes to the shop, dialog:
- Do you have eggs?
- Yes.
- Than give me ten sausages.

Yep. We really think like that, dear wives :)

Feb 27, 2013

Speeding up OpenOffice/LibreOffice

I had major problems with OpenOffice and its clone: LibreOffice. When I launched OpenOffice, it took about a minute for it to start. With LibreOffice the start was fast but opening each document took about 15 seconds of waiting.

I took OS X Activity Monitor and found that both apps spend all this time waiting in a call to gethostbyname. The call before that was a call to get the name of the local host. So both apps first tried to get the name of the local host and than to resolve its IP address and that did not work well.

Feb 26, 2013

Some photos of Uetliberg, Zurich, Switzerland

You can check some of my photos in this album on Facebook.

Google Chrome and Apple Time Capsule

If you back up your Mac using Apple Time Capsule and you use Google Chrome, you will notice that Time Machine sends around 300MB to the Time Capsule each time. This is because Google Chrome changes a lot of large file each time when you navigate to a new page.

To Solve the issue, go to the Time Machine properties and exclude ~/Library/Application Support/Google/Chrome from the backup. If you do not like the idea to loose data, just sign in to your Google Account with Chrome and it will ask you to set up a sync. Sync will send most of your data Chrome to Google and it can be stored in the encrypted form if you tick the corresponding box in settings. If you do not mind that, you can restore your Chrome in case of failure.

Feb 25, 2013

Blah-blah #2

– Why is it called "beta"?
– 'Cause it's beta than nothin'.

Sorry. Could not resist.

Feb 24, 2013


From one framework docs: "Before describing the configuration aspects of components (...), component types and implementations are described, since it is aspects of the component type that are configured by components – and the configurable aspects are defined by the component type.".

Reminds me something. Just can't remember what...

Feb 21, 2013

SVN: how to see only modified files

When you work with a command line SVN client, you may find its output too clattered, especially if you have a lot of externals or generated files that you do not commit (such as in typo3temp/ or uploads/).

To see only modified files, you can use egrep like this:

svn st | egrep '^M '

Feb 14, 2013

TYPO3 at GitHub

Some of you may know that there is a mirror of the official TYPO3 GIT repository at GitHub. It is quite difficult recently to get patches through the official review system, so I decided to work on GitHub from now on. Here is my fork of the official repository. I plan to add there patches I do for Snowflake as well as my own enhancements. I will merge official code into this fork from time to time.

This is not an attempt to fork entire project and go "my own way". This is an attempt to enhance TYPO3 using the patches that do not pass the official review system. I plan to do performance improvements as well as other enhancements. Think of it as of an experiment :)

I will continue patch reviews in TYPO3 Gerrit as before.

Feb 12, 2013

Speeding up Samba access in OS X

The following Terminal commands will help you to speed up the access to Samba shares. Note that one of command will report a error in recent OS X versions. You can ignore that error safely.

sudo sysctl -w net.inet.tcp.mssdflt=1460 
sudo sysctl -w net.inet.tcp.sendspace=262144 
sudo sysctl -w net.inet.tcp.recvspace=262144 
sudo sysctl -w net.inet.udp.recvspace=74848
sudo sysctl -w net.inet.udp.maxdgram=65535
sudo sysctl -w net.inet.tcp.rfc1323=1 
sudo sysctl -w net.inet.tcp.newreno=1 
sudo sysctl -w net.inet.tcp.always_keepalive=1 
sudo sysctl -w net.inet.tcp.keepidle=3600 
sudo sysctl -w net.inet.tcp.keepintvl=150 
sudo sysctl -w net.inet.tcp.slowstart_flightsize=4
sudo sysctl -w net.inet.tcp.strict_rfc1948=1
sudo sysctl -w net.inet.tcp.delayed_ack=1