Posts

Showing posts with the label javascript

Custom 2D Drawing in Android and Html5 Canvas

Image
Recently, I attended an online MOOC course about  html5 canvas drawing . I was surprised how simple of its  drawing API , which has the power to create awesome UI effect. I summarize the 2D drawing API as two fields: regular shape drawing API and transformation API. As for 2D shape drawing in html5 Canvas there are following limited properties and functions: beginPath, endPath, fillStyle, strokeStyle, stroke, fill, fillRect, moveTo, lineTo, arc, font, fillText, strokeText, createLinearGradient, createRadialGradient, addColorStop, drawImage, bezierCurveTo, quadraticCurveTo. To sum up, the above 2D drawing API can do following jobs. moving a point; drawing a line; drawing an arc or circle; drawing a bezier curve; make a path; stroke along the path; fill the closed path with image, colors, gradient effect or patterns; Then, we count the transformation APIs: save, restore, translate, rotate, scale, transform. No need any more illustrations, is it? The transfo...

Javascript Callback Hell

Image
Javascript Callback Hell Table of Contents callback hell Promise bluebird 1 callback hell Javascript callback hell looks like an inherent problem in js language, because of its asynchronous nature, writing callback functions and nesting them together looks the only way to coding for a newbie.    It then gave programmers some mess code, if he persists to writing nesting callback code, and this mess codes are named as callback hell . fs.readFile( "file.json" , function ( err , val ) { if ( err ) { console.error( "unable to read file" ); } else { try { val = JSON.parse(val); console.log(val.success); } catch ( e ) { console.error( "invalid json in file" ); } } }); 2 Promise Promise is a new ES6(ECMAScript 2015) feature, is used for deferred and asynchronous computations. Promise is also a proposal , which represents the eventual ...

Adding javascript source code into browser's bookmarks

Image
Adding javascript source code into browser's bookmarks Table of Contents 1 Introducing two awesome web app. 2 How did those buttons works? 3 A hello world example 1 Introducing two awesome web app. First one, Tumblr is a really popular blog system, it provides mobile clients to post articles anytime and anywhere, that's awesome right, what's more, its customized themes and open API is what I appreciated. It's a fabulous app.  For web browser users, It provides a share button which can be added to your bookmarks. So when you find some great articles, and you are urgent to share, what you did is just to click the share button in your bookmarks which you just installed.  This shard button located in http://www.tumblr.com/apps . The second web app is Instapaper , which is a simple tool to save web pages for reading later. I always search articles in the browser, and sometimes I just get too many results, but I have to power off the PC at midn...