15
Sep 2011

Elgin Avenue Street View

When Google started its Street View program, people flocked to the service to find the most outrageous things captured by Google's sneaky cameras. So far people have found fires, flashers, fights and frogmen in various cities around the world.

Today I was made aware of a picture taken by Google on Elgin Avenue that unfortunately has 'Winnipeg' written all over it. Below is a static image, just in case Google chooses to remove this candid view of our city:

Winnipeg: One great city!

8
Aug 2011

I point to the increased fire danger and I point to Folklorama. That's all

"I point to the increase in autism and I point to internet use. That's all."

Neuroscientist (of sorts) Lady Susan Greenfield

It appears the latest trend is creating Greenfieldisms; by offhandedly implying causation where only correlation exists. Carl Zimmer has collected a bunch which are excellent:

"I point to Alzheimer's and I point to cheese doodles. That's all."

"I point to the deliciousness of waffles and I point to Belgians. That's all."

"I point to diabetes and I point to cats. That's all."

30
Jun 2011

Memrise

The hardest part of learning most languages is starting out. To build the initial vocabulary you need to spend hours with flash cards (or a reasonable equivalent) which is very dull work.

Well, I'm going to say this has become any easier, because it hasn't. However, Memrise is a site which promises to make this slightly more convenient by throwing those flash cards online.

You can choose from a variety of languages and for (most) words, a mnemonic, pronunciation and graphic illustration are included. Currently I am reviewing French, picking up a few words and rediscovering some old vocabulary that I had lost. The site, in addition to helping you learn words, lets you review words you've previously covered to ensure that you stay on top of your new knowledge. Beyond the content, the site's design is certainly easy on the eyes which is something that I appreciate.

Memrise promises to be interesting since it provides a free alternative to many pay-to-use language learning sites currently available. I wonder how the pay-to-use sites will change in order to accommodate this challenge?

28
May 2011

Watermark Hotlinks with .htaccess, PHP and ImageMagick

Continuing my unintentional series on .htaccess, today's discussion is about watermarking.

Recently I wrote about how to block hotlinked images using .htaccess. This was a popular method in the past, but the advent of RSS readers means that many well-meaning visitors will be viewing my site's images using hotlinks. I would rather not lose my RSS audience, so how can I continue to deliver images to them?

I initially considered white-listing popular RSS readers, but maintaining the list would likely be a challenge in the future. So based on this, I need a way to show my images to everyone but degrade them enough to be annoying to anyone who hotlinks to my images. Hmm... a watermark perhaps.

.htaccess

This approach is similar to the previous one which redirects hotlinks to an error image, but instead of redirecting requests to a static image the server redirects to a script which applies a watermark to the requested image.

The modified .htaccess rule to allow watermarking looks like:

