The LINICKX clock – power by jquery, css3 and Google App Engine

It’s been a long time since my last weekend project, over on git hub I have just published the code for my LINICKX Clock.

n800 linickx clock

Photo of my n800 running clock.linickx.co.uk in full screen

I have an old Nokia n800 which I wanted to put to some use. If you want a good time service then time.is is IMHO the best; the reason I’m not using time.is/just on my n800 is that it’s very boring! I wanted to create something that would change, add a little bit of variety – regardless on your opinion on if LCD screen-burn exists or not.

LINICKX Clock is powered by Google’s App Engine (GAE), which means that occasionally it will sleep, however I’ve been running the clock for a few days now an it’s updating fine.

The background, font, text-area and clock delimiters change every 15mins so if you want to see something unique to you then you’ll have to be patient!

Chrome Screenshot of clock.linickx.co.uk

Chrome Screenshot of clock.linickx.co.uk

The clock uses from very simply jquery to download a JSON file from the server, the JSON response updates the style sheet for the page. Some of the clock features are CSS3, such as the blinking delimiter and scaling background so browser milage may vary. The background images are powered by Subtlepatterns.com and SimpleDesktops.com, I’m caching the images on the GAE to reduce the impact to the upstream provider (hopefully they don’t mind!).

You can easily run your own if you want, the simplest method would be to deploy your own app into google, i.e. create a new app, change the application “name” in app.yaml and deploy. If you want to run this locally then you’ll need php (and memcached for caching), you’ll also need to rewrite the permalinks, for example on line 96 of index.php:

$.getJSON('/rd').success(function(data){ 

The random data is a http request to /rd unless you use something like mod_rewrite then you will need to change this to /rd.php

The source code can be found here: github.com/linickx/clock. If you have any suggestions or improvements, feel free to fork or create an issue on github.

OpenShift – PHP, APC & hotdeploy

If you are using apc caching on openshift you may have noticed that your cache gets binned each time you git push, the reason for this is that the push restarts your gear’s apache process. To keep the same process, thus keep the cache you can enable hot deployment.

$ touch .openshift/markers/hot_deploy
$ git add .openshift/markers/hot_deploy
$ git commit -m “enabling hot_deploy”

Now you can push as many times as you like without invalidating the cache… of course if you now need to clear the cache or restart the process you have to do it manually with

$rhc app restart -a myapp

HTH!

My Lifestream – PHP, Curl, CA & Certificate Issues

I use my own lifestream plugin to feed my blog page with activity from other sites.

A (long) while ago HTTPS feeds stopped working, basically due to certificate trust issues.

Now the lifestream plugin uses WordPress built in functions to perform HTTP requests…. and this was not something I wanted to change. It’s taken a bit of exploring to work out why the default configuration did not work… and then find the best way to patch it.

Eventually I found out that you can set the PHP_CURL CA Path in php.ini using the curl.cainfo directive. On CentOS the “well known” CAs are stored in /etc/pki/tls/certs/ therefore the fix was quite simple, add the following to /etc/php.ini

curl.cainfo = /etc/pki/tls/certs/

Job done! Now HTTPS only site (like github) lifestream nicely!

apc.php for rhel / centos

Note to self: The apc.php (script for monitroing apc performance) is stored in – /usr/share/doc/php-pecl-apc-3.1.3p1

rxalarm – Alarm Console (webhook) for Rackspace Cloud Monitoring.

When rackspace launched cloud monitoring I was really interested, especially since leaving AWS… I kind of felt a bit blind to what my servers were doing.

By default, the monitoring service sends you emails for up/down alarms… just what we need more emails! … So I have started to write an alarm console which is a compatible webhook for their API…. i.e. you can send alarms to it!

My Webhook is called [rx]Alarm… rx as in receive :)

The source code is on github (rxalam repo) and a working copy is on openshift (rxalam site).

This may end up being yet-another-project-I-don’t-finish … or it maybe not, only time will tell!

php basic twitter oauth example

Oauth it seems tricky, to help me understand I’ve attempted to code up an example which allows users to log into a php app with their twitter credentials.

The code has been pushed to a branch of my abandonware repo as I don’t plan to make on any future changes, checkout README.md for some info on how the code works.

https://github.com/linickx/a/tree/oauth

I found it quite difficult to find some simple code to do this, so hopefully ^that^ will help someone else :)

