Konstantin Vlasenko

An engineer is someone who can make for a dollar what any fool could make for two. – Alan Kay

Category Archives: JavaScript

#jQuery. Use the .delegate() instead of .live(). Use .on() instead of .delegate()

As of jQuery 1.7, the .live() method is deprecated. Use .on() to attach event handlers. Users of older versions of jQuery should use .delegate() in preference to .live(). When a selector is provided (.on), the event handler is referred to as delegated. The handler is not called when the event occurs directly on the bound element, but only for descendants (inner elements) that match the [...]

[express/connect.static] Set ‘Last-Modified’ to now to avoid 304 Not Modified

Why do I need this? The right answer is: I don’t need that trick! The example below is just to show how to use routes to intercept requests to a static file. Put router before static. app.use(app.router); app.use(express.static(__dirname + ‘/static’)); Add ‘/*’ handler (don’t forget to call next()) app.get(‘/*’, function(req, res, next){ res.setHeader(‘Last-Modified’, (new Date()).toUTCString()); [...]

HTML5 chessboard

<html> <head> <script type=”text/javascript” src=”http://code.jquery.com/jquery-1.6.4.min.js”></script> <script type=”text/javascript”> $(document).ready(function () { // draws a chessboard function drawChessboard() { // define the constants var baseX = 0.5, baseY = 0.5, width = 50; // get the 2D context from the “chessboard” canvas var context = document.getElementById(“chessboardCanvas”).getContext(“2d”); // draws the 8 by 8 chessboard for (var i = [...]

node.js Allow access only for logged in users

The reference to isLoggedIn in the route is an connect route middleware. Control is passed to the middleware function before the route function is called. Use isLoggedIn to verify that we have a user token in the session before we send the client the requested route. If we do not have a user token in [...]

Get Spot Price History by using aws-lib

We are going to get the pricing history for t1.micro instances by using aws-lib (Extensible Node.js library for the Amazon Web Services API): var aws = require(“aws-lib”); var ec2 = aws.createEC2Client(accessKeyId, secretAccessKey); var iType = ‘t1.micro’; ec2.call(‘DescribeSpotPriceHistory’, {‘InstanceType.1′:iType}, function(result) { console.log(result.spotPriceHistorySet.item); } );

connect.bodyParser converts FORM data to JSON format

http://senchalabs.github.com/connect/middleware-bodyParser.html Client: Server: Output: login= { { name: Velaskec, password: Pa$$word } }

WCF and JSON

You can also use the WebGet attribute to specify the format for request and response messages By default, operations marked with WebGet send response messages formatted as XML data, and the WCF runtime serializes them as POX objects However, you can send response messages in JSON format by specifying the ResponseFormat property of the WebGet [...]

#JavaScript: ISO 8601 formatted string to Date

ECMAScript 5 includes new support for ISO 8601 dates. This means you’ll be able to create a new Date object using an ISO 8601 formatted string. However, only a few browsers (Firefox 3.5 and WebKit-based browsers) currently support the new ISO 8601 formatting, so you’ll still need to provide the conversion functionality for IE  8. If [...]

Google Closure Library

http://code.google.com/closure/library/index.html Closure Library is for Large-Scale Web Development: JavaScript + HTML/CSS/DOM Collaborative development Managing complexity Modularization and conventions Testing and stability

Follow

Get every new post delivered to your Inbox.