Tuesday, September 13, 2016

Compile PHP modules on MacOS

On MacOSX, in order to compile modules such as mcrypt one may need to run the following before starting the configuration and compilation:

MACOSX_DEPLOYMENT_TARGET=10.6
CFLAGS="-arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp"
CCFLAGS="-arch i386 -arch x86_64 -g -Os -pipe"
CXXFLAGS="-arch i386 -arch x86_64 -g -Os -pipe"
LDFLAGS="-arch i386 -arch x86_64 -bind_at_load"
export CFLAGS CXXFLAGS LDFLAGS CCFLAGS MACOSX_DEPLOYMENT_TARGET

Then the compilation should continue as below:
$ cd php-5.4.24/ext/mcrypt
$ phpize
$ ./configure # this is the step which fails without the above dependencies
$ make
$ make test
$ sudo make install

Thanks to http://stackoverflow.com/a/8432855

Tuesday, May 03, 2016

Symfony - Navigation with "paginator"


{% if pagination.items|length %}
     {% set queryParams = pagination.params %}
     {% set pg = pagination.paginationData %}
     {% set itemStart = (pg.current - 1)*pg.numItemsPerPage + 1 %}

Records {{ itemStart }} - {{ itemStart + pagination.items|length - 1 }} of {{ pg.totalCount }}

{# array (size=16)
  'last' => int 2235
  'current' => int 1
  'numItemsPerPage' => int 9
  'first' => int 1
  'pageCount' => int 2235
  'totalCount' => int 20112
  'pageRange' => int 5
  'startPage' => int 1
  'endPage' => float 5
  'next' => int 2
  'pagesInRange' =>
    array (size=5)
      0 => int 1
      1 => int 2
      2 => int 3
      3 => int 4
      4 => int 5
  'firstPageInRange' => int 1
  'lastPageInRange' => int 5
  'currentItemCount' => int 9
  'firstItemNumber' => int 1
  'lastItemNumber' => int 9#}



   {% for entity in pagination %}
      ..
   {% endfor %}
{% else %}
   Your search returned no results
{% endif %}

{{ knp_pagination_render(pagination) }}

Wednesday, April 27, 2016

Shell script to scan folders and delete all but the most recent ones

root@server1 [~]# cat rm-releases.sh

#!/bin/bash

DIRECTORY="releases"

for i in $(ls -l /home | grep - | awk '{print $8}'| sed 's|[/]||g'); do
#  echo ${i%%/};

  if [ -d "/home/${i%%/}/$DIRECTORY" ]; then
    TARGETDIR=$(ls -t /home/${i%%/}/$DIRECTORY | head -1)
#    echo $TARGETDIR;
    for j in $(ls -l "/home/$i/$DIRECTORY" | grep - | awk '{print $8}' | sed 's|[/]||g'); do
      if [ "$j" != "$TARGETDIR" ]; then
        echo "rm /home/$i/$DIRECTORY/${j}"
        rm -rf "/home/$i/$DIRECTORY/${j}"
      fi
    done
#    break;
  fi
done