Tuesday, 15 November 2011

Kindle Web Clipping

I've been lucky enough to work on an interesting new project, a "Kindle Web Clipping" service called ClipDO.com.

ClipDO is a free service allowing you to send articles to Kindle (and soon to support other mobile devices).

My job as a developer for the project is to ensure that the "parser" (the part of the service that analyses the clipped webpage) correctly extracts the article whilst ignoring superfluous content (adverts, menus, comments, etc).  For example, in the screenshot below The New York Times is converted from a webpage (left), to a cleanly formatted article (right).  The article is then wirelessly transferred to your Kindle, ready to read:


Developing the parser is really interesting work.  It's amazing how structurally different popular news sites are, and developing a "one-size-fits-all" algorithm to do this is both challenging and rewarding.  We've tested the parser with hundreds of popular sites, and I think it fares very well (although if you do find a site that doesn't clip well, please drop me a line - aaron at tangaro.net).

Sunday, 2 October 2011

Installing Samba on the Pogoplug

The Pogoplug can be turned into a dedicated Samba server by following the steps below.


1. PREREQUISITES
As a prerequisite of this article, please complete the steps described in my previous post here in order to prepare your Pogoplug so you can install packages using the IPKG package management system.


2. INSTALLING THE SAMBA PACKAGE
To install the Samba server, SSH to your Pogoplug and perform the following:

# Install samba server
/opt/bin/ipkg install samba2

3. CONFIGURING THE SAMBA SERVER
The Samba server should now be installed.  At this point we need to modify the configuration file.  Perform the following:

# Navigate to the samba config directory
cd /opt/etc/samba/
# Backup the default configuration file
cp smb.conf smb.conf.backup 
# Edit the configuration file
vi smb.conf
My config file is as follows (you can copy, paste, edit as required):

[global]

workgroup = PARKNET
server string = Pogoplug Samba2 Server
hosts allow = 192. 127.
null passwords = yes
guest account = root
log file = /opt/var/log/samba/log.%m
max log size = 50
security = share
encrypt passwords = yes
smb passwd file = /opt/etc/samba/smbpasswd
dns proxy = no
preserve case = yes

[HD1]
comment = HD1 Network Share
path = /tmp/.cemnt
available = yes
public = yes
writable = yes
printable = no
create mask = 0777
guest ok = yes
browseable = yes


4. RUNNING THE SAMBA SERVER
To start the Samba, run the following:

# Start the Samba Server
/opt/etc/init.d/S80samba start

If all goes according to plan, you should be able to perform the following (from a Windows PC):
  • Go to the Run prompt (Windows key + r)
  • Type "\\pogoplug\" and press enter (where pogoplug is replaced with the IP address of your device)
  • If prompted, enter your root username and password to authenticate
You should now be able to browse your device from Windows Explorer, map drives as network shares etc.



Thursday, 28 July 2011

Installing a BitTorrent client on the Pogoplug

The Pogoplug can be turned into a dedicated BitTorrent client by following the steps below.


1. PREREQUISITES
As a prerequisite of this article, please complete the steps described in my previous post here in order to prepare your Pogoplug so you can install packages using the IPKG package management system.


2. INSTALLING THE BITTORRENT PACKAGE
To install the Transmission BitTorrent client, SSH to your Pogoplug and perform the following:

# install transmission
/opt/bin/ipkg install transmission
# start transmission in order to generate a default configuration file
/opt/bin/transmission-daemon
# stop the transmission process
killall transmission-daemon
# make a new configuration directory to hold the transmission configuration files
mkdir /opt/config
# move the freshly generated transmission configuration files off of the main flash drive and onto the spare flash drive
mv /root/.config/transmission-daemon /opt/config/
# move into the transmission configuration directory
cd /opt/config/transmission-daemon/
# backup the generated configuration file
cp settings.json settings.json.backup

3. CONFIGURING THE BITTORENT CLIENT
At this point, the Transmission BitTorrent client is installed on your Pogoplug, congratulations! Now we need to decide on a location for torrents to be downloaded to. To do this, perform the following (in a terminal session):

# Display disk usage
df -h
and observe the output. This command lists hard drives connected to the Pogoplug, as well as any mounted internal flash drives. You can choose any drive to download to, but I would advise a connected USB hard drive to prevent unnecessary reading of the flash drive, and also help prevent filling up the internal flash drives (which can lead to boot problems).
Anyway, you should see something similar to this:

-bash-3.2# df -h
Filesystem                Size      Used Available Use% Mounted on
/dev/mtdblock2           32.0M     14.4M     17.6M  45% /
none                    125.0M      3.2M    121.8M   3% /tmp
/tmp/.cemnt/sda1        916.9G    435.1G    472.5G  48% /tmp/.cemnt/mnt_sda1
/dev/mtdblock3           91.0M     14.7M     76.3M  16% /opt

The USB drives connected to your pogo plug will be mounted under "/tmp/.cemnt/". In my case, I chose the following destination folder (which already existed on my Pogoplug):


/tmp/.cemnt/mnt_sda1/My Documents/Downloads/


Now we will update the Transmission configuration file to use our selected directory. To edit the file, enter the following:

# Enter a text editor to edit Transmissions settings.
vi /opt/config/transmission-daemon/settings.json
You will need to update the following keys with your selected download directory: "download-dir", "incomplete-dir".


4. RUNNING THE BITTORENT CLIENT
To start the BitTorrent client, run the following:

# Start the Transmission client, pointing the application to the custom configuration directory
/opt/bin/transmission-daemon --config-dir /opt/config/transmission-daemon/

You should now be able to access the web interface for the BitTorrent client by entering the following into a browser on a device in the same local network as your Pogoplug:


http://pogoplug:9091/transmission/web/


Replacing "pogoplug" with the IP address/domain name of your Pogoplug device.
Your Pogoplug is now running a BitTorrent client :)


