Robert Basic's blog

Archives for February, 2012

Automatically upload screenshots in XFCE4

by Robert Basic on February 13, 2012.
Heads-up! You're reading an old post and the information in it is quite probably outdated.

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 Evan Coury’s GtkGrab - 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 this little script:

# based on GtkGrab by @EvanDotPro
function rename_file()
    NEWFILE=$(echo $1 | md5sum | cut -c-5)'.png'
xfce4-screenshooter -r --save=$LOCALPATH
LOCALFILE=$(ls -tr $LOCALPATH | tail -n 1)
rename_file $LOCALFILE
while [ "$I" -lt "$LIMIT" -a -f "$LOCALPATH$NEWFILE" ]
    rename_file $NEWFILE
    I=`expr $I + 1`
echo "$DOMAIN$NEWFILE" | xclip -selection clipboard
notify-send "Screenshot uploaded, URL in clipboard"

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 -> Keyboard -> 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.

Happy hackin’!

Tags: bash, script, xfce4, xfce4-screenshooter.
Categories: Development, Programming, Software.

Zend Framework full page cache tips

by Robert Basic on February 11, 2012.
Heads-up! You're reading an old post and the information in it is quite probably outdated.

When I started rewriting this blog, I knew from start that I want to use Zend Framework’s full page caching, 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 "dynamic" content. While implementing the cache, I ran into two issues.

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…

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: make_id_with_xxx_varialbes where "xxx" is one of get, post, files, session, cookie and by default all are set to true. Setting make_id_with_cookie_variables to false made the cache to disregard the always changing GA cookies which made the cache start working again.

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.

Happy hackin’!

Tags: caching, full page cache, zend framework.
Categories: Development, Programming.