<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Robert Basic &#187; Development</title>
	<atom:link href="http://robertbasic.com/blog/category/development/feed/" rel="self" type="application/rss+xml" />
	<link>http://robertbasic.com/blog</link>
	<description>the magic of coding...</description>
	<lastBuildDate>Mon, 30 Jan 2012 13:15:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Xdebug is full of awesome</title>
		<link>http://robertbasic.com/blog/xdebug-is-full-of-awesome/</link>
		<comments>http://robertbasic.com/blog/xdebug-is-full-of-awesome/#comments</comments>
		<pubDate>Mon, 30 Jan 2012 13:13:22 +0000</pubDate>
		<dc:creator>Robert</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[xdebug]]></category>

		<guid isPermaLink="false">http://robertbasic.com/blog/?p=1497</guid>
		<description><![CDATA[I&#8217;m currently trying to fix a Mockery bug and, while deep in the code, I came across a piece of code which gets eval&#8217;d. Mainly to understand better what&#8217;s going on, I wanted to step debug it. I first set a breakpoint before the eval call and then tried to step into the eval&#8217;d code, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://lh5.googleusercontent.com/-JOZg7ZD3KAE/TyaWQeClVTI/AAAAAAAAAsg/JssfwI-Um6c/s1280/Screenshot+-+01302012+-+01%3A57%3A12+PM.png"><img alt="" src="http://lh6.googleusercontent.com/-T6KPtpQIrCA/TyaW4TSDKvI/AAAAAAAAAss/dGguCKJ4ONs/s400/400x200.png" title="debugging eval&#039;d code with xdebug" class="alignright" width="400" height="220" /></a></p>
<p>I&#8217;m currently trying to fix <a href="https://github.com/padraic/mockery/issues/33">a Mockery bug</a> and, while deep in the code, I came across a piece of code which gets eval&#8217;d. Mainly to understand better what&#8217;s going on, I wanted to step debug it. I first set a breakpoint before the eval call and then tried to step into the eval&#8217;d code, but that didn&#8217;t work out, Netbeans just moves along to the next line.</p>
<p>What *did* work, is setting a <code>xdebug_break()</code> call inside of the code that will be eval&#8217;d &#8211; and BAM! it works! Netbeans picks up the signal and everything works just as with regular code &#8211; you can view the values of the variables, step in, step out and step over code.</p>
<p>Xdebug is full of awesome.</p>
<p>Happy hackin&#8217;!</p>
]]></content:encoded>
			<wfw:commentRss>http://robertbasic.com/blog/xdebug-is-full-of-awesome/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating a chat bot with PHP and Dbus</title>
		<link>http://robertbasic.com/blog/creating-a-chat-bot-with-php-and-dbus/</link>
		<comments>http://robertbasic.com/blog/creating-a-chat-bot-with-php-and-dbus/#comments</comments>
		<pubDate>Sun, 08 Jan 2012 19:22:52 +0000</pubDate>
		<dc:creator>Robert</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[bot]]></category>
		<category><![CDATA[dbus]]></category>
		<category><![CDATA[events]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[pidgin]]></category>
		<category><![CDATA[signals]]></category>

		<guid isPermaLink="false">http://robertbasic.com/blog/?p=1482</guid>
		<description><![CDATA[Now that we know how to use DBus to communicate with Pidgin from PHP and how to listen to DBus signals, it&#8217;s time to put it all together by creating a simple chat bot! Nothing fancy, just a simple script that runs somewhere on some server and, by using a Pidgin account, can respond to [...]]]></description>
			<content:encoded><![CDATA[<p>Now that we know how to <a href="http://robertbasic.com/blog/communicating-with-pidgin-from-php-via-d-bus/">use DBus to communicate with Pidgin from PHP</a> and how to <a href="http://robertbasic.com/blog/listening-to-dbus-signals-with-php/">listen to DBus signals</a>, it&#8217;s time to put it all together by creating a simple chat bot! Nothing fancy, just a simple script that runs somewhere on some server and, by using a Pidgin account, can respond to some basic queries we send it.</p>
<h3>What did we get?</h3>
<p>As we want our script to receive messages from an other account, first we need to listen to the <code>ReceivedImMsg</code> event on the <code>im.pidgin.purple.PurpleInterface</code> interface. The data we get with that event is the ID of receiver&#8217;s account, the sender of the message, the actual message and the conversation&#8217;s ID (and some flags which we&#8217;re not interested in):</p>
<pre name="code" class="php">
$interface = "im.pidgin.purple.PurpleInterface";
$method = "ReceivedImMsg";
if ($signal-&gt;matches($interface, $method)) {
    $data = $signal-&gt;getData()->getData();
    $receiver = $data[0];
    $sender = $data[1];
    $message = $data[2];
    $conversation = $data[3];
}
</pre>
<p>Of course, this is only for this one event, for data associated with other events see <a href="http://developer.pidgin.im/doxygen/dev/html/pages.html">Pidgin&#8217;s manual</a>.</p>
<h3>Who&#8217;s there?</h3>
<p>The event we are listening for will fire for any and all accounts, no matter who is the sender or the receiver of the message. We need to make sure that the receiving and the sending accounts are the correct ones, that the receiver is connected and that the receiver and the sender are contacts, &#8220;buddies&#8221;:</p>
<pre name="code" class="php">
if ($receiver == 2034 &#038;&#038; $proxy-&gt;PurpleAccountIsConnected($receiver)
    &#038;&#038; $proxy-&gt;PurpleFindBuddy($receiver, $sender) == 3681) {
</pre>
<p>The numbers 2034 and 3681 are the account IDs for my accounts I used in this example; you&#8217;ll need to figure out yours. </p>
<h3>Sending a response</h3>
<p>Now that we know who&#8217;s talking to whom, we can act upon the received message, do something with it, create a response message and send it back! The data we got with the event, has the ID of the conversation between the two accounts. We create a new instant message for that conversation and send it on it&#8217;s merry way with our clever response message:</p>
<pre name="code" class="php">
$im = $proxy-&gt;PurpleConvIm($conversation);
$proxy-&gt;PurpleConvImSend($im, $responseMessage);
</pre>
<p>As for what action the script can take upon a new message, is really up to the developer: it can do simple stuff like sending back the current uptime of the server or the current IP, running other tools like <a href="https://github.com/enygma/usher">usher</a> and sending that result back, or whatever is necessary.</p>
<h3>Daemonizing</h3>
<p>As this little bot is supposed to run on some server, the easiest way to run it as a &#8220;daemon&#8221; is to put the script in a background job via <a href="http://en.wikipedia.org/wiki/Nohup">nohup</a>:</p>
<pre name="code" class="php">
$ nohup php chat.php &#038;
</pre>
<p>If needed, <a href="http://kevin.vanzonneveld.net/techblog/article/create_daemons_in_php/">creating daemons in PHP</a> can be done too.</p>
<p>And that&#8217;s about all what&#8217;s needed to create a chat bot. See a complete example <a href="https://github.com/robertbasic/blog-examples/blob/master/dbus/chat.php">here on Github</a>.</p>
<p>As for, is PHP the right tool for creating this kind of thing, I don&#8217;t know, maybe, maybe not. What I do know, is that I had fun writing all this and I learned a lot along the way :)</p>
<p>Happy hackin&#8217;!</p>
]]></content:encoded>
			<wfw:commentRss>http://robertbasic.com/blog/creating-a-chat-bot-with-php-and-dbus/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A year in review: 2011</title>
		<link>http://robertbasic.com/blog/a-year-in-review-2011/</link>
		<comments>http://robertbasic.com/blog/a-year-in-review-2011/#comments</comments>
		<pubDate>Sun, 01 Jan 2012 11:13:48 +0000</pubDate>
		<dc:creator>Robert</dc:creator>
				<category><![CDATA[Blablabla]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[about]]></category>
		<category><![CDATA[hex]]></category>
		<category><![CDATA[life]]></category>
		<category><![CDATA[random]]></category>

		<guid isPermaLink="false">http://robertbasic.com/blog/?p=1472</guid>
		<description><![CDATA[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 [...]]]></description>
			<content:encoded><![CDATA[<p>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!</p>
<p>Sadly, not everything was perfect. In October my grandmother and one of my uncles passed away. Around the same time my Dad&#8217;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.</p>
<p>Now that the bad part is out, let&#8217;s jump to the awesome part ;)</p>
<h3>Life changing decisions</h3>
<p>In 2011 I actually had <strong>three</strong> life changing decisions.</p>
<p>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 &#8211; around 10kgs (now just to prevent that turning into fat and into muscles instead) &#8211; and I feel much, much better overall.</p>
<p>For the second one I owe a lot to my parents and to <a href="https://twitter.com/#!/vranac">Srdjan Vranac</a>, for their continuos support and making it possible to happen. In May I handed over my resignation at my previous job and in June <a href="http://robertbasic.com/blog/announcing-hex/">I started my own company, Hex</a>, and joined up with <a href="http://code4hire.com/">Vranac</a>. Just this one thing changed my life to better in so many ways that I can&#8217;t thank Vranac enough for all he did, and is still doing! Thank you :)</p>
<p>The third decision happened in August when <a href="http://robertbasic.com/blog/haircut/">I cut my hair</a>. And nope, I didn&#8217;t regret it :)</p>
<h3>Friends and conferences</h3>
<p>This year I spoke at two conferences, <a href="http://robertbasic.com/blog/dorscluc-2011-recap/">DORS/CLUC</a> in May in Zagreb, and <a href="http://robertbasic.com/blog/webkonf-2011-recap/">Webkonf</a> in October in Budapest. My talks didn&#8217;t turn out that good (heck, the second one was pure horror), but I did make new friends which trumps bad talks any day!</p>
<p>In Zagreb I had the honor to meet fellow hacker <a href="https://twitter.com/#!/nikolaplejic">Nikola Plejić</a>, 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. :)</p>
<p>In Budapest I met fellow hackers <a href="https://twitter.com/#!/Tyr43l">Ferenc Kovács</a> and <a href="https://twitter.com/#!/djozsef">Dubravszky József</a>. Great people with whom I&#8217;d like to grab a beer or two this year :)</p>
<h3>Open source and hacking</h3>
<p>Contributed to <a href="http://web2project.net/">web2project</a> and <a href="http://framework.zend.com/">Zend Framework</a> 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&#8217;m trying to ease my way back in to contributing and general hacking now. Need to be careful though, don&#8217;t want to get this close to a burn out again, next time might not see the line.</p>
<p>Started to learn C just for fun. Don&#8217;t know what to do with it yet, can&#8217;t hurt learning/knowing it.</p>
<p>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!</p>
<p>Happy hackin&#8217; and a happy new year!</p>
]]></content:encoded>
			<wfw:commentRss>http://robertbasic.com/blog/a-year-in-review-2011/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Notes on shell scripting</title>
		<link>http://robertbasic.com/blog/notes-on-shell-scripting/</link>
		<comments>http://robertbasic.com/blog/notes-on-shell-scripting/#comments</comments>
		<pubDate>Thu, 29 Dec 2011 09:02:12 +0000</pubDate>
		<dc:creator>Robert</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[console]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://robertbasic.com/blog/?p=1462</guid>
		<description><![CDATA[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 &#8220;save&#8221; the result of a shell command to a local variable: [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I <a href="https://github.com/enygma/usher/commit/c9a74ebedbc58c6b9b99828b45b1325e86bda1dd">did some shell scripting</a> and thought about writing down the few things learned along the way. Amazing how little needs to be done to learn a lot :)</p>
<h3>Result of a command to a variable</h3>
<p>First thing I learned is how to &#8220;save&#8221; the result of a shell command to a local variable:</p>
<pre name="code" class="bash">
PHP_BINPATH=$(which php)
</pre>
<p>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.</p>
<h3>An empty variable</h3>
<p>Turns out, a variable can be empty, null. Nothing strange with that, until one tries to do something with that variable. For example:</p>
<pre name="code" class="bash">
PHP_BINPATH=
if [ $PHP_BINPATH == "foo" ]
  then
    echo "It's foo"
fi
</pre>
<p>will die with a strange error: &#8220;line 2: [: =: unary operator expected". Problem is that when evaluating it will see <code> if [ == "foo" ] </code> and turns out [ is some reserved command or some such. The fix is to wrap <code>$PHP_BINPATH</code> in double quotes:</p>
<pre name="code" class="bash">
PHP_BINPATH=
if [ "$PHP_BINPATH" == "foo" ]
  then
    echo "It's foo"
fi
</pre>
<h3>Pass all the arguments!</h3>
<p>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 <code>"$@"</code> for that:</p>
<pre name="code" class="bash">
$PHP_BINPATH usher.php "$@"
</pre>
<p>This will pass all the arguments to the PHP script which is called from within the shell script.</p>
<p>Happy hackin'!</p>
]]></content:encoded>
			<wfw:commentRss>http://robertbasic.com/blog/notes-on-shell-scripting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Listening to Dbus signals with PHP</title>
		<link>http://robertbasic.com/blog/listening-to-dbus-signals-with-php/</link>
		<comments>http://robertbasic.com/blog/listening-to-dbus-signals-with-php/#comments</comments>
		<pubDate>Mon, 26 Dec 2011 13:50:17 +0000</pubDate>
		<dc:creator>Robert</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[dbus]]></category>
		<category><![CDATA[events]]></category>
		<category><![CDATA[listen]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[pidgin]]></category>
		<category><![CDATA[signals]]></category>
		<category><![CDATA[xmpp]]></category>

		<guid isPermaLink="false">http://robertbasic.com/blog/?p=1442</guid>
		<description><![CDATA[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&#8217;s libpurple API, we can also listen to different signals on different events, that are sent via Dbus. Some of [...]]]></description>
			<content:encoded><![CDATA[<p>In my previous post I described (tried, at least) <a href="http://robertbasic.com/blog/communicating-with-pidgin-from-php-via-d-bus/">how to communicate with Pidgin from PHP</a>, by using the Dbus PHP extension.</p>
<p>The good part is that not can we only call different methods against Pidgin&#8217;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.</p>
<p>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.</p>
<h3>Watching for signals</h3>
<p>Once we know the interface and/or the specific signal we&#8217;re interested in, we can add a watch on it. This is done by calling the <code>addWatch</code> method on the Dbus object, were the first parameter is the interface, and the second, <strong>optional</strong> parameter is the exact signal we want to listen to.</p>
<pre name="code" class="php">
&lt;?php

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

// watching for a specific signal
$dbus-&gt;addWatch("im.pidgin.purple.PurpleInterface", "ReceivedImMsg");
// or watching on an entire interface
// $dbus-&gt;addWatch("im.pidgin.purple.PurpleInterface");
// also can listen to different interfaces at the same time
$dbus-&gt;addWatch("org.freedesktop.Hal.Device");
</pre>
<p>Next, we need a way to actually get these signals when the events occur. For this we are using the <code>waitLoop</code> 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&#8217;re watching, it will return the signal, which is a <code>DbusSignal</code>; otherwise we&#8217;ll get a null:</p>
<pre name="code" class="php">

do {
    $signal = $dbus-&gt;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-&gt;matches("im.pidgin.purple.PurpleInterface","ReceivedImMsg")){
            // data is in this weird DbusSet object thingy
            $data = $signal-&gt;getData()-&gt;getData();
            echo "Got stuff!\n";
        }
    }
} while (true);
</pre>
<p>Once we got the signal, to make sure that the signal is really the one we&#8217;re interested in, we call the <code>matches</code> method on it. The first parameter is the interface and the second is the signal.</p>
<p>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 <code>getData()->getData()</code> on the signal; note that this is in case of listening on libpurple&#8217;s interfaces, not sure about others. Experiment. Also, what kind of data is returned, again, depends on the interface and/or the event &#8211; some return arrays, some strings.</p>
<p>Have a look at the <a href="https://github.com/robertbasic/blog-examples/tree/master/dbus">Github repo</a> for some more examples (the dbus-signals* files).</p>
<p>In the third, and probably last post in this dbus mini-series, I&#8217;ll try to build a bot with which I can communicate and issue out commands to.</p>
<p>Happy hackin&#8217;!</p>
]]></content:encoded>
			<wfw:commentRss>http://robertbasic.com/blog/listening-to-dbus-signals-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A quick note on Dojo&#8217;s data grids and dojox.data.HtmlStore</title>
		<link>http://robertbasic.com/blog/a-quick-note-on-dojos-data-grids-and-dojox-data-htmlstore/</link>
		<comments>http://robertbasic.com/blog/a-quick-note-on-dojos-data-grids-and-dojox-data-htmlstore/#comments</comments>
		<pubDate>Fri, 23 Dec 2011 21:52:10 +0000</pubDate>
		<dc:creator>Robert</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[data grid]]></category>
		<category><![CDATA[dojo]]></category>
		<category><![CDATA[dojo store]]></category>
		<category><![CDATA[htmlstore]]></category>

		<guid isPermaLink="false">http://robertbasic.com/blog/?p=1412</guid>
		<description><![CDATA[I&#8217;m spending this day trying to create an &#8220;universal&#8221; administration dashboard with which I&#8217;ll finally be happy with. I&#8217;m using Dojo to spice up the UI, because I think it&#8217;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. [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m spending this day trying to create an &#8220;universal&#8221; administration dashboard with which I&#8217;ll finally be happy with. I&#8217;m using <a href="http://dojotoolkit.org/">Dojo</a> to spice up the UI, because I think it&#8217;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.</p>
<p>Anyway, when using <a href="http://dojotoolkit.org/reference-guide/dojox/data/HtmlStore.html#dojox-data-htmlstore">dojox.data.HtmlStore</a> as a store for a <a href="http://dojotoolkit.org/reference-guide/dojox/grid/DataGrid.html#dojox-grid-datagrid">dojox.data.DataGrid</a> (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.</p>
<p>Let&#8217;s take for example this is the given HTML table:</p>
<pre name="code" class="php">
&lt;table id="datastore"&gt;
&lt;thead&gt;
  &lt;tr&gt;
    &lt;th&gt;ID&lt;/th&gt;
    &lt;th&gt;Name&lt;/th&gt;
  &lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
  &lt;!-- body comes here --&gt;
&lt;/tbody&gt;
&lt;/table&gt;
</pre>
<p>I was defining the structure for the columns as:</p>
<pre name="code" class="php">
var struct = [[
   { field: 'id', name: 'ID', width: 'auto' },
   { field: 'name', name: 'Name', width: 'auto'}
]];
</pre>
<p>which was wrong. This is the correct one:</p>
<pre name="code" class="php">
var struct = [[
   { field: 'ID', name: 'ID', width: 'auto' },
   { field: 'Name', name: 'Name', width: 'auto'}
]];
</pre>
<p>Use what&#8217;s in the <strong>TH tags</strong> for the <strong>field</strong> 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 &#8220;&#8230;&#8221; in each column, instead of the actual data.</p>
<p>Happy hackin&#8217;!</p>
]]></content:encoded>
			<wfw:commentRss>http://robertbasic.com/blog/a-quick-note-on-dojos-data-grids-and-dojox-data-htmlstore/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Communicating with Pidgin from PHP via D-Bus</title>
		<link>http://robertbasic.com/blog/communicating-with-pidgin-from-php-via-d-bus/</link>
		<comments>http://robertbasic.com/blog/communicating-with-pidgin-from-php-via-d-bus/#comments</comments>
		<pubDate>Sun, 18 Dec 2011 21:10:43 +0000</pubDate>
		<dc:creator>Robert</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[communication]]></category>
		<category><![CDATA[dbus]]></category>
		<category><![CDATA[pecl]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[pidgin]]></category>
		<category><![CDATA[xmpp]]></category>

		<guid isPermaLink="false">http://robertbasic.com/blog/?p=1354</guid>
		<description><![CDATA[Earlier this week I got an idea of trying to communicate with Pidgin, a chat client, via the terminal. Sounded like a fun thing to hack on, plus, could be made useful (in my head, at least), for things like logging from a web application directly to IM, or, heck, even creating something like Github&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>Earlier this week I got an idea of trying to communicate with <a href="http://pidgin.im/">Pidgin</a>, a chat client, via the terminal. Sounded like a fun thing to hack on, plus, could be made useful (in my head, at least), for things like logging from a web application directly to IM, or, heck, even creating something like <a href="https://github.com/github/hubot">Github&#8217;s Hubot</a>, commanding a server or an application just via chat. Surely I wasn&#8217;t the first one to come up with this idea and after a bit of a googling found out that Pidgin&#8217;s libpurple has a nice API for that, <a href="http://developer.pidgin.im/wiki/DbusHowto">exposed via D-Bus</a>.</p>
<p>I first planned to write some scripts for this in Python or C, but when I finally sat down over the weekend to hack on this, realized there is a <a href="http://pecl.php.net/package/DBus">PHP D-Bus extension</a>, thanks to <a href="http://derickrethans.nl/">Derick Rethans</a>! As I rarely have the opportunity/need to play with more &#8220;obscure&#8221; PHP extensions, decided to give this one a spin&#8230; (Note: apart from that D-Bus is used for processes communicating with each other, I have zero knowledge about it, so I might be wrong with some things down below.)</p>
<h3>Installing D-Bus for PHP</h3>
<p>As the extension requires the <code>dbus-devel</code> package, first make sure it is installed:</p>
<pre name="code" class="bash">
$ yum install dbus-devel
</pre>
<p>The installation of the extension itself is pretty easy:</p>
<pre name="code" class="bash">
$ pecl install dbus-beta
</pre>
<p>Add the <code>extension=dbus.so</code> line to your php.ini, restart Apache if needed and have a look at the <code>phpinfo();</code>, there should be an entry for D-Bus listed.</p>
<p>Note that there is no documentation for this extension at the moment, but, luckily, the sources include an <a href="http://svn.php.net/viewvc/pecl/dbus/trunk/examples/">examples directory</a> full of goodies! After fiddling around with those for an hour or so, got the basics of the extension figured out.</p>
<p>One thing I haven&#8217;t figured out completely, is how to run scripts which use the Dbus extension via the browser, as in those cases the scripts are dying with a terrible X11 error message. So, run Dbus scripts from the console and all should be fine. </p>
<h3>The a-ha! moment</h3>
<p>What I learned by looking at the examples, is that the Dbus class is used for creating a proxy, which can be used to call methods on the service/application we&#8217;re interested in. But, what methods are available, what arguments do those methods accept (if any), and what will they return as a result?</p>
<p>This can easily be found out by <strong>introspection</strong>. Create a proxy to an object which implements the <code>Introspectable</code> interface and call the <code>Introspect</code> method on that proxy:</p>
<pre name="code" class="php">
&lt;?php

$dbus = new Dbus;

$proxy = $dbus-&gt;createProxy("im.pidgin.purple.PurpleService",
                            "/im/pidgin/purple/PurpleObject",
                            "org.freedesktop.DBus.Introspectable");

$data = $proxy-&gt;Introspect();

file_put_contents('introspect.xml', $data);
</pre>
<p>As the result of the introspection is returned in an XML and can be quite big, putting it in a file for easier viewing.</p>
<p>By looking at the XML file, it&#8217;s pretty easy to figure out what&#8217;s going on; method names, method arguments, their names and types, and the returned result:</p>
<pre name="code" class="php">
<method name="PurpleAccountGetUsername">
  <arg name="account" type="i" direction="in"></arg>
  <arg name="RESULT" type="s" direction="out"></arg>
</method>
</pre>
<p>With all this information at our disposal, it&#8217;s easy to write a script which does something useful, like, listing all the connected accounts and the protocols they are using:</p>
<pre name="code" class="php">
&lt;?php

$dbus = new Dbus;

$proxy = $dbus-&gt;createProxy("im.pidgin.purple.PurpleService",
                            "/im/pidgin/purple/PurpleObject",
                            "im.pidgin.purple.PurpleInterface");

$accounts = $proxy-&gt;PurpleAccountsGetAllActive();

foreach ($accounts-&gt;getData() as $account) {
    if ($proxy-&gt;PurpleAccountIsConnected($account)) {
        $username = $proxy-&gt;PurpleAccountGetUsername($account);
        $protocolId = $proxy-&gt;PurpleAccountGetProtocolId($account);
        $protocolName = $proxy-&gt;PurpleAccountGetProtocolName($account);
        echo $username . " is connected on the " . $protocolName
                       . " (" . $protocolId . ") protocol.\n";
    }
}
</pre>
<p>A sample output would be something like: &#8220;robertbasic@irc.freenode.net is connected on the IRC (prpl-irc) protocol.&#8221;</p>
<h3>Next steps</h3>
<p>Of course, this is far from a chat bot which can execute commands on a remote server, but at least we have some foundation to build on. In the coming days I&#8217;ll try to figure out how to create a loop which can be used to listen to different purple events &#8211; when a contact comes online, a chat is sent, or received, etc.</p>
<p>Also, it is quite fun trying to figure out a PHP extension just by looking at examples and the C source itself. One can learn a lot this way.</p>
<p>Happy hackin&#8217;!</p>
<p>P.S.: Code samples are up on <a href="https://github.com/robertbasic/blog-examples/tree/master/dbus">Github</a>!</p>
<p>Update 2011-12-26: the 2nd post, <a href="http://robertbasic.com/blog/listening-to-dbus-signals-with-php/">listening to dbus signals with php</a>, is published!</p>
]]></content:encoded>
			<wfw:commentRss>http://robertbasic.com/blog/communicating-with-pidgin-from-php-via-d-bus/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Upgrading to Fedora 16</title>
		<link>http://robertbasic.com/blog/upgrading-to-fedora-16/</link>
		<comments>http://robertbasic.com/blog/upgrading-to-fedora-16/#comments</comments>
		<pubDate>Sat, 12 Nov 2011 20:39:49 +0000</pubDate>
		<dc:creator>Robert</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[fedora]]></category>
		<category><![CDATA[grub2]]></category>
		<category><![CDATA[upgrade]]></category>
		<category><![CDATA[xfce]]></category>

		<guid isPermaLink="false">http://robertbasic.com/blog/?p=1347</guid>
		<description><![CDATA[Decided today to upgrade my laptop to Fedora 16, which was released a few days ago. I first switched to Fedora (with XFCE as the desktop environment) from Ubuntu in August, I think. An excellent decision as it is working really great for me. XFCE is also great, really happy that I made this switch. [...]]]></description>
			<content:encoded><![CDATA[<p>Decided today to upgrade my laptop to <a href="http://fedoraproject.org/">Fedora 16</a>, which was released a few days ago. I first switched to Fedora (with XFCE as the desktop environment) from Ubuntu in August, I think. An excellent decision as it is working really great for me. <a href="http://xfce.org/">XFCE</a> is also great, really happy that I made this switch.</p>
<p>Anyway, the upgrade from Fedora 15 to 16 went smoothly (although a bit slow, thanks to my shitty internet connection), using the <a href="http://fedoraproject.org/wiki/How_to_use_PreUpgrade">PreUpgrade</a> script/process. I was a bit sceptical about doing an upgrade and not a cleanstall, but gave it a shot after all (note: every time I tried a dist-upgrade with Ubuntu it failed miserably). PreUpgrade was downloading stuff for a bunch of hours and (about) an hour of installing them, the upgrade was&#8230; Done. Fedora 16 just booted up and I was using my laptop just as before.</p>
<p>I did the post upgrade steps from the above linked article, but the <code>yum distro-sync</code> step failed; it was complaining something about a &#8220;Transaction Check Error&#8221; for a libdvdcss package. I simply disabled the <strong>rpm.livna.org</strong> software source, re-run the distro-sync, it did it&#8217;s thing and then re-enabled the source.</p>
<p>The second thing that &#8220;wasn&#8217;t working&#8221; is that Apache and MySQL were not starting on bootup, so I ran chkconfig for both of &#8216;em:</p>
<pre name="code" class="bash">
$ chkconfig --levels 235 mysqld on
$ chkconfig --levels 235 httpd on
</pre>
<p>Lastly, grub was upgraded to grub2. It was working fine, just that it was showing the grub menu on startup, which is a bit silly given that I&#8217;m running only one OS on this machine. Anyway, added the following lines to <code>/etc/default/grub</code>:</p>
<pre name="code" class="bash">
GRUB_DISABLE_RECOVERY=true
GRUB_HIDDEN_TIMEOUT=0
GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT=0 # I actually edited this line, from 5 to 0
</pre>
<p>and ran:</p>
<pre name="code" class="bash">
$ grub2-mkconfig -o /boot/grub2/grub.cfg
</pre>
<p>I also thought for a while that there was an issue with my wifi, that it&#8217;s dropping connection randomly, but it only happened once, so I don&#8217;t know what to do with it.</p>
<p>Happy hackin&#8217;!</p>
]]></content:encoded>
			<wfw:commentRss>http://robertbasic.com/blog/upgrading-to-fedora-16/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Contributing to Zend Framework 2</title>
		<link>http://robertbasic.com/blog/contributing-to-zend-framework-2/</link>
		<comments>http://robertbasic.com/blog/contributing-to-zend-framework-2/#comments</comments>
		<pubDate>Thu, 10 Nov 2011 19:51:16 +0000</pubDate>
		<dc:creator>Robert</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[cla]]></category>
		<category><![CDATA[contributing]]></category>
		<category><![CDATA[zend framework 2]]></category>

		<guid isPermaLink="false">http://robertbasic.com/blog/?p=1330</guid>
		<description><![CDATA[Today a pretty big news hit the interwebs: as of today, the CLA is not required any more to contribute to Zend Framework 2! This means anyone can issue pull requests and submit patches to the new version. Note that if you want to contribute to Zend Framework 1, you still need a signed CLA. [...]]]></description>
			<content:encoded><![CDATA[<p><img alt="" src="https://lh6.googleusercontent.com/-_Y348B_wmpE/TrwpnoQPAsI/AAAAAAAAAr4/95Yxsz48Y9U/s725/Screenshot%2B-%2B11102011%2B-%2B08%253A08%253A35%2BPM.png" title="The CLA is not required any more." class="alignright" width="363" height="174" /></p>
<p>Today a pretty big news hit the interwebs: as of today, <strong>the CLA is not required</strong> any more to contribute to Zend Framework 2! This means anyone can issue pull requests and submit patches to the new version. Note that if you want to contribute to Zend Framework 1, you still need a signed CLA. I&#8217;ve decided to write a quick post with additional information and links, to make it easier getting started with the contributions!</p>
<p>Back in July I wrote a post on <a href="http://robertbasic.com/blog/helping-out-with-zend-framework-2/">helping out with Zend Framework 2</a>, so consider this post as a second part of that post ;)</p>
<p>The development is on git. The original repo is <a href="http://git.zendframework.com/?a=summary&#038;p=zf">http://git.zendframework.com/?a=summary&#038;p=zf</a>, while <a href="https://github.com/zendframework/zf2">the one on Github</a> is a mirror which gets updated twice a day. Not that it matters much, as everyone forks the Github version and sends pull requests against that.</p>
<p>The issues are kept on a Jira instance: <a href="http://framework.zend.com/issues/browse/ZF2">http://framework.zend.com/issues/browse/ZF2</a>. Please make sure you are actually on the Zend Framework 2 project, as we have a separate project for ZF 1. Create an account on Jira and off you go. If I&#8217;m not mistaken, it is connected to the <a href="http://framework.zend.com/wiki/">ZF wiki</a>, so you can use that too.</p>
<p>All ZF2 related stuff on the wiki is located <a href="http://framework.zend.com/wiki/display/ZFDEV2/Home">in it&#8217;s own section</a>. It&#8217;s full of goodies, so take your time to browse it.</p>
<p>We hold <a href="http://framework.zend.com/wiki/display/ZFDEV2/IRC+Meetings">biweekly IRC meetings</a>: every second Wednesday, 17:00 UTC. The next one is going to be on November 23rd. Prior to each meeting we set up an agenda, vote on it, decide who will be moderator and then just discuss whatever is there to discuss. The meetings are held on the #zf2-meeting channel, on Freenode. All agendas and logs from previous meetings can also be found on the wiki.</p>
<p>We have a separate #zftalk.2 IRC channel devoted to discussing all things ZF2!</p>
<p>Subscribe to the <a href="http://framework.zend.com/wiki/display/ZFDEV/Mailing+Lists">mailing lists</a>; you&#8217;ll be especially interested in the &#8220;Contributors&#8221; section; all big and small things are discussed there.</p>
<p>A new &#8220;thing&#8221; introduced to the ZF ecosystem are the <a href="http://framework.zend.com/wiki/display/ZFDEV2/RFC%27s">RFCs</a>. We&#8217;re using those when a new architecture is discussed or a rewrite/refactor of an existing component is to be done.</p>
<p>New components need to go through a <a href="http://framework.zend.com/wiki/display/ZFPROP/Proposal+Process">proposal process</a>. The proposal process is rumoured to get an overhaul, but (hopefully!) it won&#8217;t be going away.</p>
<p>There is also <a href="http://framework.zend.com/blog">a blog</a> set up, so be sure to <a href="http://framework.zend.com/zf2/blog/feed">subscribe to the feed</a>.</p>
<p>Great and exciting times are ahead of us and I welcome all new ZF contributors! :)</p>
<p>Happy hackin&#8217;!</p>
]]></content:encoded>
			<wfw:commentRss>http://robertbasic.com/blog/contributing-to-zend-framework-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Benchmarking pages behind a login with ab</title>
		<link>http://robertbasic.com/blog/benchmarking-pages-behind-a-login-with-ab/</link>
		<comments>http://robertbasic.com/blog/benchmarking-pages-behind-a-login-with-ab/#comments</comments>
		<pubDate>Wed, 09 Nov 2011 21:27:50 +0000</pubDate>
		<dc:creator>Robert</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Free time]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[ab]]></category>
		<category><![CDATA[benchmarking]]></category>
		<category><![CDATA[console]]></category>
		<category><![CDATA[cookies]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://robertbasic.com/blog/?p=1316</guid>
		<description><![CDATA[Tonight I decided to relax a bit and what better way of relaxing is there for a geek then to do some bash scripting?! So for fun and no profit I decided to try and benchmark pages with ab, Apache HTTP server benchmarking tool, which are behind a login. Turns out, it&#8217;s pretty easy after [...]]]></description>
			<content:encoded><![CDATA[<p>Tonight I decided to relax a bit and what better way of relaxing is there for a geek then to do some bash scripting?! So for fun and no profit I decided to try and benchmark pages with <a href="http://httpd.apache.org/docs/2.0/programs/ab.html">ab, Apache HTTP server benchmarking tool</a>, which are behind a login. Turns out, it&#8217;s pretty easy after reading some man pages ;)</p>
<p><strong>ab</strong>&#8216;s help pages gives a few possible leads. We can POST data with the <code>-p</code> option, which would be great if we would like to benchmark the login process itself. But, we want to test the page after the login. So we&#8217;ll need the ab&#8217;s <code>-C</code> option, which allows for passing cookies in <code>cookie-name=value</code> pairs.</p>
<p>The login process itself is done with <strong>curl</strong> as it allows us to POST data to a server and store cookies received from the server in a cookie jar. curl writes the cookies in a Netscape cookie file format, whatever that is. Sample line is:</p>
<pre name="code" class="bash">
# Netscape HTTP Cookie File
# http://curl.haxx.se/rfc/cookie_spec.html
# This file was generated by libcurl! Edit at your own risk.

example.com	FALSE	/	FALSE	0	PHPSESSID	[RANDOM_SESSION_ID]
</pre>
<p>From this output we&#8217;re interested in the <strong>[RANDOM_SESSION_ID]</strong> cookie value, as the cookie name is simply PHPSESSID and we can just hard-code it. To get the value, we use some obscure *nix magic: <code>grep</code> and <code>cut</code>. grep to grep the line with the PHPSESSID cookie and cut to cut out the 7th column from that line. Easy!</p>
<p>Now that we have the value of the cookie, we just pass it along with ab and done! We&#8217;re benchmarking pages behind a login.</p>
<p>The entire script is:</p>
<pre name="code" class="bash">
#!/bin/bash

COOKIE_JAR="/tmp/ab-login-cookie-jar"

echo "Logging in..."

curl -c $COOKIE_JAR -d username=user -d password=h4x0r http://example.com/login

echo "Getting the session id..."
PHPSESSID=$(cat $COOKIE_JAR | grep PHPSESSID | cut -f 7)

echo "The session id is:"
echo $PHPSESSID
echo "=================="

ab -n 10 -c 10 -C PHPSESSID=$PHPSESSID http://example.com/loggedin
</pre>
<p>The script is also on Github <a href="https://github.com/robertbasic/blog-examples/tree/master/ab-login">here</a>.</p>
<p>Tip: use ab&#8217;s -v option to test for HTTP codes and/or redirects to see if you are really on the page you want to be.</p>
<p>Happy hackin&#8217;!</p>
]]></content:encoded>
			<wfw:commentRss>http://robertbasic.com/blog/benchmarking-pages-behind-a-login-with-ab/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