UPDATE: See my new post on how to allow for adding new torrent files from the my.pogoplug.com website :)



Wednesday, 13 April 2011

Make your site compatible with IE6

IE6 isn't very well loved anymore, even Microsoft are apologising for it. Microsoft are however, attempting to move people away from IE6, using the statement "Friends don’t let friends use Internet Explorer 6".

This may be so, but unfortunately at this point in time (April 2011) IE6 still counts for roughly 12% of the worlds browser usage. It's tempting as a web developer to say "nope" to requests for making your website work with IE6, but when working for an organisation where customers cannot/refuse to upgrade their browser, and their custom pays your salary, sometimes you don't have a choice.

Below are some tips and tricks that may help in turning a modern (read: standards compliant) website into something that will hopefully work reasonably nicely in IE6 too. These tips certainly worked for me.

CONDITIONAL COMMENTS
In a perfect world the CSS written to style your website will work in all browsers. In the real world this is often not the case, particularly when it comes to IE6.

If you have written standards compliant CSS and have it working nicely in the modern browsers, trying to shoehorn CSS that works to IE6 can be a pain. In these instances, I prefer to use conditional comments, so I can separate my valid CSS from my "quirky IE6 CSS".

Conditional comments are used exclusively by the IE browser family, and allow for serving portions of HTML to specifically targeted IE versions. To see a list of available conditional comments, click here.

In my example, I want to load a custom CSS file for all IE browser versions below IE7:


<!--[if lt IE 7]>
<link rel="stylesheet" type="text/css" href="/Include/CSS/ie6.css" />
<![endif]-->

The code between these tags will only be included in IE browsers below IE7 - all other browsers will ignore the include statement. This allows for writing CSS in the "ie6.css" file that will only be applied for users with IE6, IE5.5 etc.

For example, if you have an element that is positioned correctly in all the modern browsers, but appears out of place in IE6, the CSS class can be redefined in the "ie6.css" file, and the "!important" declaration can be used to override existing class styles:

In Layout.css (used by modern browsers)

#logo
{
    left: 100px;
    top: 30px;
}

