2012/10/30

App Engine Templates and CSS with Python

HTML is much easier to maintain in App Engine if you use templates. Templates are way of storing you HTML code, it also has syntax to show your application data where you want it to be.

Django's templating engine is included in webapp2 framework.

Here is a sample code how to render html template:

 import webapp2  
 from google.appengine.ext.webapp import template  
 class index(webapp2.RequestHandler):  
  def get(self):  
   self.response.out.write(template.render('index.html', {}))  
 app = webapp2.WSGIApplication([('/', index)])  

Just remember to store your html file in the same folder.

Then you probably want to add CSS to your project? Create folder called css (or whatever you want to call it) and add it as a static directory to your app.yaml:

This will map your "physical" css directory into <project url>/css url.

 - url: /css  
  static_dir: css  

Create your style.css file and refer it in index.html and you are done!

 <link href="css/styles.css" rel="stylesheet" type="text/css">  


2012/10/01

Add Workspaces to Windows using VirtualWin

There is definitely one very important function missing in Windows and that is Workspaces.

Workspaces are "virtual desktops" that you can switch on fly. For instance Workspace 1 can have your browser open, Workspace 2 your applications and Workspace 3 your music player and so on. This makes managing multiple windows alot more simpler and faster.


It didn't take long googling to find this desktop manager called "VirtualWin". VirtualWin is a free software licensed under the GNU General Public License. It works on many Windows operating systems (Win9x/ME/NT/Win2K/XP/Win2003/Vista/Win7)

It looked interesting and i wanted to give it a go.

Setting up application was easy, no need to configure anything if you want to go with default settings. By default VirtualWin has 2x2 workspaces that can be changed to whatever you want in Setup screen. You can bind your own hotkeys for swapping workspaces, default is Control-Alt-Arrows combination, same as in Ubuntu for example!

For me windows was hiding application icon that tells my current Workspace, so i had to change icon behaviour.

Control Panel\All Control Panel Items\Notification Area Icons


Moving windows between workspaces works with Alt-Windows-Right/Left, it feels bit weird since it moves you with the window to next workspace, this can be also changed by changing the bind command from "WIN: Move to next desktop and follow" to "WIN: Move to next desktop".

What a great piece of software, i can only wish that i would have discovered this earlier!

VirtualWin project page





Amazon EC2: Getting started (Part 2/2)

Back to Amazon EC2: Getting started (Part 1/2)

Now our instance is launching, view your instance by selecting "instances" from left navigation bar


















My instance is now running but its still Initializing, so we have to wait until instance is fully launched, this will take couple of minutes. Once "Initializing" will be replaced with something like 2/2 checks passed, instance is ready for use.

Next select your instance and properties windows will be populated with information about your instance. We need public DNS address in order to connect our instance. Private DNS address is used for internal communication of your instances.






Connecting to your server using PuTTY

First you must generate .ppk file from your private key .pem file. Windows users can follow this guide and Linux users this.

Copy paste your Public DNS or IP address to "Host name". Then browse to

Connection -> SSH -> Auth and Browse for your .ppk file and click Open.




















Since you are probably connecting your server for the first time PuTTY will alert you that this host key is not yet in system cache. You can ignore this and press Yes.

In ubuntu server, default login name is ubuntu.





Now we are logged in! Have fun!

If you want to setup LAMP server to your instance. Check out this:

Setting up LAMP in Ubuntu server

Amazon EC2: Getting started (Part 1/2)

EC2 = Amazon Elastic Compute Cloud

In this post we will create EC2 Micro instance.

For now Amazon EC2 has been my weapon of choice for testing out stuff. Instances are easy to launch and if you run it for couple of hours its basically free.

This is very simple guide that runs trough the process of creating a virtual machine in Amazon infrastructure.

I'm not going to cover signing up part, but its easy to do just follow the instructions. You need a valid credit card in order to register.

If you are registering first time to AWS, you will be eligible for Amazon's free tier!

Yes! Free micro instance for 12-months, the performance is not going to rock your world buts its alright to run small website on it. More information about free-tier here

http://aws.amazon.com/ec2/

Once you get your account done you can log into your AWS Console. As you can see EC2 is only one part Amazon Web Services, we are not covering any other services than EC2 now.


















Click EC2 to proceed.

Next up its importat to choose correct region in upper left navigation bar. If you are setting up your instance for your personal testing use, its good to choose region nearest to you.

















Once the region is selected hit "Launch Instance" button in the middle of the screen.





You can either use classical wizard or quick launch, both do the same but in our case Quick launch is quicker (duh) and correct image seem to be at the first page (Ubuntu Server 12.04.1 LTS)

Next set the name for your instance and set the name for your Key Pair. You must also download your key from the Download button next to Name field.

Key Pair? Yes, Amazon provides public/private key pairs, public key goes into your virtual machine and you will be using private key. These keys must match in order to establish a connection to your server.

You can only download this file once while creating the key pair so don't loose it! So I'm going to choose 64-bit Ubuntu server, you can use whatever you want.


Then we review our instance, we have Type t1.micro it is a Micro instance, it has 613 MB of memory poor I/O performance. But for testing purposes it will do fine. Personally at this point i would rename security group since it cannot be renamed afterwards.


You can create your custom security group if you click "Edit details". Check " Create new Security Group", name it and set some kind of description for it. From the "Create a new rule" Dropdown you select predefined groups, choose what you need and click "Add Rule". Here you could restrict from what source IP addresses can access your service, default 0.0.0.0/0 means everyone. 

After you are finished, click Create



Click Save details, then you will return to review windows and click Launch.

Continue to part 2











Generate .ppk out of .pem with Linux (Ubuntu)

Here is a example how to convert .pem to .ppk using Ubuntu.

First you need to install package putty-tools
 sudo apt-get install putty-tools  

After install, all you really need to do is this:
 puttygen key.pem -o key.ppk  

But.. with -P switch you can set passphrase for extra security, this is recommended and easy to do:
 puttygen key.pem -o key.ppk -P -C "My server key"  

It is also recommended to set comment for your key using -C switch, because this string will be prompted to you when you are entering your passphrase.





Note that you can also change passphrase afterwards by using -P switch

 m@box:~/Downloads$ puttygen -P key.ppk   
 Enter passphrase to load key:   
 Enter passphrase to save key:   
 Re-enter passphrase to verify:   

And you are done!