Xah's Web Dev Blog Archive 2013-12

JavaScript Regex Syntax (first version)

split into 2 pages.

web hosting service with virtual machine

woot! just activated my digitalocean account. It's a web hosting service using virtual machines. Meaning, you have a whole linux box to yourself, as a dedicated box, with root access. So, you can do anything you want. Ruby, Rails, ngixn, Node.js, anything, or just play with it. They run it on solid state drive.

https://www.digitalocean.com/

JavaScript: Random Range, Randomize Array (updated)

♥ JavaScript, Node.js, socket.io ♥

thanks to friends on g+, discovered Socket.io

Socket.IO is a JavaScript library for realtime web applications. It has two parts: a client-side library that runs in the browser, and a server-side library for node.js. Both components have a nearly identical API. Like node.js, it is event-driven.

Socket.IO primarily uses the WebSocket protocol, but if needed can fallback on multiple other methods, such as Adobe Flash sockets, JSONP polling, and AJAX long polling,[2] while providing the same interface. Although it can be used as simply a wrapper for WebSocket, it provides many more features, including broadcasting to multiple sockets, storing data associated with each client, and asynchronous I/O.

It can be installed with the npm (node packaged modules) tool.[3]

if you have Node.js's npm installed, npm install socket.io

JavaScript, Node.js, am in heaven. Screw perl, python.

love the Ryan Dahl guy. Today's work, annotated the whole thing. His video is the best intro to node.js. Node.js Video Tutorial by Ryan Dahl, with Annotation

my copy of the node.js doc. New is the left side persistent list of node objects. Node.js v0.11.10-pre Manual & Documentation

JavaScript: What's Default Charset, Encoding? How to Escape Unicode Character? (updated)

Variable assignment returns a value.

// variable assignment returns a value
var xx;
console.log(xx = 3);            // 3

So, variable assignment can be chained.

var xx;
var yy;

console.log(xx = yy = 3);       // 3
console.log(xx);                // 3
console.log(yy);                // 3

JavaScript Tutorial by Example

How to Build Node.js Doc for Local Browsing (download node.js doc)

JavaScript. Multiple variables can be declared on the same line, separated by comma var name1, name2, name3 …;

// declare variable, use 「var」
var x;
var y;

// multiple variables can be declared on the same line, separated by comma
var a, b, c;

Multiple variables can be declared and assigned at the same time.

// declare variable and assign
var x = 4;

// declare variable and assign multiple variables
var a = 1, b = 2, c = 3;

When a variable is declared but not assigned, the default value is undefined.

When a variable is not declared nor assigned, and you try to access it, you get ReferenceError.

var x;
console.log(x); // prints 「undefined」
console.log(y); // ReferenceError: y is not defined

Several tutorials on web server and networking. Btw, don't use Apache. Apache is dinosaur. Use nginx & node.js.

JavaScript Variable Scope: Function Level vs Block Level (updated)

Search Unicode Characters

major update on unicode search. You can search by name, codepoint (decimal or hexadecimal) or paste in Unicode characters. Search is now real-time. Result shows as you type. For example, try to find unicode related to christmas. 🎄 🎅. Use the search box at Unicode Characters ☢ ☯ ☭ ∑ ∞ ♀ ♂ ♥

unicode search screenshot 2013-12-17
Unicode search screenshot

JavaScript: Property Attributes: Writable, Enumerable, Configurable (updated)

web UI/UX design is like fashion industry. Each year, grave words are given about the kick-ass-ness of certain design, but after few years, it's all forgotten.

whoever moved the reload ⟳ button into the URL bar is a idiot. Was it Apple Safari who started this?

JavaScript: Call Any Function as Method

JavaScript: What's Strict Mode and How to Determine Strict Mode? (updated)

JavaScript: What's Constructor? What Does Keyword “new” Do? (updated)

JavaScript: Creating Object with Object.create() (major update)

JavaScript: Understanding Prototype & Inheritance (more update)

JavaScript: Dot Notation vs Bracket Notation for Accessing Properties (updated)

added a section about using function scope as namespace. JavaScript Variable Scope: Function Level vs Block Level

JavaScript: Closure in Javascript

JavaScript: Variable & Function Declaration Order: Name Hoisting

JavaScript: Most Frequently Used DOM Methods (major update)

JavaScript Encode URL, Escape String (major update)

JavaScript: Array vs NodeList vs HTMLCollection (major update)

updated with new syntax coloring, a formal language approach to computer language tutorial & documentation.

JavaScript: Most Frequently Used DOM Methods (updated with new syntax coloring)

do you understand the lang well before you use frameworks?

JavaScript Example of Functional Programing: Normalize Vector

// JavaScript. By William James. Modified by Xah Lee
function normalize( vec ) {
var div = Math.sqrt(vec.map(function(x) {return x*x}).reduce(function(a,b) {return a+b}));
return vec.map(function(x) {return x/div});
}

console.log(normalize([3,4,5,6]));
// [ 0.3234983196103152, 0.43133109281375365, 0.539163866017192, 0.6469966392206304 ]

see Vector Normalize Function in Mathematica, APL, Haskell, Ruby, Python, Perl, Lisp, JavaScript, Java, …

JavaScript, example of array splice, 3 arguments form

// example of array splice, 3 arguments form
var uu = [0,1,2,3,4,5];
var rs = uu.splice(2,3, "a");   // start at index 2, removed 3 items, add "a"
console.log(uu);                // [ 0, 1, 'a', 5 ] the new value
console.log(rs);                // [ 2, 3, 4 ] removed items

for detail, see JavaScript Array Methods

Intro to Event in GUI Programing (updated)

How to Create and Update a Website Logo (Favicon) (minor update)

blog comments powered by Disqus