Prepare your Amazon Linux for Sencha ExtJS 6.0 development

  1. install unzip
  2. install java
  3. download ExtJS 6.0 GPL
  4. download SenchaCMD 6.0
  5. unzip SenchaCMD
  6. unzip ExtJS 6.0
  7. install SenchaCMD
  8. logout/login
sudo yum install unzip
sudo yum install java-1.7.0-openjdk 
curl http://cdn.sencha.com/ext/gpl/ext-6.0.0-gpl.zip -o ext-6.0.0-gpl.zip
curl http://cdn.sencha.com/cmd/6.0.0.202/no-jre/SenchaCmd-6.0.0.202-linux-amd64.sh.zip -o SenchaCmd-6.0.0.202-linux-amd64.sh.zip
unzip SenchaCmd-6.0.0.202-linux-amd64.sh.zip
unzip ext-6.0.0-gpl.zip
./SenchaCmd-6.0.0.202-linux-amd64.sh

Apache proxy for sencha app watch

  1. sudo yum -y install httpd
  2. sudo service httpd start
  3. sudo vi /etc/httpd/conf/httpd.conf
  4. <VirtualHost *:80>
      ProxyPass / http://localhost:1841/
      ProxyPassReverse / http://localhost:1841/
    </VirtualHost>
  5. now you can access your server trough port 80

What to read when started with AngularJS

Just note for myself.

ng-boilerplate
AngularJS Best Practices: I’ve Been Doing It Wrong!
AngularJS CRUD application demo

Authentication in Single Page Applications With Angular.js – Looks good. But not sure if it is the best way to deal with the authentication task. Going to read Mastering Web Application Development with AngularJS (Chapter 7: Securing Your Application)

AngularUI
http://egghead.io/
http://tv.jetbrains.net/tags/angularjs

#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 selector.

Advantage of event delegation is that any children added dinamically to the element whould still have the event listener.

 

 

[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());
  next(); 
});

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 = 0; i < 8; i++) {
			for (var j = 0; j < 8; j++) {
				var x = baseX + width * i, y = baseY + width * j;

				// draw the rectangle
				context.strokeRect(x, y, width, width);

				// fill the odd number rectangles
				if ((i + j) % 2 != 0) {
					context.fillRect(x, y, width, width);
				}
			}
		}
	}
	drawChessboard();
});
</script>
</head>
<body>
<canvas id="chessboardCanvas" width="401" height="401" class="block"/>
</body>

</html>

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 the session, then we redirect the client to the ‘/login’ route. This effectively locks down our routes from unauthenticated access.

function isLoggedIn(req, res, next) {
    if(req.session['FedTokenCookie']){
      next();
    }else{
      res.writeHead(301, {"Location":'/login'});
      res.end();
    }
};
app.get('/mails', isLoggedIn, function(req, res, next){
  ...;
});
app.get('/docs', isLoggedIn, function(req, res, next){
  ...;
});