<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
  <channel>
    <title>Robert Basic - the magic of coding</title>
    <description>Robert Basic - the magic of coding</description>
    <pubDate>Wed, 30 May 2012 13:22:17 +0200</pubDate>
    <generator>Zend_Feed_Writer 1.11.11 (http://framework.zend.com)</generator>
    <link>http://robertbasic.com/blog/</link>
    
    <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/robertbasic/blog" /><feedburner:info uri="robertbasic/blog" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId>robertbasic/blog</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item>
      <title>Automatically upload screenshots in XFCE4</title>
      <pubDate>Mon, 13 Feb 2012 21:58:16 +0100</pubDate>
      <link>http://feedproxy.google.com/~r/robertbasic/blog/~3/8CpGJNWV-Ps/automatically-upload-screenshots-in-xfce4</link>
      <guid isPermaLink="false">http://robertbasic.com/blog/automatically-upload-screenshots-in-xfce4</guid>
      <content:encoded><![CDATA[XFCE4 has a nice little tool for making screenshots - xfce4-screenshooter. My only gripe with it is that it can't automatically upload the images to a server and give me the URL to the image (to be honest, it can, but it uploads the images to a shady looking website, and I don't like that). And then one day I saw <a href="https://github.com/EvanDotPro/GtkGrab" target="_self">Evan Coury's GtkGrab</a> - a set of scripts which does exactly what I want! But, sadly, that's for Gnome. So, based on Evan's work, I put together <a href="https://gist.github.com/1748455" target="_self">this little script</a>:<br /><br />

<pre class="bash" name="code">#!/bin/bash
# based on GtkGrab by @EvanDotPro https://github.com/EvanDotPro/GtkGrab
function rename_file()
{
    NEWFILE=$(echo $1 | md5sum | cut -c-5)'.png'
}
REMOTE=user@domain.tld:/home/user/screens/
DOMAIN=http://i.domain.tld/
LOCALPATH=/home/user/Pictures/screenshots/
xfce4-screenshooter -r --save=$LOCALPATH
LOCALFILE=$(ls -tr $LOCALPATH | tail -n 1)
rename_file $LOCALFILE
I=0
LIMIT=10
while [ &quot;$I&quot; -lt &quot;$LIMIT&quot; -a -f &quot;$LOCALPATH$NEWFILE&quot; ]
do
    rename_file $NEWFILE
    I=`expr $I + 1`
done
mv &quot;$LOCALPATH$LOCALFILE&quot; &quot;$LOCALPATH$NEWFILE&quot;
scp &quot;$LOCALPATH$NEWFILE&quot; &quot;$REMOTE$NEWFILE&quot;
echo &quot;$DOMAIN$NEWFILE&quot; | xclip -selection clipboard
notify-send &quot;Screenshot uploaded, URL in clipboard&quot;</pre>

Save this script somewhere on your computer, configure the DOMAIN, LOCALPATH and REMOTE variables, set the script to be executable and then create a shortcut combination for it via Settings -&gt; Keyboard -&gt; Application Shortcuts. Programs you'll need to have installed for this to work are xfce4-screenshooter, xclip and notify-send. If you don't want to be prompted for the password/passphrase for the scp command each time, set up a passwordless login for your user on your remote server.<br /><br />Happy hackin'!<img src="http://feeds.feedburner.com/~r/robertbasic/blog/~4/8CpGJNWV-Ps" height="1" width="1"/>]]></content:encoded>
    <feedburner:origLink>http://robertbasic.com/blog/automatically-upload-screenshots-in-xfce4</feedburner:origLink></item>
    <item>
      <title>Zend Framework full page cache tips</title>
      <pubDate>Sat, 11 Feb 2012 10:06:14 +0100</pubDate>
      <link>http://feedproxy.google.com/~r/robertbasic/blog/~3/yV-SR52f-w4/zend-framework-full-page-cache-tips</link>
      <guid isPermaLink="false">http://robertbasic.com/blog/zend-framework-full-page-cache-tips</guid>
      <content:encoded><![CDATA[When I started rewriting this blog, I knew from start that I want to use Zend Framework's <a href="http://framework.zend.com/manual/en/zend.cache.frontends.html#zend.cache.frontends.page" target="_self">full page caching</a>,
 as, I think, that's the best cache for this purpose. Not much going on 
on the front end, much more reads than writes, no ajax or any other 
&quot;dynamic&quot; content. While implementing the cache, I ran into two issues.<br /><br />The
 first problem was that the cache files were created, but they were 
never valid - on each request a new cache file was created. It was a 
noob(ish) mistake - I had two calls to Zend_Session::startSession() in 
my code, which made the session ID always to change which made the cache
 validity test to fail. Removed the second call and all was well. Or so I
 thought...<br /><br />I moved the code to staging to run some final tests 
before pushing it live, but the cache started failing again. This time 
the cache files weren't even being created! The same code works on my 
machine, fails on staging. The only difference was that I had turned off
 the loading of Google Analytics in the development environment. But... 
that can't be it, right? Wrong. On every request the values of the GA 
cookies are different. The full page cache has a set of settings which 
dictates what variables are taken into account when creating an ID for 
the cache: <i>make_id_with_xxx_varialbes</i> where &quot;xxx&quot; is one of get, post, files, session, cookie and by default all are set to true. Setting <i>make_id_with_cookie_variables</i> to false made the cache to disregard the always changing GA cookies which made the cache start working again.<br /><br />So,
 if Zend Framework's full page cache starts failing for you, check the 
contents and behaviours of all the variables - get, post, files, 
session, cookie - and play around with the cache settings until it 
starts working again.<br /><br />Happy hackin'!<img src="http://feeds.feedburner.com/~r/robertbasic/blog/~4/yV-SR52f-w4" height="1" width="1"/>]]></content:encoded>
    <feedburner:origLink>http://robertbasic.com/blog/zend-framework-full-page-cache-tips</feedburner:origLink></item>
    <item>
      <title>No more Wordpress</title>
      <pubDate>Thu, 09 Feb 2012 12:03:13 +0100</pubDate>
      <link>http://feedproxy.google.com/~r/robertbasic/blog/~3/XlgBl0uV3Lo/no-more-wordpress</link>
      <guid isPermaLink="false">http://robertbasic.com/blog/no-more-wordpress</guid>
      <content:encoded><![CDATA[Over the weekend I finally had enough of wordpress and the bloat it 
became, so I ended up writing my own blog engine thing. Basically I just
 slapped together all the ZF modules and pieces I wrote over the past 
few years.<br /><br />The main goal was that the front end should remain as 
it was under wordpress. Think I got that part pretty well, even improved
 it in a few places (for example using sprites for the smaller icons, 
the header image is finally clickable ...). Gave a short thought about 
changing the theme, but even tho I'm using it for 3.5 years now, I still
 like it, so it stays as it is.<br /><br />The old content is pretty much 
all here; posts, tags, categories and comments are all imported. I 
intentionally left out the &quot;pingbacks&quot;. Probably will end up writing a 
separate post just about the importing of the content.<br /><br />The admin 
area still needs some work, but it's in usable state. If anyone is 
interested, the &quot;template&quot; I'm using for the admin area can be found <a href="https://github.com/robertbasic/admin" target="_self">on Github</a>,
 uses Dojo a lot. I still haven't decided will I end up open sourcing 
all of the PHP code, don't think there's anything new or &quot;revolutional&quot; 
in it - just good ol' time proven ZF code.<br />
<br />
Currently my main &quot;concern&quot; is the RSS feed, hopefully I didn't break 
it. If you notice anything broken with the site, please leave a comment 
or give me a shout on <a href="https://twitter.com/#!/robertbasic" target="_self">twitter</a>.<br />
<br />
Happy hackin'!<br /><img src="http://feeds.feedburner.com/~r/robertbasic/blog/~4/XlgBl0uV3Lo" height="1" width="1"/>]]></content:encoded>
    <feedburner:origLink>http://robertbasic.com/blog/no-more-wordpress</feedburner:origLink></item>
    <item>
      <title>Xdebug is full of awesome</title>
      <pubDate>Mon, 30 Jan 2012 13:13:22 +0100</pubDate>
      <link>http://feedproxy.google.com/~r/robertbasic/blog/~3/hYlofvCgnu8/xdebug-is-full-of-awesome</link>
      <guid isPermaLink="false">http://robertbasic.com/blog/xdebug-is-full-of-awesome</guid>
      <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'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'd. Mainly to understand better what'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'd code, but that didn'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'd - and BAM! it works! Netbeans picks up the signal and everything works just as with regular code - 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'!</p>
<img src="http://feeds.feedburner.com/~r/robertbasic/blog/~4/hYlofvCgnu8" height="1" width="1"/>]]></content:encoded>
    <feedburner:origLink>http://robertbasic.com/blog/xdebug-is-full-of-awesome</feedburner:origLink></item>
    <item>
      <title>Creating a chat bot with PHP and Dbus</title>
      <pubDate>Sun, 08 Jan 2012 19:22:52 +0100</pubDate>
      <link>http://feedproxy.google.com/~r/robertbasic/blog/~3/uUpRNaGc1oA/creating-a-chat-bot-with-php-and-dbus</link>
      <guid isPermaLink="false">http://robertbasic.com/blog/creating-a-chat-bot-with-php-and-dbus</guid>
      <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'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's account, the sender of the message, the actual message and the conversation's ID (and some flags which we'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's manual</a>.</p>
<h3>Who'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, "buddies":</p>
<pre name="code" class="php">
if ($receiver == 2034 && $proxy-&gt;PurpleAccountIsConnected($receiver)
    && $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'll need to figure out yours. </p>
<h3>Sending a response</h3>
<p>Now that we know who'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'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 "daemon" 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 &
</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's about all what'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'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'!</p>
<img src="http://feeds.feedburner.com/~r/robertbasic/blog/~4/uUpRNaGc1oA" height="1" width="1"/>]]></content:encoded>
    <feedburner:origLink>http://robertbasic.com/blog/creating-a-chat-bot-with-php-and-dbus</feedburner:origLink></item>
  </channel>
</rss>

