Justin Kelly various ramblings

Google Plus photos extension for non Chromebook Pixels

Earlier today Google released a new Chrome extension for Google+ Photos that only works on the new Chromebook Pixel.

I’ve been after the functionality of this extension for my non-Pixel PCs/laptops. So quickly unminifed the source code, removed the pixel only limiation and loaded in Chrome.

The extension works fine - but may be missing some features that are in the Pixel version.

I’ve uploaded this extension to GitHub but won’t be uploading to the chrome webstore or distributing a .crx for it. Installation instructions are below.

https://github.com/justinkelly/google_plus_photos

ReadMe from GitHub

Status

  • The original extensions javascript has been unminified and adjusted so that it not starts on a non Chromebook Pixel

Install

  • Download
  • In Chrome open chrome://flags and Enable ‘Experimental Extensions APIs’
    • refer screenshot below
  • In Chrome Manage Extensions page enable ‘Developer mode’
    • refer 1. in screenshot below
  • Then click ‘Load unpacked extension’ and choose the folder for this git repo

Use

Once installed you can now launch Google+ Photos from your Chrome apps menu, refer below screenshot of startup in Win 7

Auto select all text with jQuery

If you’re stuck using an older version of jQuery ( < 1.9 ) and need to auto select all text in a dynamically created input field you can combine .select() with .live() to make it work.

Refer the javascript code and demo below to see it in action.

Code

Result

URL rewriting with Nginx and Vanilla forum

Having just migrated a number of sites from Apache to the Nginx webserver here’s the below Nginx config to get URL rewriting working correctly with Vallia Forums

location /forum {try_files $uri $uri/ @forum;}
location @forum {rewrite ^/forum(.+)$ /forum/index.php?p=$1 last;}

This assumes you already have the configs to get PHP working with Nginx and have the forum installed at /forum

A number of forum posts detail a much more complex way to get Vanilla working - but as long as you have PHP running fine all you need is the above config and it’ll work

Twitter sidebar for Octopress

Since Twitter has decommissioned the old Twitter API, the Twitter sidebar in Octopress based blogs has stopped working. A few blogs have started to add the new Twitter widget to the sidebar but its quite garish.

My solution just copies the Google Plus sidebard and re-formats for Twitter - just refer the bottom right in the sidebar of this page to see it in action

New sidebar file

Create a new file source/_includes/custom/asides/twitter2.html

{% if site.twitter_user %}
  <section class="twitter2">
    <h1>
      <a href="https://twitter.com/{{ site.twitter_user }}">
        <img src="https://twitter.com/images/resources/twitter-bird-light-bgs.png" width="32" height="32">
          {{ site.twitter_user }}
      </a>
    </h1>
</section>
{% endif %}

CSS

Update the sass/partials/sidebar/_googleplus.scss and add in

.twitter2
{
  @extend .googleplus;
}

Note: I’m not using the googleplus class for the new twitter sidebar as it causes problem for my Octopress / Google Plus comments javascript

Config

In _config.yml add the new sidebar file to the default_asides

default_asides: [custom/asides/twitter2.html, ...

Remove the original asides/twitter.html from the default_asides: line

Migrate MySQL to MariaDB in Ubuntu 12.10

If you have MySQL installed on an Ubuntu (12.10) server and are looking to migrate to MariaDB , here are the steps to migrate over to MariaDB 10.

MariaDB is a drop-in replacement for MySQL - you don’t need to export then import your databases - it just works

Remove MySQL

sudo apt-get install software-properties-common
sudo apt-get remove mysql-server
sudo apt-get remove mysql-server-5.5
sudo apt-get remove mysql-server-core-5.5

Add MariaDB repository

sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xcbcb082a1bb943db
sudo add-apt-repository 'deb http://mirror.aarnet.edu.au/pub/MariaDB/repo/10.0/ubuntu quantal main'
sudo apt-get update
sudo apt-get install mariadb-server

Check that its worked

mysql --version

If the migration was a success it’ll says the distribution of mysql is MariaDB - similar to below

mysql  Ver 15.1 Distrib 10.0.3-MariaDB, for debian-linux-gnu (i686) using readline 5.1

Ubuntu Numlock

If your using a smaller Ubuntu or Debian based distro (lubuntu, solusOS, etc..) you’ll often find that numlock on the keyboard isn’t turned on my default. Just paste the below commands into the commandline and numlock will be on by default.

    sudo apt-get update
    sudo apt-get -y install numlockx
    sudo sed -i 's|^exit 0.*$|# Numlock enable\n[ -x /usr/bin/numlockx ] \&\& numlockx on\n\nexit 0|' /etc/rc.local

Simple javascript function to format the date as YYYY-MM-DD

Tired of concatenating Date.getYear() Date.getMonth(), and Date.getDay() to format todays date in Javascript?

Heres a simple javscript function I use to output the date in YYYY-MM-DD format

Code

Result

How to fix Ubuntu unlock wireless/Gnome keyring issues

Even if you manage to get wireless/wifi working fine in Ubuntu, one annoying issue (if you have auto login set) will be that the ‘Gnome keyring’ will keep prompting you for a password every time you login or wake from hibernation - so that it could connect to my Wi-Fi network.

The solution is simple but one you shouldn’t have to worry about:

  • Right click the Network Manager icon in your panel
  • Select Edit Connections, and switch to the Wireless tab
  • Select the connection you want to work with and click the Edit button
  • Check the boxes for Connect Automatically and Available to all users.

2 decimal places in Javascript/jQuery

I always forget how to format a number as 2 decimal places in Javascript/jQuery, its extremely simple, just use the unmemorable toFixed() function - refer below is an example

$("#total"+row_number).html($total,toFixed(2));

Posterous Backup

Posterous.com is due to shutdown at the end of April 2013. If your after a simple way to backup a Posterous site the below command will download your Posterous site as static html

wget -r -l inf -k -E -p -nc http://yourblog.posterous.com/

The options used are:

  • -r recursive
  • -l inf infinite depth
  • -k suffix html files with .html
  • -E update the saved files with links to local files
  • -p download page resources
  • -nc don’t redownload urls more than once

This command won’t download all images (ones hostes on a different CDN) but it will download the majority of your site fine