is_blog

Since moving to a static front page I’ve noticed google is indexing /blog rather than individual posts…. this little addition to my header.php should fix it!

<?php
/*
                DO NOT INDEX /blog
        */

        if ( (!is_front_page()) && (!is_page()) && (!is_single()) && (!is_archive()) ) {
                echo '<meta name="robots" content="noindex">' . "\n";
        }
?>

You may notice that WordPress doesn’t appear to be an is_blog function which would do the same thing.

root-cookie 1.6, two years in the making?

No taking two years to release an update is not good, but in my defence root-cookie is so simple that there are very few issues and complaints ;)

Actually a two year wait isn’t strictly true, those watching the dev log would have seen I’ve pushed the odd update here and there.

So what prompts this release, well I’ve noticed that in WP3.3 that the cookie functions have changed, so to ensure future compatibility (and minimal issues for me) I have updated this plugin to be aligned to the core source.

The usual blurb…

ChangeLog

  • Contextual Help
  • Bug fix “undefined method WP_Error::get_items”
  • Logout Enhancement
  • WP 3.3 Compatability
  • Donation Link (it’s good for your karma)

PHP to solve problems

PHP make you think of web app’s right? … well, did you know you can run it from the CLI to?

Recently I’ve been doing a lot of spreadsheet and sub-netting type stuff, whilst doing this mundane work I’ve realised that I can get scripts to work for me. I’ve started to post a few PHP network functions to github which I’ve been using.

Here’s an example: I have a nokia firewall, the routing table in voyager is shown in the following format –

Network / CIDR Mask , Gateway
10.0.0.0 / 8 , 10.0.0.1

I need that same routing in a Cisco ASA format –

Network , Mask , Gateway
10.0.0.0, 255.0.0.0, 10.0.0.1

Now this is not a problem for a few routes but the firewall I’m looking at now has 177 static routes, which I don’t want to convert manually.

Roll in PHP!
Save the original routing table as a .csv file. ColA = ip/mask , ColB = gateway.

Save this a route_conv.php

<?php

	/**

		Change the below to your CSV File.

	**/

	$firewall_csv = "./routes_cdr.csv"; 

	/**

		Function to convert CIDRs such as "23" to decimall dotted like "255.255.254.0"
		I've got more of these: https://gist.github.com/1309388

	**/

	function cidr2mask($netmask) {

		$netmask_result="";
		for($i=1; $i <= $netmask; $i++) {
		  $netmask_result .= "1";
		}

		for($i=$netmask+1; $i <= 32; $i++) {
		    $netmask_result .= "0";
		}

		$netmask_ip_binary_array = str_split( $netmask_result, 8 );

		$netmask_ip_decimal_array = array();
		foreach( $netmask_ip_binary_array as $k => $v ){
		    $netmask_ip_decimal_array[$k] = bindec( $v ); // "100" => 4
		}

		$subnet = join( ".", $netmask_ip_decimal_array );

		return $subnet;

	}

	ini_set('auto_detect_line_endings', true); // detect CR

	if (file_exists($firewall_csv)) {

		$file = fopen($firewall_csv, 'r');

		$counter = 0; // array counter

		while (($data = fgetcsv($file)) !== FALSE) {
			
			list($ip, $netmask) = split( "/", $data[0] ); // SPLIT Col A into IP & Mask

			$netmask = cidr2mask($netmask); // Covert Mask

			$gateway = $data[1]; // Col B

			/**
				This echo is the CSV style output, but you could change this to echo "route add $ip $mask $ gateway \n" for unix style output.
			**/

			echo $ip . "," . $netmask . "," . $gateway . "\n";

		}

		fclose($file);

	} else {
		
		echo "404: $firewall_csv \n"; // FILE NOT FOUND.

	}
