Sketch: Model-View-Controller

Model-view-controller is a well-known programming pattern that is used to organize software code. It suggests code separation within a software into three roles: input (model), process (controller), and output (view). When the software gets really big, such organization of business logic makes it manageable, as well as easier to maintain and extend in the future.

However, many new programmers and non-techy people find it difficult to understand the concept. Here is my attempt to visualize it by using the metaphor of supermarket:

Model – product info and price data retrieve from external source, such as the supermarket headquarter, supplier and so on.

View – shelf arrangement, decoration, poster, price tags, and things that could be affected by the data (product info and price). View is a passive element, which doesn’t automatically update by itself.

Controller – the staff in the store, who would constantly update and rearrange the shelves, decoration and so on base on the ever changing external data provided to them.

Post to Twitter Post to Facebook

Awesome Screenshot

Awesome Screenshot is a Safari extension that allows you to take full-length webpage screenshots with just one click of a button. After taking a screenshot, you can add annotations and symbols to it, and then save the picture in PNG format or upload it to image sharing sites. It is a very convenient tool for web design research and archiving.

I have a couple of issues though:

  1. When AwesomeScreenshot is enabled, my Safari seems to have trouble loading some Javascript powered pages. A big inconvenient example is Google Reader, where the entire view pane is blank and some buttons on the page are not responding at all. Also I have trouble viewing live statistics in Woopra.com.
  2. When saving the file to desktop by dragging, the filename is always named “Unknown.png”. It would be helpful if you can automatically name it the source URL, domain name or page title.

Post to Twitter Post to Facebook

Javascript Snippet for YouTube Video Data

Disclaimer: the following content is solely for education purpose and personal use. Please strictly follow the terms of service of YouTube, do not use this technique for commercial or illegal use. Use it at your own risk.

The following Javascript snippet can fetch useful information from the new YouTube video page layout, including video ID, title and “download hash“:

fv=document.getElementById('movie_player').getAttribute('flashvars'); w=fv.split('&'); ret={'t':'','video_id':'','rec_title':''}; for(i=0;i<w.length;i++) {v=w[i].split('=');if(v[0] in ret)ret[v[0]]=unescape(v[1]);} [document.getElementById('watch-headline-title').innerText,ret.video_id,ret.t];

Usage

  1. Open a YouTube video page (try this one: Introducing the Blogger Template Designer)
  2. Fire up debug console
  3. Copy and paste the snippet above to the console and run it
  4. The console should return to you an array of three values:
    • Video title
    • Video ID
    • Video download hash. This is a time-sensitive token that is required to download a video

With these information it is possible to craft a direction download URL of a YouTube video in MP4 format. Format:
http://www.youtube.com/get_video?fmt=18&video_id=(video_id)&t=(download_hash)

Oh yeah, that means it’s possible to make a bookmarklet to download a video from YouTube page with just one click. Well I’ll leave the fun for you to figure this out since it is pretty trivial. In fact I made a URL Service from Automator to conveniently download YouTube mp4 video straight into my iTunes library, which can be later on sync into iPod, iPhone or AppleTV.

Download YouTube to iTunes

right click on a YouTube URL and save to iTunes

The code snippet is tested on the latest updated video layout as of April 2010.

Credit: code snippet above is a modified version from http://unlockforus.blogspot.com/2010/04/downloading-youtube-videos-not-working.html.

Post to Twitter Post to Facebook

About Calvin

Hello there, I’m Calvin Chun-yu Chan. Grew up in Hong Kong, studied and worked in Canada as web engineer+designer, now designing mobile apps in Tokyo. On my blog I would like to share my opinions on design, usability, culture and creativity.

Follow me on:
Twitter @calvincchan