• Subscribe to the RSS feed! RSS icon
  • Subscribe by Email
  • home
  • blog
  • dev
  • Recent Posts

    • Automatically upload screenshots in XFCE4
    • Zend Framework full page cache tips
    • No more Wordpress
    • Xdebug is full of awesome
    • Creating a chat bot with PHP and Dbus
    • A year in review: 2011
    • Notes on shell scripting
    • Listening to Dbus signals with PHP
    • Configuring 2 monitors with xrandr
    • A quick note on Dojo's data grids and dojox.data.HtmlStore
  • Recent Comments

    • Robert on Zend Framework full page cache tips
    • Stephen S. Musoke on Zend Framework full page cache tips
    • David on Zend Framework full page cache tips
    • Anon on A quick note on Dojo's data grids and dojox.data.HtmlStore
    • James on Communicating with Pidgin from PHP via D-Bus
    • Robert on A Zend Framework 2 EventManager use case
    • Jowee on A Zend Framework 2 EventManager use case
    • Jurian Sluiman on A Zend Framework 2 EventManager use case
    • Jurian Sluiman on A Zend Framework 2 EventManager use case
    • djozsef on Webkonf 2011 recap
  • Tags

    php, about, random, framework, zend, example, ubuntu, blog, site, zend framework, book, conference, me, python, wordpress, apache, introduction, lamp, linux, open source, review, script, setup, signals, ape, community, contributing, dbus, dojo, events, hack, mysql, netbeans, pidgin, plugin, pyqt, security, shell, svn, talk
  • Categories

    • Blablabla
    • Development
    • Free time
    • Places on the web
    • Programming
    • Software
    • Uncategorized
  • Archives

    • February, 2012
    • January, 2012
    • December, 2011
    • November, 2011
    • October, 2011
    • September, 2011
    • August, 2011
    • July, 2011
    • May, 2011
    • April, 2011
    • March, 2011
    • January, 2011
    • December, 2010
    • November, 2010
    • October, 2010
    • July, 2010
    • June, 2010
    • April, 2010
    • February, 2010
    • January, 2010
    • December, 2009
    • November, 2009
    • October, 2009
    • August, 2009
    • May, 2009
    • March, 2009
    • February, 2009
    • January, 2009
    • December, 2008
    • November, 2008
    • October, 2008
    • September, 2008

A year in review: 2011

by Robert Basic on January 1st, 2012

2011 has been and gone, all in all an excellent year for me; much better than the few clusterfuck years before. Going into 2012 with tons of positive energy and going to make it even better!

Sadly, not everything was perfect. In October my grandmother and one of my uncles passed away. Around the same time my Dad's shop was robbed, twice. That was a tough period for my parents and the entire family, still not over it completely, but not giving up either! We love and support each other and will get out stronger than ever.

Now that the bad part is out, let's jump to the awesome part ;)

Life changing decisions

In 2011 I actually had three life changing decisions.

First one in March, when I decided to finally quit smoking. And I did it! After 11 years I finally threw that shit away. Gave me a nice self-confidence boost, gained much needed weight - around 10kgs (now just to prevent that turning into fat and into muscles instead) - and I feel much, much better overall.

For the second one I owe a lot to my parents and to Srdjan Vranac, for their continuos support and making it possible to happen. In May I handed over my resignation at my previous job and in June I started my own company, Hex, and joined up with Vranac. Just this one thing changed my life to better in so many ways that I can't thank Vranac enough for all he did, and is still doing! Thank you :)

The third decision happened in August when I cut my hair. And nope, I didn't regret it :)

Friends and conferences

This year I spoke at two conferences, DORS/CLUC in May in Zagreb, and Webkonf in October in Budapest. My talks didn't turn out that good (heck, the second one was pure horror), but I did make new friends which trumps bad talks any day!

In Zagreb I had the honor to meet fellow hacker Nikola Plejić, who kindly offered me a place to stay during the conference and showed me around the city. Now waiting for him to come to Novi Sad so I can return the favor. :)

In Budapest I met fellow hackers Ferenc Kovács and Dubravszky József. Great people with whom I'd like to grab a beer or two this year :)

Open source and hacking

Contributed to web2project and Zend Framework throughout the year, but somewhere in September got really close to a burn out so I decided to back up a little and have a break. I'm trying to ease my way back in to contributing and general hacking now. Need to be careful though, don't want to get this close to a burn out again, next time might not see the line.

Started to learn C just for fun. Don't know what to do with it yet, can't hurt learning/knowing it.

All in all, awesome year which set the bar high for 2012, but with all this positive energy it will be a piece of cake to fly over it!

Happy hackin' and a happy new year!

Tags: about, hex, life, random.
Categories: Blablabla, Development.
Comments: None.

Notes on shell scripting

by Robert Basic on December 29th, 2011

Yesterday I did some shell scripting and thought about writing down the few things learned along the way. Amazing how little needs to be done to learn a lot :)

Result of a command to a variable

First thing I learned is how to "save" the result of a shell command to a local variable:

PHP_BINPATH=$(which php)

By enclosing the command in parenthesis and putting a dollar sign in front of it, will put the result of that command in the variable.

An empty variable

Turns out, a variable can be empty, null. Nothing strange with that, until one tries to do something with that variable. For example:

PHP_BINPATH=
if [ $PHP_BINPATH == "foo" ]
  then
    echo "It's foo"
fi

