Monthly Archives: April 2014

how to create a responsive website

1. min-width with media query 123456789101112 /* Small screens (default) */ html { font-size: 100%; } /* Medium screens (640px) */ @media (min-width: 40rem) { html { font-size: 112%; } } /* Large screens (1024px) */ @media (min-width: 64rem) { … Continue reading

Posted in web development | Tagged | Leave a comment

check if a sequence is a output sequence of a stack or not

assume you have a stack, you have a sequence A[n] : {1,2,3,4,5}, check if sequence B[n] : {5,4,3,2,1} is an output of stack or not.   A : 1 2 3 4 5                  B : 5 4 3 2 1 … Continue reading

Posted in programming | Tagged | Leave a comment

pro js design pattern review 6–singleton and lazy loading

/* General skeleton for a lazy loading singleton, step 3. */ MyNamespace.Singleton = (function() { var uniqueInstance; // Private attribute that holds the single instance. function constructor() { // All of the normal singleton code goes here. … } return … Continue reading

Posted in web development | Tagged | Leave a comment

js pro design patterh review 5–prototypal inheritance

  var authorClone = clone(Author); alert(authorClone.name); // Linked to the primative Person.name, which is the // string ‘default name’. authorClone.name = ‘new name’; // A new primative is created and added to the // authorClone object itself. alert(authorClone.name); // Now … Continue reading

Posted in web development | Tagged | Leave a comment

pro js design pattern review 4–classical inheritance

/* Class Person. */ function Person(name) { this.name = name; } Person.prototype.getName = function() { return this.name; } var reader = new Person(‘John Smith’); reader.getName(); /* Class Author. */ function Author(name, books) { Person.call(this, name); // Call the superclass’ constructor … Continue reading

Posted in web development | Tagged | Leave a comment

pro js design pattern 3–static methods and attributes

see the source code : var Book = (function() { // Private static attributes. var numOfBooks = 0; // Private static method. function checkIsbn(isbn) { … } // Return the constructor. return function(newIsbn, newTitle, newAuthor) { // implements Publication // … Continue reading

Posted in web development | Tagged | Leave a comment

pro js design pattern review 2–private , privileged and public method

privileged method is defined in the constructor, and it is public. it could access the private variable in the constructor, for each new instance, the privileged method would be copied, so it might has performance or memory leak issue.  see … Continue reading

Posted in web development | Tagged | Leave a comment

pro js design pattern 1 – interface

/** * usage : var Composite = new Interface(‘Composite’, [‘add’, ‘remove’, ‘getChild’]); */ var Interface = function(name, methods) { if(arguments.length != 2) { throw new Error(“Interface constructor called with ” + arguments.length + “arguments, but expected exactly 2.”); } this.name … Continue reading

Posted in web development | Tagged | Leave a comment

pro javascript design pattern review–1.

  /** * usage : var Composite = new Interface(‘Composite’, [‘add’, ‘remove’, ‘getChild’]); */ var Interface = function(name, methods) { if(arguments.length != 2) { throw new Error(“Interface constructor called with ” + arguments.length + “arguments, but expected exactly 2.”); } … Continue reading

Posted in Uncategorized | Leave a comment

the core algorithm of k-way merge

the code below is excerpt from an algorithm blog. This code snippet is the core algorithm of k-way merge, 1: while(true) 2: { 3: //求data中可用的最小的数字,并记录对应文件的索引 4: int min = data[0]; 5: // j 是文件索引 6: int j = 0; 7: … Continue reading

Posted in programming | Tagged | Leave a comment