?>

from your CLI run “php route_conv.php” and enjoy the output!

phpbb_recent_topics version 0.7

PHPbb Recent Topics LogoA little later than planned but the annual release of phpbb_recent_topics is finally here!

I actually started on this release a couple of months ago but couldn’t find the time to write this post and tag the release :-$ The good news is that there have been lots of changes since 0.6, basically I’ve implemented as many bug fixes and feature as I can in the WordPress-Plugin bug tracker.

If you have a feature request or patch, please submit here.

Support questions and requests for help should be directed at the forum.

Without further ado… What’s New?

  • WordPress 3.1.4 Testing
    Yep, with such a slow development cycle I can confirm that PRT works with WordPress version 3, but you knew that right ?
  • CSS Styleable output
    A common request, there is now a UL class called prt_ul and a LI class called prt_li which can be used to make you sidebar look pretty!
  • Plugin Options Modernisation
    I follow planet.wordpress so any tips, tricks and modern ways of doing things have been implemented i.e.
  • Resolved: Missing argument 1 for phpbb_topics()
    This was a stoooopid bug that has been in the code for ages, I finally found the time to squish it!
  • Code clean-up (Lots of changes)
    I’ve put a lot of effort in 0.7 to remove all the un-necessary code, the kind of stuff that get’s pasted in as a good idea but not needed, hopefully this has some positive impact in your site as well as my kama
  • Timezone/Off-Set fix (Reads +/- hours from WordPress Settings)
    This was perhaps the most requested feature, I figured out a neat way of doing it by reading the WordPress options.
  • Localisation of date/time fix (http://plugins.trac.wordpress.org/ticket/1173)
    I’m planning to complete localisation in 0.8, but this is a start right?
  • Callback functionality
    Do you want to do something cool with PRT? Check out phpbb_topics_callback in the readme!
  • Contextual Help in the admin dashboard
    In the past, this blog post has contained the instructions for getting going, I’ve now put everything either in the readme or actually in the wordpress help, keep a weather eye out for the “help” in the top right hand corner of the WordPress dashboard.

Where do I get it?
Download phpbb_recent_topics version 0.7 from WordPress.org

I hope you enjoy this release!

Footnote: Version 0.7.1 has been pushed out which fixes the date display issue reported below!

linickx on github


For your social coding pleasure, linickx code is now in github!

Yesterday I completed the subversion mirror of my WordPress projects – phpbb_recent_topics , root cookie and linickx lifestream – now this isn’t a migration, it is a mirror! For the time being I’m happy using the subversion tools provided by Automattic and the WordPress team but I understand that git is gaining momentum and many are switching, basically I’m hoping this makes it easier for the WP community to get in touch or make suggestions to the code.

I’m also working on uploading some of my old work, I rely heavily on google to broadcast my wares and perhaps there are some old dinosaurs that need resurrecting by a new community of devs? Well if you’re feeling nosey “A is for Abandonware

It’s likely that new code and projects will appear on git hub, I’ve been toying with running subversion on linickx.com but now that Xcode4 has git built in this cloud based social service might be a better option…. I guess only time will tell!

Enjoy!

WordPress Custom Query for Custom Post Types and Taxonomy

I wanted to run a custom query against WP3.0 custom post types but all the documentation and google I found all pointed to posts in categories which doesn’t work if your post type isn’t post, this was my solution….

$my_query = $wp_query-&gt;query; // Copy the existing query into a new one
$my_query['posts_per_page'] = "30"; // change the number we want displayed.
$my_query['orderby'] = "title"; // Sort by title.
$my_query['order'] = "ASC"; // 'A' first!
query_posts($my_query);  // Run our query.... normal service resumes.

Hopefully this post will give someone the light bulb moment they’re after.

Xcode for WordPress Plug-in Developers

This post is an extension to this excellent article except with a subtle difference, I’m not interested in hacking the WP core, I’m writing a plug-in :)

