Author Archive

Put a Flickr feed into your page

Friday, October 19th, 2012

I found a jquery plugin that puts your Flickr public feed into your website. Shoutout to the developers of this fine plugin!

Now let’s get straight to the code:

This is how you call the plugin:

$('#gallery').jflickrfeed({
	limit: 14,
	qstrings: {
		set: '72157624900621129',
		nsid: '7375559@N02'
	},
	itemTemplate: 
	'<li>' +
		'<a href="{{image_b}}"><img src="{{image_s}}" alt="{{title}}" /></a>' +
	'</li>'
});

Where set is the set id that Flickr assigns to each photoset you create . . . to get this number, simply go to your Flickr homepage and click on a photoset. Once you are looking at your photoset, the URL should look like this – http://www.flickr.com/photos/USER/sets/############/ – the numeric digits at the end of this URL is the set id. The nsid parameter is your Flickr ID, it is a bit tricky to get this information but go to this page and it should show you your Flickr ID.

You can bundle this with jquery Cycle for slideshow presentation or with jquery Colorbox for a nice photo gallery. Here is a more in-depth demonstration with code samples.

Plugin Options

Here is a description of each one:

  • flickrbase: This is unlikely to be needed.  It is used to set up the url the jQuery AJAX call will need to be made to.
  • feedapi: There are a number of feeds that flickr makes available.  The default is the public feed.  Here is the list of all that are available: http://www.flickr.com/services/feeds/. This has only been tested on feeds that return photos.  So, for example, don’t expect good results using this plugin on the Forum discussion feeds.
  • limit: Set how many items you want to loop through.  Flickr seems to limit its feeds to 20, so that is the default.
  • qstrings: This is the most important setting. This is used to request the correct feed.  In my examples I use this to set the user id.  These are automatically added to the request url. Depending on which feed you use (http://www.flickr.com/services/feeds/) there are different sets of query parameters available: http://www.flickr.com/services/feeds/.
  • cleanDescription: Flickr puts all kinds of junk in the description it returns. By default this plugin is set to remove everything but the plain photo description.
  • useTemplate: Set this to false if you don’t want to use the plugins templating system.
  • itemTemplate: The template rules are described below.
  • itemCallback: You can add a callback on each item.  The scope is set to the container and the item object is made available.

Template

In order to make it really easy to use any kind of markup needed with this plugin, a simple templating system has been build in. Here is an example of a template:

<li>
   <a href="{{image_b}}"><img src="{{image_s}}" alt="{{title}}" /></a>
</li>

You can see that this is just basic html with a few special tags mixed in. All of the tags are surrouned by double curly braces. The plugin works by putting in the correct information for each tag and each item into the template.

The tags that are available depend on what flickr returns for each item. For the Public Photos API these are: title, link, date_taken, description, published, author, author_id, tags, and image. For the image property, the plugin uses the Flickr URL scheme to make several sizes available.

Image Sizes

The letter suffixes are as follows: (ie {{image_b}} where the image size returned is 1024px wide/tall)

  • s small square 75×75
  • q large square 150×150
  • t thumbnail, 100 on longest side
  • m small, 240 on longest side
  • n small, 320 on longest side
  • – medium, 500 on longest side
  • z medium 640, 640 on longest side
  • c medium 800, 800 on longest side†
  • b large, 1024 on longest side*
  • o original image, either a jpg, gif or png, depending on source format

* Before May 25th 2010 large photos only exist for very large original images.
† Medium 800 photos only exist after March 1st 2012.

The Callback Parameter

The plugin’s second parameter is a callback. This has the scope of the containing element and has the entire data response available. This is a great feature if you want to integrate this plugin with others. Let’s say you want to integrate it with colorbox. If you call $(‘selector’).colorbox() and then this plugin it won’t work. This is becuase the plugin is adding elements to the page after the colorbox call. This is even true if you call colorbox after this plugin. Since this uses ajax, your images won’t be added to the page until well after most of your javascript has run. (In computer time).

Instead, the trick is to use the callback function. This allows you to pass in code that you want to run after the images have loaded. So for example, you can do this:

$('#cbox').jflickrfeed({
	    limit: 14,
	    qstrings: {
	        id: '37304598@N02'
	    },
	    itemTemplate: '...example...'
	}, function(data) {
	    $('#cbox a').colorbox();
	});

Download

Download the demo and code.

Twitter feed (blogger.js) not working . . .

Monday, October 15th, 2012

[UPDATE] As of June 2013 – This no longer works, am sure there is a workaround but I have little to no time going around trying to fix this so instead, I’m going to hang it up and use Twitter’s official widget (which I should’ve done from the beginning) – https://dev.twitter.com/docs/embedded-timeline

If you have used Twitter’s blogger.js script to show your twitter feed on your website, then you must’ve noticed that it suddenly stopped working a few days ago . . . this is because Twitter has updated their API . . . so now, you would need to update the script below:


from
<script type="text/javascript" src="http://twitter.com/statuses/user_timeline/USERNAME.json?callback=twitterCallback2&amp;count=2"></script>
to
<script type="text/javascript" src="http://api.twitter.com/1/statuses/user_timeline.json?screen_name=USERNAME&include_rts=true&count=2&callback=twitterCallback2"></script>

where USERNAME would be replaced with your twitter username.

Blackberry Jam

Friday, August 31st, 2012

If you are wondering about the title of this post and if you guessed the smartphone instead of the substance you spread on a pb sandwich then you are correct. Yes, RIM might be flailing and kicking but they have just booked the Four Seasons in Vancouver for a day to host this event (probably their last?). I had the opportunity to attend this event mainly because they had a separate web track that discusses HTML5 and how it can be used to develop for the Blackberry platform but more importantly for other mobile devices as well.

Some of the more notable frameworks discussed were jquery mobile, sencha touch, dojo toolkit and zepto.js to name a few. The idea is to build these out and skin them using bbUI.js to make it look as close to a native BB app as possible by using the same graphical elements. You could take this further by using either WebWorks or Apache Cordova to build/package it as a native app.

If any of your are interested, Blackberry has released these presentations to the public and I have also made them available here:

  1. Building HTML5 Apps with Native Capabilities
  2. Advanced BlackBerry HTML5 Development: WebGL and Remote Web Inspector
  3. How to get that Native Look and Feel using bbUI & Alice.js
  4. Making the Most of Existing Public Web Development Frameworks
Dev Alpha device

Blackberry 10 Dev Alpha

They also gave up Blackberry 10 Dev Alpha devices. These look fairly OK but they don’t function as good – I know they are evaluation devices but I had no idea how far off Blackberry 10 is . . . the OS is laggy, boot-up time takes forever and it crashes quite a bit, battery isn’t very good either and it takes so long to charge. I have almost given up on mine . . . it is like paperweight . . . how can you test on it if it won’t stay on long enough? The browser crashes very often as well . . . to me, it seems like they are pretty desperate. To send out a half-baked OS on a device and courting developers to develop on it?? As the market currently stands, the Blackberry platform is on life-support and this doesn’t really give developers confidence in the product, how do you expect them to waste their time to develop for it?? Well, one upside to it all is that the screen looks pretty good . . . hope somebody develops a good music/video player so I can make use of it.

Habits and Data

Wednesday, August 15th, 2012

I have been reading the Power of Habit by Charles Duhigg and have been gaining insight into our behavior and why we do the things we do. Humans are habitual creatures and apparently, we go through the majority of our day by relying on our habits – though it seems like we are making multiple conscious decisions throughout the day.

I have also found out about how much of what we do are being recorded and studied. There is actually software, Hit Song Science that predicts the popularity of a song. I wonder if that is the reason why there is so much crappy music nowadays . . . radio stations around the country are using data to see which songs are popular and then form playlists around those songs. A study shows that the majority of us will not tune out of a station if it is playing something familiar to us, regardless of whether we like it or not. Personally though, whenever a song I dislike gets played on the radio, I immediately tune to another station or plug in my iPod. However, it seems interesting to me that most people do not . . . However, all of this is moot as I have learned from other sources that a huge majority of teenagers use Youtube to discover new music. So, Youtube is now the new MTV.

More and more companies are relying on mathematicians and statisticians to make use of the enormous amounts of data they have on their customers. Patterns emerge whenever you apply the correct algorithm/formula and from there, companies are more than eager to take advantage of it. There used to be a time when I wasn’t too worried about companies mining data by monitoring my spending habits but they are now integrating their data with data they have bought or mined from somewhere else. There is a huge compilation of data on each individual through social media, online retailers and offline data records. It is no longer science fiction or paranoid to think that Google would know more about you than your co-workers or friends.

I’m also aware of the fact that the next generation would have no problem sharing this information to companies since they grew up in a time where it is the norm. Once they grow up to be our age, everything would probably be public information and perhaps it will be a better world, who knows? A whole generation will not know what a dial tone is, or a rotary dial phone for that matter, they will never see a typewriter and perhaps not know what a watermelon seed looks like. But hopefully, all the data that is gathered about them, helps them form good habits or at least, help them make good decisions.

Printer problem

Tuesday, May 29th, 2012

My trusted Canon ip1500 finally broke down after several years of being my sole printer so I had to resurrect my Brother MFC-240C multifunction printer which I was basically using as a scanner. I had to order ink cartridges from Amazon ($7) – cheap! But when they arrived, I found out that it was printing blank pages . . . I ran the print head cleaning utility a couple of times to no avail . . . so I googled it and found out that you should go into maintenance mode and run the cleaning utility from there (which basically cleans it out better than just running it from the menu – I don’t know why engineers think this is acceptable)

To go into maintenance mode, while pressing the Menu button, unplug the printer and without releasing the Menu button, plug it back in (You might need another person to help you achieve this). Wait until you see maintenance on the lcd screen and all four lights (fax,scan,copy,photo capture) should be blinking to indicate that the printer is in maintenance mode.

You should then press 7, 6, 4 (in that order) and then press the black start button – this will start a thorough cleaning process which should clear out any clogged nozzles and afterwards, your printer should be able to print normally.

Funny thing is, pressing just 7,6 at maintenance mode and then start would clean the print head but not thoroughly enough as when I tried it out, it only printed out magenta, yellow and a faint black . . . so if you really want to flush it out, do the process above and it should work.

I’m putting this in my blog for my reference as well as to help out anybody out there who might be at wit’s end and about to throw their printer out the window . . .

Intro to Javascript Objects

Thursday, May 17th, 2012

I have recently signed up for a class in Web Analytics at UBC. I think it will greatly complement my knowledge in usability design and will improve how I produce websites in the future. I haven’t really had much time to study user behavior in the past aside from the usual A/B testing so it will be a welcome change to be able to delve into the analysis of the user and how my websites are being consumed.

I have also made great improvements in my javascripting, having completed a course last year on the basics. I’m also finishing up on the Javascript component at Codecademy (http://www.codecademy.com/). I’m much more confident in my Javascript skills now and am consistently putting it into practice in whatever project I may be working on.

Here’s a snippet of what I have learned so far:

Creating Objects in Literal notation

var person = {
name: 'Ryan', // note the comma
weight: 150 // no comma after the last key-value pair
};

Below is the same but using an instance

var person = new Object();
person.name = 'Ryan';
person.weight = 150;

Now you can access the object’s properties by just stating

var weight1 = person.weight;
var weight2 = person['weight']; //this is an alternate way

You can also create a constructor to make it easier to create new objects

function person(name,weight)
{
this.name=name;
this.weight=weight;
}

And then afterwards, create new objects just by using the constructor

var myFriend=new person("John",150);

That is the basics of Javascript objects . . . I will be sharing more about Javascript and jquery on later posts.

Stop Internet Censorship!

Wednesday, January 18th, 2012

If there was any doubt that big business controls the government, there shouldn’t be any after 2 bills – SOPA and PIPA are about to pass in US Congress and the Senate. These 2 bills are so obviously drafted by big media companies in order to protect their copyrighted content in an attempt to eradicate online piracy. The huge problem is that, if they pass this bill – it will cripple the internet as sites can be taken down without any due process. And online piracy, the very thing that the media companies are trying to eliminate will probably not be affected at all. File sharing as history has it . . . has morphed and adapted to whatever hurdles may come its way . . . short of cutting all telecommunications methods, these 2 bills will NOT stop piracy. The very people who drafted these bills obviously do not understand how the Internet works – or are desperate enough to try everything they can just to protect their own interests.

Below is a video from TED explaining further how this is going to affect you as an internet user.  And further below are a few sites opposed to the bills and are participating in the blackout today!

Google

Google

Wordpress

Wikipedia

Reddit

Mozilla

Wired

Using Google Feed API to parse external RSS/XML feeds

Tuesday, November 8th, 2011

Recently, I have been tasked to parse an XML/RSS feed using only client-side code. As the website is being migrated from Apache to IIS, it is difficult to settle on which server-side code to use (asp.net or php or python) thus the reasoning behind using pure Javascript/jquery for the task. At first, I thought that this was not possible but as I later found out . . . Google has released an API that would accomplish this task.

Here is a simple implementation of this task:

<script type="text/javascript" src="https://www.google.com/jsapi?key=API_KEY"></script><script type="text/javascript">// <![CDATA[
google.load("feeds", "1");
google.setOnLoadCallback(showFeed);
function showFeed() {
var feed = new google.feeds.Feed("FEED_URL");
feed.setNumEntries(5);
feed.load(function(result) {
if (!result.error) {
var container = document.getElementById("listing");
for (var i = 0; i < result.feed.entries.length; i++) {
var entry = result.feed.entries[i];
var li = document.createElement("span");
li.innerHTML = '<h3><a href="' + entry.link + '">' + entry.title + '</a> <cite>on ' + entry.publishedDate + '</cite></h3>';
li.innerHTML += '<p>' + entry.contentSnippet + '</p>';
container.appendChild(li);
}
if(result.feed.entries.length == 0) { container.innerHTML = '<h4>Nothing in the feed.</h4> Please check back later'; }
} else {
var container = document.getElementById("listing");
container.innerHTML = '<span><h4>Error getting the feed.</h4>
<a href="http://www.benjamingaw.com/blog">Check out my Blog</a></li>';
}
});
}
// ]]></script>

In the HTML, all you need is a placeholder where you want your feed to appear:

You will need to sign up for an API key here. Google loads up the feed as a JSON object, but you can specify XML if that is what you prefer – the entire documentation is found here – http://code.google.com/apis/feed/v1/devguide.html

Look at a demo of this.
There are a couple of jquery plug-ins that take advantage of the Google API as well – go check out PaRSS and gfeed.

Using jParse to post-process an XML feed

Monday, October 24th, 2011

I have used jquery to parse XML in the past for simple tasks. But rewriting the same code every time gets tedious and cumbersome. So I have resorted to using jParse – which is a freely available plug-in especially made for this task.

The plug-in works great straight out of the box and you can even customize the output to your heart’s content.  Simple usage script below:

function start(){
jQuery('#jparse-meta').html('<img alt="Content Loading" src="ajax-loader.gif" />');
}
function finish(){
jQuery('#jparse-meta').remove();
}
$(function(){
$('#ajax-cont').jParse({
ajaxOpts: {url: 'kyle-rush-feed.xml'},
elementTag: ['title', 'link', 'description'],
output: ' <div><h4><a href="jpet01">jpet00</a></h4><p>jpet02</p></div>',
precallback: start,
callback: finish
});
});

HTML for the above script is:

<div id="jparse-meta" style="text-align: center; margin: 15px 0 0 0;">
<p><a href="//http://www.benjamingaw.com/blog">Read my Blog</a></p>
</div><!--/#jparse-meta-->
<div id="ajax-cont"></div><!--/#demo-cont-->

Simple, isn’t it? However, the project I was working on required a little bit more flexibility. As it is a feed that may at times, return nothing. So how do you display default text if the RSS/XML feed is empty? I have looked around for an answer to this and found nothing on Google, so I have to write a simple snippet to address this issue.

For my purposes, the code will lie within the finish function, as this is the callback function once jParse finishes running (see the line of code – callback: finish). And here is the code snippet I added to the finish function to display “No entries. Pls. check back later.”

function finish(){
jQuery('#jparse-meta').remove();
if ($('#ajax-cont').html() == 0) {
$('#ajax-cont').append('<h4>No entries</h4><p>Pls. check back later</p>');
}
}

And that’s it, if the XML doesn’t have any entries, it will show that line of text instead of a blank space.

HP Touchpad overclocking, tips and tricks!

Friday, October 14th, 2011

[Update]: On Oct 18th, HP released an OTA update to version 3.0.4 which renders most of the patches and the overclocking non-operational. However, the update seems to have made the Touchpad more responsive and speedier. It also included a Camera app for taking images with the camera that works better than other free 3rd-party apps. I’ve also noticed a change in video playback – definitely a good update!

I have been playing with my new HP Touchpad for 2 weeks now and would like to share tips and tricks on how to speed it up. Because let’s face it – straight off the box, it is really laggy and slow.

Remove Logging

HP logs almost everything you do on your Touchpad for diagnostic information – the disadvantage is that these background processes slows down everything you do on your Touchpad. Here are some steps to follow to eliminate background logging:

Remove Logging

  • Open up the Phone & Video Calls App
  • Type ##5647# and hit the green call button
  • In the new window that pops up, click on “Change Logging Levels . . .”
  • On the next screen hit “Set Logging To Minimal”
  • Click OK to confirm on the “Are You Sure?” popup

These steps would stop some of the logging processes but not all of them. To remove logging entirely, you have to install some patches. First off, we need turn on Developer mode so we can install third-party apps that are not in the HP App Catalog.

In the Just Type bar – type in webos20090606. Tap the Developer Mode icon. A window will appear – do not set/change password. Instead just hit the toggle from Off to On. That’s it, your Touchpad is on Dev mode.

Installing “Preware” onto your PC or Mac


Download WebOs Quick Install here. Make sure you have java runtime installed on your PC, double-click on the .jar file to install WebOs Quick Install. Let it install the Palm Novacom drivers, it will then prompt you that there is no device attached.

Use a USB cable to connect the TouchPad to your computer. Do not go into USB drive mode (just click cancel)

Once your Touchpad is detected, Click on the globe-like button on the right. A new window will pop up – Type in “Preware” in the search box in the Applications tab and Install it.

Okay. Now you have installed Preware on your TouchPad. Load it up and now you will be able to install the patches. You can do this by clicking on Available Packages > Patch or by simply typing the name of the patches into the search prompt (click on the magnifying glass icon on the right of the Preware title bar)

Here are some suggestions on what patches to install:

  • Advanced Reset Options
  • Muffle System Logging
  • Faster Card Animations HYPER Version
  • Remove Dropped Packet Logging
  • Quiet Powerd Messages
  • Remove Tap Ripple
  • Unthrottle Download Manager

There may be more to come in the coming weeks, just go through all the patches and install the ones that interests you.

Overclock

To overclock your Touchpad, load up Preware and search for Govnah. Install this application and load it up. Click on “Profile” and instead of Palm, select “OnDemandTcL 1512”. This will overclock your CPU to 1.5Ghz.

You will be able to overclock it to as high as 1.9Ghz but that is not as stable and I do not recommend it. That’s it. Enjoy your Touchpad!!