Base64 image uploading to Pasteros

Pasteros now has JPEG handling abilities when pastes are uploaded with base64 data (see commit). Convert your image to base64 like this and view it by add .jpg to the end of the paste ! I also wrote a command line utility that uploads a selected screenshot area to Pasteros.



function uploadImage {
 content=$(cat $1 | base64 -w 0)
 pasteid=$(curl -silent -H "Expect:" -X POST -d $content | tail -1)
 echo "$pasteid.jpg"  | xclip -selection c

DISPLAY=:0.0 scrot -s "shot.jpg" 
uploadImage "shot.jpg"
rm "shot.jpg"
notify-send "Done"



SEOBudd WordPress plugin

I thought I'd mess around with WordPress and create a plugin or two. I ended up creating SEOBudd, a SEO stats plugin for WordPress. It retrieves stats about your website, such as average load time, social media mentions and incoming search words. It' has been approved and is now available for purchase on CodeCanyon.



I must say, working with the WordPress plugin API was no fun. Everything felt just so clunky. Unless I'm missing something, you're almost forced to use global variables and procedural functions. The amount of things you can do with the API is quite astounding (the shortcode functions are quite interesting), but the online documentation is difficult to navigate. I finally found the function reference that lists every available function after some searching.

At first, I opted to using my own CSS for the admin panel of SEOBudd. Of course I didn't really investigate more and ended up with a design that didn't fit WordPress at all. After some searching, I found this page "How To Design And Style Your WordPress Plugin Admin Panel"; you can inherit the administration CSS rather than using your own. I found that his created a more native experience.

Another function I found interesting was the options functions. Instead of creating your own database or table, you can let WordPress handle it for you. No need to worry about data types either.

Though it may have not been very much fun, it was easier, if I may say, than creating a Drupal module. I think that Drupal has a much more rigid structure that guides you along.

Anyway, I don't expect too many sales of SEOBudd, so I'll probably put it up on Github sooner or later.

Google Analytics to Twitter bot

The last week, I've been tinkering with Google's Analytics API. What I wanted to do was have daily reports on my website which then  tweets the difference from yesterday to today. The ideal situation was I would have it SMS me the results. The problem is that my phone carrier (Rogers) complicates things. For most carriers, you can email a carrier-supplied address ( for example) which in turn would send an SMS to that address. But, what Rogers does is once you receive a text, you have to respond back with REPLY to view it. Stupid huh.

To get around this, I subscribe to my bots account via text message and for every new tweet, I get a text message.

What you need: Google Analyrtics API class [download] and twitteroauth [download]

For this to work, you need to create an app on Twitter Developers which creates your consumer key, consumer secret, OAuth secret and token. You also need to create gabot.txt for the bot to cache to.

See the code below for the bot or download at the bottom.



    $website_info = $ga->getWebsiteProfiles();
    // set the date range we want for the report - format is YYYY-MM-DD

    $to = date("Y-m-d", strtotime("now"));
    $from = date("Y-m-d", strtotime('Yesterday'));
    $ga->setDateRange($from, $to);

    // get the report for date, showing pageviews and visits
    $report = $ga->getReport(
            array('dimensions' => urlencode('ga:date'),
                'metrics' => urlencode('ga:pageviews,ga:visits'),
                'sort' => '-ga:pageviews'

    //convert the associative array to a numeric array so we dont have to use the $from date as a key
    $report_n = array_values($report);
    //what we're going to tweet
    //0 = today 1 = yesterday
    $stats = $website_info[0]['title'] . " today: pageviews: " . $report_n[0]['ga:pageviews'] . " - visits: " . $report_n[0]['ga:visits'];

    //string to write in file
    $string = $report_n[0]['ga:pageviews'] . '#' . $report_n[0]['ga:visits'];

    //difference from yesterday to today
    $visits_difference = $report_n[1]['ga:visits'] - $report_n[0]['ga:visits'];
    $pageviews_difference = $report_n[1]['ga:pageviews'] - $report_n[0]['ga:pageviews'];

    //open the file for the old saved data
    $fh = fopen($file, 'r');
    $data_read = fgets($fh);

    //compare read data to latest data
    if ($data_read != $string) {

        $fh = fopen($file, 'w') or die("can't open file");
        fwrite($fh, $string);

        $connection = new TwitterOAuth($consumerKey, $consumerSecret, $oAuthToken, $oAuthSecret);
        $connection->post('statuses/update', array('status' => $website_info[0]['title'] . " difference: visits: $visits_difference pageviews: $pageviews_difference"));

        echo $stats;
} catch (Exception $e) {
    print 'Error: ' . $e->getMessage();



WorkSimple 1.3.5 control panel and login fix

After playing around with WorkSimple 1.3.5 (and apparently not doing much  testing), login.php doesn't redirect on login and cp.php strips HTML.  Download the attachments below and replace cp.php and login.php with the new versions. Save the new versions as cp.php and login.php respectively and upload them to your WorkSimple install directory.

WorkSimple 2.0 roadmap

I've been making lots of new changes to WorkSimple, paving the way for WorkSimple 2.0. I'll be going over old code and re-implementing some things. I used Twig for templating instead of a custom made method since it seemed easier and more convenient. Templates now are much more customizable and flexible. Check out the screenshot for what it may look like (the colours suck, I know).

Pasteros: cloud-based text storage

I just had to create [another] text storage project, just for shits. Pasteros (temporary domain) is a text storage storage (think Pastebin, Pastie, etc) running on DotCloud. It uses Twig for templating and I just converted the MySQL innerworkings to PostgreSQL (juste pour le fun). I also made an API for public use as well. I'll be releasing the source code shortly. Any feedback is appreciated.