I’m going to assume that you’ve requested access to WordPress.org’s SVN repository, and you’ve found the admin panel and want to get your Xcode goodness hooked up to the WP SVN.

To get started create a new Empty Xcode project.

Screenshot of Xcode project chooser Empty XCode waiting for LINICKX LifeStream
Xcode project chooser Empty Project

From the menu bar select SCM then Configure Repositories, the window select the + to add a new repo, the username & password pair are your wordpress.org credentials, you can find the URL to your SVN repo on the wordpress.org site.

WordPress dot org Admin Interface
The WP.org admin interface

Next from the menu bar select SCM then Repositories, highlight the repo you’ve just created and choose checkout; you’re going to be asked for a folder to “save” the contents of the repo to, I chose inside my Xcode project folder.

Checking out with Xcode
Repo’ Config Code Checkout

You now need to add those “checked out” files to you project, in the tree on the left, right/control click the blue project icon at the top and select add existing files, accept the defaults and the repo should be imported.

Code imported
Imported Code

These files now in the project need to be associated with the repo, this is done by highlighting the blue project icon and clicking the “Info” button, then click “Configure Roots & SCM”; click the + button and choose your repo folder (again)… the dropdown on the right should automatically select the correct SCM.

Project LINICKX LifeStream Info WP Xcode Edit Project Root
Project Properties Project Roots

If you now change a file / add / delete / etc it will appear under the SCM tree, you can right/control click and commit to the repo…. job done :)

WP Xcode readme txt changed
Yay it works!

Very quickly you’re going to find out that you want to test your changes prior to commiting them, to do this you may want to copy your files upto a webserver…. I get Xcode to do that for me, using macfuse to mount my webroot via ssh but for this example I’ll create a directory on the desktop … you also need to create any subdirectories you may need.. I have to create “admin”.

To copy the files we’re use an Xcode target, from the menu bar choose Project then New Target then Copy Files Target, I called my new target CopyFile. Using the info button change the absolute path of the copy – e.g. /Users/Nick/Desktop/LL … now here I ran into a problem (suggestions welcome)… next I created extra copy build phases for each subdirectory. Control/right click your Target ( i.e CopyFiles) then choose Add, New Build Phase, New Copy Files Build Phase… I then set the absolute path of this “sub target” to /Users/nick/Desktop/LL/admin/ to represent my admin subdirectory.

Finally DRAG down the files into their correct target, all being well and a fair wind clicking “BUILD” will cause your files to be copied into your directory. You can now make changes, click build to test, and then commit them to subversion when you’re happy :)

WP Xcode - Finished
Finished!

The red sweater post that inspires this now talks about creating a RUN shortcut to automatically open a web browser for testing, however mine didn’t work… I got this error “The program being debugged is not being run“… suggestions to fix welcome!

phpbb_recent_topics version 0.6

UPDATE: This Plugin has been updated, the below links to the new file, but please comment on the new post, thanks.

Screenshot phpbb_recent_topics admin page

Screenshot phpbb_recent_topics admin page

Admin GUI

It’s that time again, enough things have happened in the support forum to warrant another version.

phpbb_recent_topics 0.6 owes a debt of gratitude to number3nl he has worked very hard to push in two main new features and his work was so good it only needed a couple of minor tweaks from myself.

New Features!

  • The loooong awaited phpBB recent posts feature has been enabled, simply tick the box that says “Sort results by post date” and you’re away!
  • Tooltips are here! Yup if you’re into that kind of thing enabling tool tips will show a snippet of the post content to your visitors prior to them clicking on any links.
  • Admin UI Error Messages are here; the GUI will now inform you if you’re connected to phpBB.

Bug Fixes.

  • The variables in display.php now match those of admin-display.php; hopefully this will make community contribution simpler.
  • Uninstall.php has been added so removal of the plugin is more comprehensive.