# Watermark hotlinked images
RewriteCond %{REQUEST_FILENAME} .*jpg$|.*gif$|.*png$ [NC]
RewriteCond %{REQUEST_URI} !/backend/(.*) [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !seancarney\.ca [NC]
RewriteCond %{HTTP_REFERER} !google\. [NC]
RewriteCond %{HTTP_REFERER} !search\?q=cache [NC]
RewriteCond %{HTTP_REFERER} !msn\. [NC]
RewriteCond %{HTTP_REFERER} !yahoo\. [NC]
RewriteRule (.*) http://www.seancarney.ca/backend/watermark.php?src=$1 [L]

PHP

As you can see above, the request is now fed into a PHP script called watermark. The watermark script collects the url of the originally requested image, sanitizes the url, and then returns a watermarked image using the ImageMagick library.

The code for watermark.php is as follows:

<?php
// Get the URL parameter
if (isset($_GET['src'])) { $input = $_GET['src']; }
// Sanitize the input
$input = str_replace(" ", "%20", $input);
$search = array("\\", "|", ";", ":", "<", ">", "{", "}", "[", "]", "(", ")", "!", "`", "~");
$input = str_replace($search, "", $input);
// Extract the image extension
$ext = substr($input, strlen($input) - 3, 3);
// Send the correct HTTP header for the image type
switch ($ext) {
case "bmp" : header("Content-type: image/bmp"); break;
case "jpg" : header("Content-type: image/jpeg"); break;
case "gif" : header("Content-type: image/gif"); break;
case "png" : header("Content-type: image/png"); break;
case "tif" : header("Content-type: image/tiff"); break;
}
// Prepare and send the watermarked image
passthru("convert -size 200x100 xc:none -fill grey -gravity NorthWest -draw \"text 10,10 'www.seancarney.ca'\" -gravity SouthEast -draw \"text 5,15 'copyright'\" miff:- | composite -tile - http://www.seancarney.ca/$input $ext:-");
?>

ImageMagick

Lastly I should mention what's happening in ImageMagick.

ImageMagick is a powerful tool for creating and editing images. Here I am creating a 200 by 100 pixel image with 'www.seancarney.ca' in the upper left hand corner and 'copyright' in the lower right hand corner using the convert command. Next the composite command is used to tile the watermark image over the original image.

If you want to customize the watermark further I recommend reading annotating using ImageMagick. This presents a good introduction to the different methods available including using images as watermarks.

...and that's it! Now people viewing hotlinked images will be redirected to the watermarked image while regular visitors will be unaffected.

24
May 2011

Find Hotlinks with Google and Block them with .htaccess

Next up on bandwidth reduction week / stupid .htaccess tricks week - how to identify and block hotlinked images.

How to Find Hotlinked Images

Using Google, you can find hotlinked images on your server using the following Google Image search:

inurl:seancarney.ca -site:seancarney.ca

This will bring up all the images which have your website in their URL, but appear in pages not hosted on your domain. This trick isn't guaranteed to find all the images, but it will find some of them. Searching using my domain, I have a handful of hotlinked images most of which are appearing on various spam websites.

How to Block Hotlinking with .htaccess

This isn't anything new, but it flows with the topic so I think it's worthwhile discussing.

Blocking hotlinks is simple at a high level. Each request for an image is checked to ensure that the referring domain is in a list of allowed sites, and if not an 'error' image is shown.

The trick to blocking hotlinks is to distinguish between the 'good' and the 'bad' referrers. Image search engines tend to use hotlinks which I want to allow, while I want to block any spam and attack sites. To ensure search engines can link to images, the rule is written so that all sites are blocked with the exception of:

  • My website
  • Search engines
  • Unknown sites which are requesting my 'no hotlinking image'

Below is the finished rule I added to my .htaccess file:

# Prevent hotlinking
RewriteCond %{REQUEST_FILENAME} .*jpg$|.*gif$|.*png$ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !seancarney\.ca [NC]
RewriteCond %{HTTP_REFERER} !google\. [NC]
RewriteCond %{HTTP_REFERER} !search\?q=cache [NC]
RewriteCond %{HTTP_REFERER} !msn\. [NC]
RewriteCond %{HTTP_REFERER} !yahoo\. [NC]
RewriteCond %{REQUEST_URI} !/sites/default/files/2011/05/22/hotlink.jpg$
RewriteRule (.*) /sites/default/files/2011/05/22/hotlink.jpg [R=302,L]

...and voila! Now any sites which link directly to my images will sport a lovely image informing them that I frown upon hotlinking.

22
May 2011

Redirect High Traffic Referrers to an External Cache with .htaccess and Coral Cache

Last week, out of the blue, a blog post of mine from 2009 started gaining popularity on the social bookmarking site StumbleUpon. While this was a pleasant surprise, the traffic on this site has gone to ~50 visits per day to over 5000. Given the bandwidth caps imposed by my ISP, this extra traffic began to worry me.

My first thought was to use .htaccess to redirect the traffic to the Google cache of the webpage, but the Google cache doesn't load quite right and looks poor. I thought about other caching services and decided to use Coral Cache since it caches webpages in a fairly transparent manner.

The next problem was that using a simple url rewrite rule caused loops where Coral Cache would request content and the webserver would redirect these requests back to Coral Cache. Excluding Coral Cache from the rule prevented these loops from occurring.

Below is the finished rule I added to my .htaccess file:

# Redirect high traffic referrers to Coral Cache
RewriteCond %{HTTP_USER_AGENT} !^Googlebot
RewriteCond %{HTTP_USER_AGENT} !^CoralWebPrx
RewriteCond %{QUERY_STRING} !(^|&)coral-no-serve$
RewriteCond %{HTTP_REFERER} ^http://([^/]+\.)?digg\.com [OR]
RewriteCond %{HTTP_REFERER} ^http://([^/]+\.)?reddit\.com [OR]
RewriteCond %{HTTP_REFERER} ^http://([^/]+\.)?stumbleupon\.com [OR]
RewriteCond %{HTTP_REFERER} ^http://([^/]+\.)?boingboing\.net [OR]
RewriteCond %{HTTP_REFERER} ^http://([^/]+\.)?del\.icio\.us
RewriteRule ^(.*)$ http://www.seancarney.ca.nyud.net/$1 [R=302,L]

Based on this rule, any request from one of the listed websites is routed through Coral Cache and all other requests are served normally. You can see this in action by viewing my site through StumbleUpon.

27
Jan 2011

Netflix on Pay per GB ISP Pricing

Netflix has issued a bold statement against metered usage charges imposed by Internet service providers (ISPs) in their 2010 fourth quarter letter to shareholders (emphasis theirs).

Wired ISPs have large fixed costs of building and maintaining their last mile network of residential cable and fiber. The ISPs’ costs, however, to deliver a marginal gigabyte, which is about an hour of viewing, from one of our regional interchange points over their last mile wired network to the consumer is less than a penny, and falling, so there is no reason that pay-per-gigabyte is economically necessary. Moreover, at $1 per gigabyte over wired networks, it would be grossly overpriced.

I find this interesting since Netflix appears to be coming against a bit of a wall in Canada. Now that ISPs are allowed to implement metered billing they will likely make prices per GB prohibitively expensive to drive customers to their own video distribution channels. This will stifle competition from online service providers and increase the users reliance on their ISP for content delivery.

I don't have any issue with billing customers based on their usage, but the billing should at least match the costs of the ISP. In my mind ISPs should charge a fairly high connection cost to pay for the infrastructure and a low per GB cost for the actual usage of said infrastructure. Sadly, I think the trend in Canada is going to have low connection costs and high usage costs in the future since this will increase profit for the ISPs and discourage competition.

1
Jul 2010

Linkbait

Linkbait is a blog title generator designed to give you inspiration for what to blog about. It's basically Mad-Libs for blog titles, using every blogging cliche imaginable to pad the subject line. That having been said, if you plug the right topic in (such as "British Telecom" or "a raging case of west nile virus"), you can get some pretty amusing titles.

15
Apr 2010

OpenParliament

Today I came across the website OpenParliament.ca which will soon become my primary news source for federal politics. OpenParliament provides an easy way of browsing the federal hansard (minutes of the house) and vote records.

All the hansard and vote records are already available online, but they are very burdensome to use. OpenParliament allows you to browse the hansard by member of parliament or by topic of discussion. They also provide a listing of recent quotes and votes for each MP so you can see what your MP is up to.

If you are looking for debate regarding Canada's role in Afghanistan, visit the site and click on the link Afghanistan. If you want to know what your member of parliament is up to, just do a search for your postal code and view their profile. You can also see all the current bills before the house and the votes for each bill.

This seems like an excellent way to summarize and digest what's happening in Ottawa. While it doesn't solve the problem that there is far to much information to absorb, it does take a big step forward in filtering that information and making it more accessible.

10
Mar 2010

Manitoba Markers Month

James over at Slurpees and Murder declared March to be Manitoba Markers Month and issued an invitation asking for uniquely Manitoban things he can draw with markers. I left a comment asking for him to draw the commenters at the Free Press website, and this morning he posted his masterpiece.

I must say that this is an excellent job. The final image even conveys the feeling of dirtiness I feel after reading the comments. I am eager to see what comes up next as the month goes on. Currently it looks like something that will make Brandon residents angry will be posted soon, along with zombie Steven Juba.