Monday, October 27, 2014

Email address

Email address has two parts, namely local-part and domain part, usually in  local-part "@" domain format.

The local-part of the e-mail address may use any of these ASCII characters:
  • Uppercase and lowercase English letters (a-z, A-Z)
  • Digits 0 to 9
  • Characters ! # $ % & ' * + - / = ? ^ _ ` { | } ~
  • Character . (dot, period, full stop) provided that it is not the first or last character, and provided also that it does not appear two or more times consecutively.
The domain part is defined as follows:

The Internet standards (Request for Comments) for protocols mandate that component hostname labels may contain only the ASCII letters a through z (in a case-insensitive manner), the digits 0 through 9, and the hyphen (-). The original specification of hostnames in RFC 952, mandated that labels could not start with a digit or with a hyphen, and must not end with a hyphen. However, a subsequent specification (RFC 1123) permitted hostname labels to start with digits. No other symbols, punctuation characters, or blank spaces are permitted.

The format of email addresses is local-part@domain where the local-part may be up to 64 characters long and the domain name may have a maximum of 253 characters – but the maximum of 256-character length of a forward or reverse path restricts the entire email address to be no more than 254 characters long.

One Javascript Example:
/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/

Backbone validation Example:
email: /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i,

For more info, check out the following links:
http://en.wikipedia.org/wiki/Email_address
http://stackoverflow.com/questions/2049502/what-characters-are-allowed-in-email-address

Friday, October 24, 2014

BaaS (Backend-as-a-Service)

Parse was acquired by Facebook 2013, which means BaaS is a hot concept. Using a Backend-as-a-Service (BaaS) can reduce development cost and time-to-market. It’s a simple way of getting a highly scalable backend solution without significant upfront investment.

There are a bunch of players in this field with similar offerings and pricing. When you select a vendor, pricing, performance, developer-friendly etc factors might need your considerations. I have not tried them out yet, but list here for future reference.

ACS (Appcelerator's)
Applicasa
Buddy
CloudMine
Deployd
mobDB
Parse
sencha.io
Helios
backendless.com

Check out http://en.wikipedia.org/wiki/Mobile_Backend_as_a_service for more info.

Thursday, October 23, 2014

encodeURI vs encodeURIComponent

Javascript provides some very similar APIs (functions) like
encodeURI vs encodeURIComponent
decodeURI vs decodeURIComponent
substr vs substring

Here are some testings to help understand the difference

encodeURI('http://www.google.com')
"http://www.google.com"
encodeURIComponent('http://www.google.com')
"http%3A%2F%2Fwww.google.com"

encodeURIComponent(";,/?:@&=+$#-_.!~*'()")
"%3B%2C%2F%3F%3A%40%26%3D%2B%24%23-_.!~*'()"
encodeURI(";,/?:@&=+$#-_.!~*'()")
";,/?:@&=+$#-_.!~*'()"

encodeURI("中文")
"%E4%B8%AD%E6%96%87"
encodeURIComponent("中文")
"%E4%B8%AD%E6%96%87"

The substring() method returns a subset of a string between one index and another, or through the end of the string.
str.substring(indexA[, indexB])

The substr() method returns the characters in a string beginning at the specified location through the specified number of characters, or the end of the string.
str.substr(start[, length])

Saturday, October 4, 2014

Video

A video file usually contains video track, audio tracks. Individual track can have meta data (video aspect ratio, audio language etc), and containers can also have metadata (video title, poster, episode numbers etc)

Video container formats define how to store things, not what kind of data is stored. There are lost of video container formats, some most popular formats are MPEG-4 (.mp4, m4v), Ogg (.ogv, Ogg Theora), WebM (.webm), Flash Video (.flv), Audio Video Interleave (.avi).

When we watch a video, video player (e.g. VLC) usually does several things at once:
  1. Interpret the container format to find out video and audio tracks, and how they are stored within the file for decoding process
  2. Decode the video stream and display a series of images (frames) on the screen
  3. Decode the audio stream and send the sound to speakers
Video codec (a combination of words coder and decoder) is an algorithm to encode video stream. Video player decodes the video stream according to video codec. There are lossy and lossless video codecs. There are many video codecs (like video containers), and most popular are H.264 (patent encumbered), Theora (royalty-free and not patent-encumbered), and VP8 (royalty-free not encumbered by any patents).

As to audio codecs, MP3 (patent encumbered), AAC (Advanced Audio Coding, patent-encumbered) and Vorbis (not patent encumbered) are most popular for Web audio.

Tools:
Firefogg for encoding Ogg video, ffmpeg2theora for batch encoding Ogg videos
HandBrake for encoding H.264 video
ffmpeg for encoding WebM video
LAME project is the free encoder for MP3
FAAC library is the open source (mencoder and ffmpeg)
OggConvert, ffmpege, aoTuV and libvorbis (QuickTime component on Mac, DirectShow filter on Windows)