Montag, 17. Februar 2014

Chrome Browser: How to emulate a touch screen

The Chrome Browser integrates a nice feature to simulate multiple mobile devices or a touch screen.

First of all you have to enable the "Emulation" view in the console drawer. Open the Developer Tools and click the settings icon:

Next, switch to the "General" panel and enable "Show emulation view in console drawer"

Now close the settings and press the ESC (Escape Key) and switch to the "Emulation" Panel (2). The "Sensors" menu (3) let's you enable the "Emulate touch screen" (4) checkbox. That's it!

Freitag, 7. Februar 2014

Git Dropbox Remote Repo

With git you can easily use any directory as an remote repo. Dropbox offers a lot of free space and automatically backups files so why not using dropbbox as a git remote repo :-)

This tutorial should also works with Google Drive and Microsoft SkyDrive. Please make sure that the paths provided below match your local Dropbox / Google Drive / Skydrive folder.

mkdir -p ~/Dropbox/git/my-project

Initialize Git:

git init --bare ~/Dropbox/git/my-project

Go to your project and add the new created dir as remote:

git remote add origin ~/Dropbox/git/my-project

That's it! Now you can push your repo to your dropbox folder:

git push origin master

Donnerstag, 6. Februar 2014

PHP Memcache list / get keys

     * @param string $server
     * @param int $port
     * @param int $limit
     * @return array
    public function getMemcacheKeys ($server, $port, $limit = 10000)
        $keysFound = array();

        $options = $this->_options;
        $server = $options['servers'][0];
        $memcache = new Memcache;
        $memcache->connect($server, $port = 11211, 5);

        $slabs = $memcache->getExtendedStats('slabs');
        foreach ($slabs as $serverSlabs) {
            foreach ($serverSlabs as $slabId => $slabMeta) {
                try {
                    $cacheDump = $memcache->getExtendedStats('cachedump', (int) $slabId, 1000);
                } catch (Exception $e) {

                if (!is_array($cacheDump)) {

                foreach ($cacheDump as $dump) {
                    if (!is_array($dump)) {

                    foreach ($dump as $key => $value) {
                        $keysFound[] = $key;

                        if (count($keysFound) == $limit) {
                            return $keysFound;

        return $keysFound;

Dienstag, 4. Februar 2014

Must Have Git Aliases

Git Shortcut

This is first thing you should do. Aliasing git as `g` will save you a lot of typing. After this symlink creation you can access git with only typing `g` in the command line.
$ sudo ln -s `which git` /usr/bin/g
I'm using git now for some years and over the time I came up with a long list of git aliases. Git is great and can give you a great coding experience with it's customizable shortcuts.

Your .gitconfig file is located in your home dir. All examples can be added to the [alias] section in this file.
$ nano ~/.gitconfig

Basic Aliases

  co = checkout
  cp = cherry-pick
  p  = pull
  squash = merge --squash
  st = status
  df = diff
  b = branch

Advanced Usage

Revert a file

  rv = checkout --


  ours = checkout --ours --
  theirs = checkout --theirs --


  sl = stash list
  sa = stash apply
  ss = stash save

Danger! Cleanup working dir

This alias will reset all modified files!
cleanup = !git reset --hard && git clean -f 

List all aliases

alias = config --get-regexp 'alias.*'

Log One Line

logol = log --pretty=format:"%h\\ %s\\ [%cn]"

Search in files

search = "grep -Iin"


vup = !vagrant up
vsu = !vagrant suspend
vss = !vagrant ssh
vde = !vagrant destroy
vpr = !vagrant provision

Sonntag, 2. Februar 2014

PHP Segmentation fault

This is the worst case for every php developer when hacking some code - your script runs not as expected and you get a simple message saying "Segmentation fault".

Here are the steps you can do, to track down this error.

Some simple tips to start

- Use a debugger like ZendDebugger or XDebug to find the line of code causing the error.

- Disable PHP's internal garbage collector. The garbage collector is known to often cause segmentation faults. If disabling will help you are probably found an internal reference counting bug in the garbage collector
ini_set('zend.enable_gc', 0);
- Look for recursion in your code. PHP throws a segmentation fault if you have a infinite recursion in your code

- If you have apc installed sometimes it helps to empty the cache or disable the cache

Use strace

If php runs on Linux or Mac OS you can use strace/dtruss to hook into the process and see what's happening. Strace can be installed on Debian by running

apt-get install strace

Run phpunit with strace

$ strace phpunit

Attach strace to a already running process

$ sudo strace -s 256 -p <PID>

Run any php script with strace

$ strace php index.php

Attach strace to a running cgi process

$ ps axf | grep php5-cgi # lists all running processes
#If more than one process is found you can use the tool php-strace (see below) to trace all processes at the same time. If only one process is found you can use the following command to trace:
$ sudo strace -s 256 -p <PID>
#For debugging purposes I recommend to limit the cgi processes running to one, so you can be sure to hook into the right process which is serving your browser.
# The number of running cgi processes can be edited by editing the file /etc/php5/fpm/pool.d/www.conf .


Also you can try to run the script inside of gdb. On Debian gdb can be installed using the command "apt-get install gdb"

gdb --args php /usr/bin/phpunit
#inside gdb enter:
set env MALLOC_CHECK_=3
#then enter:


I wrote a tool for easy monitoring running cgi proccesses on a server or a developer box.

php-strace helps to track down segfaults in running php processes. It starts a new strace instance for every running php5-cgi or php-fpm process to monitor whether a segfault happened.


To get started, visit my github page.


php-strace V0.3 available:

Samstag, 1. Februar 2014

How to change the terminal title with a script

Save the following lines in a file called
    #!/bin/zsh -f
    echo -ne "\033]0;$@\007" 
and make it executable:
    $ chmod +x
To change the title simply call
    $ ./ “New Title”