In IE6.css (only picked up by versions of IE below 7

#logo
{
   top: 20px!important;
}

TRANSPARENT PNGs
Put simply, IE6 does not support PNG transparency.  Below is a screenshot demonstrating the how a transparent PNG is rendered in IE6 versus IE8:


This is not an issue if the images on your website use a single transparent background (bit-transparency) - images can be converted from PNG to GIF (you will however, need to consider whether doing this will reduce the quality of your image). However, if you utilise more complex opacity in your images (alpha-channel transparency), you will either have to lose your fancy opacity settings, or make use of one of the many JavaScript libraries that will attempt to fix this for you.

My preference is the "ifixpng" jQuery library, available here.

Once you have included the library in your project, you can apply the PNG transparency fix to all images across your website using:

$('img[@src$=.png]').ifixpng(); 

Or to a specific image (with ID of "logo"):

$('#logo').pngfix();

The nice thing about this library is that the code to do the PNG transparency conversion will only run if it detects the IE6 browser, so no extra processing will take place for users of modern browsers.

JQUERY POPUPS & Z-INDEX ISSUES
In modern websites it is common to utilise popups on a page to retrieve information from users, display larger images from thumbnails, etc. IE6 does not play nicely with these popups if certain types of element are on the page, for example, the "select" element, as demonstrated below:

A form displayed in IE6 (before "Save" button is clicked and popup appears):


Popup which is displayed after "Save" button is clicked:


As you can see, the "select" element peeks through the dimmed background of the popup window (and the popup itself).  This is due to the fact that IE6 does not support the "z-index" attribute on "select" elements.

Again, there is a handy jQuery library designed to work around this issue with relative ease - bgiframe. From the plugin webpage:
"The bgiframe plugin works by prepending an iframe to the element. The iframe is given a class of bgiframe and positioned below all the other children of the element. In the default configuration it automatically adjusts to the width and height of the element (including the borders) and the opacity is set to 0. The element needs to have position (relative or absolute) and should have a background (color or image)."
In short, if you have elements poking through your popups (or any other DOM object for that matter) when viewing in IE6, include the bgiframe library and call the following on the popup:

$('#popup').bgiframe();

Hope this helps! :)

Monday, 28 March 2011

Customising your Pogoplug

or, "How to turn your Pogoplug into a BitTorrent, file and web server!"

Please note: Follow the instructions below at your own risk.  Please do not blame me if your Pogoplug breaks :)
11/01/2012 - Please note that a number of users appear to be having issues completing the steps described below on the latest incarnation of the Pogoplug (v4).  Unfortunately I do not own v4 of this device, so I cannot experiment/resolve this issue.  If you have any information to help get users working with this version, please post in the comments section below.

Pogoplug is a small embedded Linux device sold to enable personal cloud computing.  If you have never heard of Pogoplug, check it out here.  

If you have one already and would like to add support for 100s of different applications, including a BitTorrent client, Samba, Apache Web Server, CUPS etc, then read on!

The great thing about the Pogoplug is that it allows root access via SSH, and also includes an unused internal flash drive, perfect for tinkering with. In this tutorial I am going to describe the steps I took to install a package management system which gives access to a whole host of useful applications that can run directly on your Pogoplug (and lots of other packages, a list of available ones can be seen here).  

1. PREPARING YOUR POGOPLUG

First, make sure you have setup your Pogoplug correctly and it is accessible from my.pogoplug.com.

  • Log in to my.pogoplug.com with your username and password
  • Go to “Settings” > “Security Settings" page and tick “Enable SSH access for this Pogoplug enabled device"
Now you need to find the IP address of your Pogoplug in your local network.  There are lots of different ways to do this, probably the most straightforward is to login to your router and look through the list of connected Ethernet devices.  Once you have found your Pogoplug's local IP address, you can SSH to it using a terminal application.

  • Open up a terminal (instructions for Windows, Linux and Mac)
  • Once you have your selected terminal open, type the following (replacing “123.456.789.100” with your Pogoplugs IP address:
    • ssh root@123.456.789.100
  • When prompted for a password, use “ceadmin” and hit enter
Congratulations!  You are now connected to your Pogoplug.


2. INSTALLING A PACKAGE MANAGEMENT SYSTEM

Now it’s time to install a lightweight package management system on the unused internal flash drive – this will enable us to install a whole host of useful packages that are not included on the Pogoplug as standard.  

  • Copy and paste the following into your connected SSH session to prepare your Pogoplug for installing applications (it may be worth copying and pasting a line at a time and checking for any errors before continuing with the next step):
mount -o remount,rw /
mkdir /opt
mount /dev/mtdblock3 /opt
cd /opt
wget http://ipkg.nslu2-linux.org/feeds/optware/cs08q1armel/cross/unstable/ipkg-opt_0.99.163-10_arm.ipk
tar -xOvzf ipkg-opt_*_arm.ipk ./data.tar.gz | tar -C / -xzvf –
mkdir -p /opt/etc/ipkg
echo "src cross http://ipkg.nslu2-linux.org/feeds/optware/cs08q1armel/cross/unstable" > /opt/etc/ipkg/armel-feed.conf
echo "src native http://ipkg.nslu2-linux.org/feeds/optware/cs08q1armel/native/unstable" >> /opt/etc/ipkg/armel-feed.conf
/opt/bin/ipkg update
Now you have the package manager installed, congratulations, there are a whole host of applications available at your disposal! You can see a list here, or by executing “/opt/bin/ipkg list” from the command line of your Pogoplug.

Future posts will cover installing a BitTorrent client, SAMBA and a webserver :)