A note to upgrader’s.

  • If you’re using secure database connectivity you’ll need to GRANT access to the posts table….
    GRANT SELECT ON phpbb_database.phpbb_posts TO wp_user@localhost;

Download phpBB_Recent_Topics_0.6 from wordpress.org

The usual stuff now follows….


The Installation

Before starting you need to get your database configuration sorted. So, are you going to connect to the PHPBB Database securely or Insecurely?

To connect Securely you need to GRANT access TO WordPress FROM phpbb.

How to GRANT wordpress read only access to phpBB ?
If you don’t know it already you need to find your wordpress mysql user id, it’ll be in wp-config.php

define('DB_USER', 'wp_user');     // Your MySQL username

and you should have already found your phpbb database & table for the above.
You need to type the following syntax into your mysql database

GRANT SELECT ON phpbb_database.phpbb_topics TO wp_user@localhost;

AND

GRANT SELECT ON phpbb_database.phpbb_forums TO wp_user@localhost;

AND

GRANT SELECT ON phpbb_database.phpbb_posts TO wp_user@localhost;

this can be achieved by logging into phpmyadmin as your phpbb user, selecting SQL and pasting the correct GRANT into the text box.

WordPress Installation

  • Unzip phpbb_recent_topics.tgz in your `/wp-content/plugins/` directory. (You’ll have a new directory, with this plugin in /wp-content/plugins/phpbb_recent_topics)
  • Activate the plugin through the ‘Plugins’ menu in WordPress
  • Configure the plugin, you need to tell wordpress about phpbb, this is done in the wordpress menu ‘Settings’ -> ‘phpBB Recent Topics’
    The following Settings are required:

    • * The name of your phpBB database (e.g phpbb)
    • * The name of the table where topics are held (the default is phpbb_topics )
    • * The full url of your forum for links (e.g. http://www.mydomain.com/forum)
    • * The number of topics to show. (If left blank you get 5)
    • * The Date Formatting, i.e. “d/M/y – g:i a” similar to the WordPress “General Settings”
  • The use of Insecure connectivity is optional – See Below
  • Tick the boxes of any Forums you don’t want this plugin to show posts from
  • Hit ‘Update Options”
  • To output the list of topics in a page or post…
    • * create a new page/post, type {phpbb_recent_topics} , hit ‘Publish’ or ‘Create new page’

    To output the list of topics in your theme sidebar using the widget…

    • * click “design” in the dashboard
    • * click “widgets”
    • * next to phpBB Recent Topics click “add”
    • * click “save changes”

    To output the list of topics in your theme sidebar using a template tag…

    • * edit sidebar.php and inside <div id=”sidebar”> type…
      <?php
      if (function_exists('phpbb_topics')) {
      phpbb_topics();
      }
      ?>

What is Insecure MySQL Connectivity & How do I use it?
If you need to you can connect in a less secure manner, the connection details held in your PHPBB config.php can be loaded into WordPress. This is insecure becuase the phpbb3 credentials are store in clear text, this is bad cuase if someone somehow comprised WordPress they’d have full access to PHPBB.

To use, tick the “Enable Insecure Database Connection” box, and submit, when the page re-freshes you’ll have some more boxes to populate, from your phpbb config.php fill in


$dbuser = phpbb MySQL Database UserName
$dbpasswd = phpbb MySQL Database Password
$dbhost = phpbb MySQL Server

Click update, and you should be connected!

Support
I’ve always been honest about support, there isn’t any. Basically I write this for my own needs and then publish it for you to use for free. You’re more than welcome to post comments here and if you need support the community phpbb-recent-topics forum is available, I do read every post there but we all have busy lives and I make no promises on how quickly I’ll reply to you.

Finally Subversion
The source for this plugin is in the wordpress subversion, you can checkout the trunk directly from here, if you weren’t aware wp.org also auto-magically creates a nightly build of any developments here.

I hope you enjoy my plug-in!