will die with a strange error: "line 2: [: =: unary operator expected". Problem is that when evaluating it will see if [ == "foo" ] and turns out [ is some reserved command or some such. The fix is to wrap $PHP_BINPATH in double quotes:

PHP_BINPATH=
if [ "$PHP_BINPATH" == "foo" ]
  then
    echo "It's foo"
fi

Pass all the arguments!

When calling some other command from within the shell script, and all the arguments which are passed to the shell script need to be passed to that other command, use "$@" for that:

$PHP_BINPATH usher.php "$@"

This will pass all the arguments to the PHP script which is called from within the shell script.

Happy hackin'!

Tags: bash, console, scripting, shell.
Categories: Development, Programming.
Comments: None.

Listening to Dbus signals with PHP

by Robert Basic on December 26th, 2011

In my previous post I described (tried, at least) how to communicate with Pidgin from PHP, by using the Dbus PHP extension.

The good part is that not can we only call different methods against Pidgin's libpurple API, we can also listen to different signals on different events, that are sent via Dbus. Some of the events that are signalled are when a chat message is recieved, a friend comes online, a file is sent, or any other from a list of some 110 different events.

The PHP Dbus extension allows us to watch for one exact signal on an interface, or for all signals on an interface. Of course, we can add watches on multiple interfaces at once.

Watching for signals

Once we know the interface and/or the specific signal we're interested in, we can add a watch on it. This is done by calling the addWatch method on the Dbus object, were the first parameter is the interface, and the second, optional parameter is the exact signal we want to listen to.

<?php

$dbus = new Dbus(Dbus::BUS_SESSION);

// watching for a specific signal
$dbus->addWatch("im.pidgin.purple.PurpleInterface", "ReceivedImMsg");
// or watching on an entire interface
// $dbus->addWatch("im.pidgin.purple.PurpleInterface");
// also can listen to different interfaces at the same time
$dbus->addWatch("org.freedesktop.Hal.Device");

Next, we need a way to actually get these signals when the events occur. For this we are using the waitLoop method of the Dbus class. That method accepts a number as a parameter, which is the number of miliseconds it should wait between requests. If an event happened on the interface we're watching, it will return the signal, which is a DbusSignal; otherwise we'll get a null:


do {
    $signal = $dbus->waitLoop(1000);

    if ($signal instanceof DbusSignal) {
        // even if we watch only for one signal on one interface
        // we still can get rubbish, so making sure this is what we need
        if($signal->matches("im.pidgin.purple.PurpleInterface","ReceivedImMsg")){
            // data is in this weird DbusSet object thingy
            $data = $signal->getData()->getData();
            echo "Got stuff!\n";
        }
    }
} while (true);

Once we got the signal, to make sure that the signal is really the one we're interested in, we call the matches method on it. The first parameter is the interface and the second is the signal.

Each event has (can have? not sure yet) additional data associated with it. To get to it, for some odd reason, we need to call getData()->getData() on the signal; note that this is in case of listening on libpurple's interfaces, not sure about others. Experiment. Also, what kind of data is returned, again, depends on the interface and/or the event - some return arrays, some strings.

Have a look at the Github repo for some more examples (the dbus-signals* files).

In the third, and probably last post in this dbus mini-series, I'll try to build a bot with which I can communicate and issue out commands to.

Happy hackin'!

Tags: dbus, events, listen, php, pidgin, signals, xmpp.
Categories: Development, Programming.
Comments: None.

Configuring 2 monitors with xrandr

by Robert Basic on December 25th, 2011

My current, most used set up, includes a laptop and a second screen attached to it. The laptop is always to the left of the second monitor and together they give one big screen with a total resolution of 3046x1050. From time to time, X11 gets confused and shows the same image, with the same resolution, on both monitors.

The tool which can help fix this is xrandr.

First, query X11 to find out what monitors there are:

$ xrandr -q

Once the monitor IDs are known, this fixes things for me:

$ xrandr --output VGA1 --auto --right-of LVDS1

Where LVDS1 is the laptop's screen and VGA1 is the second screen.

Happy hackin'!

Tags: monitors, x11, xrandr.
Categories: Software.
Comments: None.

A quick note on Dojo's data grids and dojox.data.HtmlStore

by Robert Basic on December 23rd, 2011

I'm spending this day trying to create an "universal" administration dashboard with which I'll finally be happy with. I'm using Dojo to spice up the UI, because I think it's awesome and it has a lot of stuff in it and plays well with Zend Framework. This post is dedicated to the future stupid me.

Anyway, when using dojox.data.HtmlStore as a store for a dojox.data.DataGrid (or any other grid, really), pay attention to the definition of the columns structure which is passed to the grid. I was doing a really stupid thing which cost me a bunch of hours until I finally figured out what was going on.

Let's take for example this is the given HTML table:

<table id="datastore">
<thead>
  <tr>
    <th>ID</th>
    <th>Name</th>
  </tr>
</thead>
<tbody>
  <!-- body comes here -->
</tbody>
</table>

I was defining the structure for the columns as:

var struct = [[
   { field: 'id', name: 'ID', width: 'auto' },
   { field: 'name', name: 'Name', width: 'auto'}
]];

which was wrong. This is the correct one:

var struct = [[
   { field: 'ID', name: 'ID', width: 'auto' },
   { field: 'Name', name: 'Name', width: 'auto'}
]];

Use what's in the TH tags for the field properties! I was trying to be clever and use the name of the fields in the database. The worst part is that there will be no errors, the grid will render correctly the header row and a correct number of rows for the data, but! it will show "..." in each column, instead of the actual data.

Happy hackin'!

Tags: data grid, dojo, dojo store, htmlstore.
Categories: Development, Programming.
Comments: 1 comment.
« ‹ 1 2 3 4 5 › »
Robert Basic © 2008 — 2012
Design & graphics by: Livia Radvanski
Coded by: Robert Basic
Home page last updated on November 30th, 2009.
Frameworks used: Zend Framework, Dojo, 960 Grid System