re:Post – Question and Answer platform for AWS Community

Update 2nd December, 2021: The community guidelines have been updated.

If you are on internet and belong to tech industry then you know stack-overflow and other similar forums and platforms where questions are posted and answered with-in minutes by the expert in the field.

AWS has launched a similar platform called re:Post which is going to replace previous AWS forums. re:Post is available for all AWS users including free tier users, its a crowdsourced platform where user can ask their questions and they will be answered by AWS experts, community members, partners and other customers as well.

re:Post has a voting system which allows re:Post users to vote questions and answers based on the quality and detail provided by the user. This is crowdsourced moderation and allows great answers to rank at the top which will help any future users to know which answer is more appropriate.

re:Post has its own community guidelines so make sure to read them, before using the platform.

Frequently asked questions are also very important and should be read before using the platform specially the questions explaining what are different components of the platform e.g topic, tag and community groups.

In my view its a great platform for AWS community and will be really helpful for any new AWS users to get their issues resolved by other AWS users.

How to Use Windows Drive as a Hard Disk On VirtualBox VM

VirtualBox allows you to add new Hard Disks from the UI, you can just goto Virtual machine settings and add new hard disks, but its a bit tricky if you want to use as one of your hard disk partitions as the new hard disk, specially if your host is Windows OS. We are going to use VBoxManage utility which was installed with VirtualBox.

To be able to use any selected hard disk partition on your VirtualBox VM follow the steps below, I am going to give all the details and explanations but my assumption is you at least have an understanding of virtual machines, command line and environment variables.

What is VBoxManage?

VBoxManage utility allows you to configure and control almost all the aspects of VirtualBox which includes creating virtual hard disks, network interfaces configuring your virtual machines and much more.

For the purpose of this howto we are going to use VBoxManage to list the partitions, and then create a virtual disk file which will be pointing to one of the hard drive partitions.

Set up Environment Variable

First we need to set up the “PATH” environment variable, when ever you run a command on command line all the folders specified in “PATH” environment variable are search to find the respective executable.

Click on Start menu and type “system”, click on “System” Control Panel menu item.

System Control Panel App in Start Menu

Click “Environment Variables” in System properties window.

System Properties Window

Under “System Variables” select “Path” variable and click “Edit”.

Select Path Environment variable

Click “New”




Be default VirtualBox is installed in “C:\Program Files\Oracle\VirtualBox”, if you haven’t installed in custom folder location just add this path in the new field.


Find Out The Hard Drive Number

Now we need to find out the Hard Drive number, so we can properly construct the PhsyicalDrive (more on this later) name for VBoxManage utility.

Click on Start Menu and type “hard disk partitions” and click on “Create and format hard disk partitions”.


In the “Disk Management” window note the Disk number from the left side of the disk.


Create Virtual Drive using VBoxManage

Now we are going to create a virtual disk which we will map to one of the partitions of our physical drive. As we have already noted the physical disk number which is “1” so our Physical Drive construct would look something like: “\\.\PhysicalDrive1”

Click on Start Menu and type “cmd”, right-click on “Command Prompt” menu item and click “Run as administrator”.


Run the following command to get the list of partitions, so we can use the partition number in next command:

# VBoxManage internalcommands listpartitions -rawdisk \\.\PhysicalDrive1

You should see an output like following


Now that we know the partition numbers we can map them to virtual disk files and then add those virtual disks to our Virtual Machine.

Run the following command to map partition number 5 from above output to HomeDrive.vmdk

# VBoxManage internalcommands createrawvmdk  -filename "C:\Users\hamekhan\VirtualBox VMs\Hawk\HomeDrive.vmdk" -rawdisk \\.\PhysicalDrive1 -partitions 5

If the command will execute successfully you should see something like


Now goto your virtual machine settings and select navigate to “Storage” from left side then click on the plus sign with hard drive icon under your desired controller.


Click on “Choose Existing” and navigate to the folder where you created the “.vmdk” file and then select the file.


That’s it, now boot your VM and start using the new hard disk in your virtual machine.

Common Errors


If you get the “VERR_ACCESS_DENIED”, make sure you have started the “Command Prompt” with administrator privileges, see first step in “Create Virtual Drive using VBoxManage”.


Use Git Hook to Automate the Deployment of Code to Staging or Production Servers

Continuous integration is an integral part of software development today. Git hooks help us accomplish continuous integration, and I can’t imagine how difficult it would have been without git hooks.

If you use git for development then following can help you setup automated deployment of code to your staging and production servers. I used the following to setup staging environment for one of my Django projects, but it can be used with other type of web applications as well.

I wanted to be able to run the app as it will run in production, so I wanted to use Apache with WSGI to host the application. So when I push the code I wanted following to happen in order:

  1. Update the application code hosted on server.
  2. Restart apache.

Staging or Production Server Setup

You need to host a bare repository on your server. If you already have that you can skip this section, below I will list down the steps to replicate how my server is setup and how git bare repository is hosted.

  1. Create a user to host git repository.
    useradd -m git
  2. Set up the password for new user or if you use key based ssh logins set it up for new user and make sure you are able login to remote machine from your development machine.
  3. Login as git on your server and clone your git repository.
    git clone --bare

    If you run the above command in home directory of git user you will have a new directory created named “<RepositoryName>.git”. Git will automatically add ‘.git’ at the end of bare repository to differentiate them from the non-bare repositories.

  4. Goto your development machine and setup new git remote, I am using ‘staging’ in the following command but you can name it what ever you want.
    git remote add staging
  5. Do a test push to verify everything is working and you can successfully push to your repository on staging.
    git push staging +master:refs/heads/master

Setup Git Hooks For Automated Deployment

If you followed the steps above then your bare git repo will be at “/home/git/<RepositoryName>.git”. But for simplicity we will use following variable names.

Bare Repository Path on Remote Server: <RepositoryPath>
Application deployment path (document root): <AppPath>

  1. Goto your <RepositoryPath>/hooks
  2. Create a script named: post-receive
    Note: It can be a executable script in any language, but I prefer bash for such trivial tasks.
    Note 2: Don’t forget to change the variables in the script as per your setup.

    while read oldrev newrev ref
        if [[ $ref =~ .*/master$ ]];
            echo "Master ref received.  Deploying master branch to production..."
            git --work-tree= \
                    --git-dir= checkout -f
            echo "Restarting Aapche"
            sudo /usr/sbin/apache2ctl restart
            echo "Ref $ref successfully received."
            echo " Doing nothing: only the master \
    branch may be deployed on this server."
  3. Make script executable.
    chmod +x post-receive
  4. Do a git push and you should see output like. Notice the lines starting with “remote:”. These are the outputs from our script.
    Counting objects: 4, done.
    Delta compression using up to 8 threads.
    Compressing objects: 100% (4/4), done.
    Writing objects: 100% (4/4), 375 bytes | 0 bytes/s, done.
    Total 4 (delta 3), reused 0 (delta 0)
    remote: Master ref received. Deploying master branch to production...
    remote: Project update successful... Restarting Aapche
       50244ea..e46a9f0 master -&gt; master

Django Specific Post-receive script

For deployment of Django app there are some extra django specific commands which you might want to run before restarting your apache, so I modified the script that I am using to do following as well before actually restarting apache, and the apache is only restarted if all the commands are successfully completed.

  1. export Python virtual environment path.
  2. source
  3. load the virtual environment
  4. make sure pip-tools is installed
  5. run pip sync to make sure all project dependencies are installed and upto date
  6. run db migrations
  7. collect static files
  8. django check to verify everything is good
  9. restart apache

Below is the script as it is.

while read oldrev newrev ref
    if [[ $ref =~ .*/master$ ]];
        echo "Master ref received.  Deploying master branch to production..."
        git --work-tree=/var/www/MySite \
		--git-dir=/home/git/MySite.git checkout -f
	cat &lt;

Vagrant 101: Basic Virtual Machine Customizations

Vagrant is a powerful too, and it’s power comes from the modifiable, programmable configuration file. The configuration file allows us to define how the guest virtual machine that will be launched by vagrant should look like. If you haven’t already read my very simple Vagrant 101: Getting Started guide, please read it now.

For our examples we will focus on Virtualbox, as I also use it for my day-to-day tasks and it is easily available for all platforms. There are many ways you can customize virtual machine, but imagine keeping your virtual machine customization with your project under version control. Can you see the power it will give you over your development? Can you imagine the possibilities?

Enough talk, let’s see how we can actually do it in Vagrant. Vagrant stores all of the vagrant configuration for a project in Vagrantfile which we already added to our version control. Let’s go it and modify different aspects of our Virtual machine. All the virtual machine customization is done under config.vm.provider section. As we are using virtual box our provider should be virtualbox, so our section will look like following:

config.vm.provider "virtualbox" do |vb|
    # VM Customizations go here

Search for the line config.vm.provider “virtualbox” and add the following customization options.

Modify CPU Configuration

You can modify number of CPUs available to your virtual machine by specifying the the number in this section. For example if you want to assign 2 CPUs to your VM, you can use the following example customization, or else specify your own number instead of 2.

vb.customize ["modifyvm", :id, "--cpus", "2"]

Modify Memory Configuration

Just like you modified your CPU configuration, you can also modify your virtual machine memory configuration, for example if your want to assign your virtual machine 2 GB memory, you can use the following customization option. Remember have to provide the memory size in MBs.

vb.customize ["modifyvm", :id, "--memory", "2048"]

Disable USB 2.0

As I mostly use Virtualbox to do development and don’t need USB access, I can disable it safely, this might be true for everyone at least in 90% of the cases. Disabling USB support on your guest virtual machine is very simple and it requires the following 2 customization options.

vb.customize ["modifyvm", :id, "--usb", "off"]
vb.customize ["modifyvm", :id, "--usbehci", "off"]

How to apply the changes?

Find the status of your virtual machine using status command.

vagrant status

If your virtual machine is already running, use the reload command.

vagrant reload

If your virtual machine is not running, just use the up command.

vagrant up

What else can be customized?

By now you might be wondering what aspects of your virtual machine you can customize. Almost all of them, to see the list of options, use the following command (tested on linux)

vboxmanage modifyvm

The above command will show you all the options available, you just need to use the option in Vagrantfile in the same way we have modified the CPU and memory above and provide the correct values depending on the feature you are customizing.

Complete section.

Just for your verification and to clear any confusion you might have, your config.vm.provider section should look like following:

customize.vm.provider "virtualbox" do |vb|
  # Assign 2 CPUs
  vb.customize ["modifyvm", :id, "--cpus", "2"]
  # Assign 2 GB Memory
  vb.customize ["modifyvm", :id, "--memory", "2048"]
  # Disable USB
  vb.customize ["modifyvm", :id, "--usb", "off"]
  vb.customize ["modifyvm", :id, "--usbehci", "off"]

What’s next?

In the next few articles I will write about shared folders, networking, sharing and provisioning which are other powerful options vagrant provides you. Let me know in comments if you have any other questions regarding these basic VM customziations?

Vagrant 101: Getting Started

Although late to party, but finally I joined. Until now I had been manually managing my VMs in Virtualbox without Vagrant, but that process was very tedious and slow. Find the image, download it, import it, boot the machine, configure networking, assign the IP addresses, setup the machine. But with Vagrant its as easy as:

Note: Dont’ worry about what it means, I will explain in later chapters.

vagrant init <url to box>
vagrant up
vagrant ssh

As you can see how easy it is to get your new sandbox environment up and running within few minutes. Its not just the basic setup, but Vagrant allows you to completely setup your new VM with everything you need in your dev environment.

The great part is you don’t have to leave your local machine to write code. Confused? Vagrant actually mounts your local folder (where you ran vagrant init) in your VM, so what ever changes you make on your local machine will be available in your vagrant box.

Let’s Dive into Vagrant

Enough of the praising, let’s dive in and experience the power of vagrant. First you need to find Vagrant boxes (VM images), so you can use them for your development. The following instructions assumes that your are using some flavor of linux (the concept is same for other OS, you just have to convert the commands as per your OS).

The best place to find the Vagrant boxes are Vagrant Cloud. Once you find the suitable box for your development. Create your development directory and do the vagrant init (remember git or hg init?) with the the name of the box from Vagrant Cloud. See the commands below:

mkdir web-app-dev
cd web-app-dev
vagrant init hashicorp/precise32

This will create the Vagrantfile and add the box name to the Vagrantfile. You are ready to launch your first vagrant controlled sandboxed dev environment. Just run the vagrant up to get the VM up and running. See the example below (run the command in same folder where you ran vagrant init):

vagrant up

This will download the box (VM image) from the Vagrant cloud, after downloading it will boot the box, do the provisioning and then it will mount your development folder on VM at /vagrant. After few minutes your new VM will be up and running.

Once the VM is up, you can login to the VM by just doing a vagrant ssh. Yes it is this simple, see the example below:

vagrant ssh

Now that you are logged into the VM, you can configure it for your development manually (for now). Later on I will write about how can you automate the setup part too, based on your development needs.

Checkout the folder share, by creating files in /vagrant folder on your new VM and then go back to your local folder and see them appear there. Similarly you can create files on local and they will immediately appear in your VM.

Where is the Version Control?

You can add Vagrantfile to your version control so you can replicate your Vagrant setup to other devs or on other locations too. Don’t add other Vagrant files to version control, for now it is just Vagrantfile. Simply just run the following commands (from same folder where you ran vagrant init):

git init
git add Vagrantfile
git commit -m "Add Vagrantfile"

What’s next?

I tried my best to make this getting started guide as simple as I could, and not be confusing for the new developers who are still trying to figure out how linux works. Later on I will write about provisioning and advanced networking setup in Vagrant.

If you have any questions, confusions feel free to ask them in comments and I will try to help you as much as I can.

Securing your Linux VPS For dummies

Almost everyone have their own VPS now a days which is running some kind of Linux flavor. Usually people just get the VPS and start using it straight away, without even doing the basic security and setup.

I thought I should write the basic security measures that should be done on a brand new VPS. These steps are no way meant to completely secure your server, but at the very least these steps will make it harder for newbies or wannabes to get break into your server.

Got root?

First thing first, change the root password. Root is the most powerful user on any linux server, make sure you change the password immediately as soon as you get the VPS from your VPS provider.

Login as root and the following command to change your root password.


SSH: the door to your server.

Change SSH port to some non-default port. The path of sshd configuration file is:

It is never a good idea to keep running the SSH service on the default port which is port 22. Find the line starting with Port and change your port. See the example below.

Port 2014

Disable root login, Find the line starting with “PermitRootLogin” and set it to no, see the example below.

PermitRootLogin no

Restart the sshd service.

service sshd restart

Wanna be a Cop?

In third world countries when cops are looking for bad guys, they close down all the roads and only allow the traffic on the road they are monitoring so they can check all the cars passing through.

Similarly you should close all the ports to your server and only allow ports that you use. Just make sure you allow the new non-default SSH port that you have set above or otherwise you will lock out yourself from your own server.


You can do more to make your server more secure, for example Google 2-Factor authentication for SSH, install fail2ban, etc etc. Want to know more? Want to secure more? Let me know in comments and I will try to help as much as I can.

Howto Setup Vim IDE for PHP Development

As a PHP developer one has quiet a lot of choices of IDE. Some are graphical will built-in features like debugging, code completion, auto indentation, syntax highlighting, code checking and many more. But those IDEs are very heavy and slow to use, and I know many people like me who just can’t live without Vim and want to use Vim for all type of text editing they do, whether they are writing code, editing configuration files or may be creating simple text files.

Recently I posted a screenshot of my Vim editor and got a lot of emails that how did I setup Vim that way. So, I hope this howto will be easy enough for everyone to follow and setup their Vim as their PHP  IDE. For the sake of simplicity I am assuming you are using Vim on Linux or Linux like system. If you are a windows user then this guide should still work for you, but I might not be able to provide Windows related details where needed.

Features that we will add or enable in Vim to make it a complete IDE.

  • Code Completion
  • Tag Lists
  • Project Management
  • Syntax Highlighting
  • Code Checking

First we need to download following Vim scripts and extract them in our ~/.vim directory.

Download above scripts one by one and install them. Installing them is easy just unzip them in you .vim directory which is located in your home directory. Now we need to download few files in our .vim/plugin directory. Download the following Vim scripts directly into your .vim/plugin directory.


Now that you have installed above scripts, you are almost all set to go. You just need to paste the following content in your .vimrc file which is located in your home directory.

" ~/.vimrc                                                      "
"                                                               "
" Version: 0.1                                                  "
"                                                               "
"                                                               "
" Hightlight the ifs and buts
syntax on
" Plugins and indentation based on the file type
filetype plugin indent on
" Don't remember source of this, i think it was already in my .vimrc
" Tell vim to remember certain things when we exit
"  '10 : marks will be remembered for up to 10 previously edited files
"  "100 : will save up to 100 lines for each register
"  :5000 : up to 5000 lines of command-line history will be remembered
"  % : saves and restores the buffer list
"  n... : where to save the viminfo files
set viminfo='10,\"100,:5000,%,n~/.viminfo
" omnicomplete from:
set completeopt=longest,menuone
inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
inoremap <expr> <C-n> pumvisible() ? '<C-n>' :
  \ '<C-n><C-r>=pumvisible() ? "\<lt>Down>" : ""<CR>'
"##       PHP             ##
" The php doc plugin
" source ~/.vim/php-doc.vim
inoremap <C-P> <ESC>:call PhpDocSingle()<CR>i
nnoremap <C-P> :call PhpDocSingle()<CR>
vnoremap <C-P> :call PhpDocRange()<CR>
" run file with PHP CLI (CTRL-M)
:autocmd FileType php noremap <C-M> :w!<CR>:!/usr/bin/php %<CR>
" PHP parser check (CTRL-L)
:autocmd FileType php noremap <C-L> :!/usr/bin/php -l %<CR>
" Do use the currently active spell checking for completion though!
" (I love this feature :-)
set complete+=kspell
" disable tabs
set expandtab
set shiftwidth=4
set softtabstop=4
" highlt matches
set hlsearch
" Taken from
" Make Vim open and close folded text as needed because I can't be bothered to
" do so myself and wouldn't use text folding at all if it wasn't automatic.
set foldmethod=marker foldopen=all,insert foldclose=all
" Enable enhanced command line completion.
set wildmenu wildmode=list:full
" Ignore these filenames during enhanced command line completion.
set wildignore+=*.aux,*.out,*.toc " LaTeX intermediate files
set wildignore+=*.jpg,*.bmp,*.gif " binary images
set wildignore+=*.luac " Lua byte code
set wildignore+=*.o,*.obj,*.exe,*.dll,*.manifest " compiled object files
set wildignore+=*.pyc " Python byte code
set wildignore+=*.spl " compiled spelling word lists
set wildignore+=*.sw? " Vim swap files
" Enable completion dictionaries for PHP buffers.
autocmd FileType php set complete+=k~/.vim/dict/PHP.dict
" PHP Autocomplete
autocmd FileType php set omnifunc=phpcomplete#CompletePHP
set ofu=syntaxcomplete#Complete
" You might also find this useful
" PHP Generated Code Highlights (HTML & SQL)                                              
let php_sql_query=1
let php_htmlInStrings=1
let g:php_folding=2
set foldmethod=syntax
" --------------------
" Project
" --------------------
map <A-S-p> :Project<CR>
map <A-S-o> :Project<CR>:redraw<CR>/
nmap <silent> <F3> <Plug>ToggleProject
"let g:proj_window_width = 30
"let g:proj_window_increment = 150
nnoremap <silent> <F8> :TlistToggle<CR>
let Tlist_Exit_OnlyWindow = 1     " exit if taglist is last window open
let Tlist_Show_One_File = 1       " Only show tags for current buffer
let Tlist_Enable_Fold_Column = 0  " no fold column (only showing one file)
let tlist_sql_settings = 'sql;P:package;t:table'
let tlist_ant_settings = 'ant;p:Project;r:Property;t:Target'
" auto change directory from:
autocmd BufEnter * if expand("%:p:h") !~ '^/tmp' | lcd %:p:h | endif
" when we reload, tell vim to restore the cursor to the saved position
augroup JumpCursorOnEdit
 autocmd BufReadPost *
 \ if expand("<afile>:p:h") !=? $TEMP |
 \ if line("'\"") > 1 && line("'\"") <= line("$") |
 \ let JumpCursorOnEdit_foo = line("'\"") |
 \ let b:doopenfold = 1 |
 \ if (foldlevel(JumpCursorOnEdit_foo) > foldlevel(JumpCursorOnEdit_foo - 1)) |
 \ let JumpCursorOnEdit_foo = JumpCursorOnEdit_foo - 1 |
 \ let b:doopenfold = 2 |
 \ endif |
 \ exe JumpCursorOnEdit_foo |
 \ endif |
 \ endif
 " Need to postpone using "zv" until after reading the modelines.
 autocmd BufWinEnter *
 \ if exists("b:doopenfold") |
 \ exe "normal zv" |
 \ if(b:doopenfold > 1) |
 \ exe "+".1 |
 \ endif |
 \ unlet b:doopenfold |
 \ endif
augroup END
" PHP code sniffer
" If code sniffer is installed you can run it on current php file by running 
" :Phpcs
function! RunPhpcs()
    let l:filename=@%
    let l:phpcs_output=system('phpcs --report=csv --standard=YMC '.l:filename)
"    echo l:phpcs_output
    let l:phpcs_list=split(l:phpcs_output, "\n")
    unlet l:phpcs_list[0]
    cexpr l:phpcs_list
set errorformat+=\"%f\"\\,%l\\,%c\\,%t%*[a-zA-Z]\\,\"%m\"
command! Phpcs execute RunPhpcs()

Thats it, now you are all set to go. Following are the few quick commands to get you started to use all the features you have just enabled in your Vim IDE.

F3: To start using project manager.
\C: After starting project manager this key combination will allow you to add new project.
F8: Tag list window
Ctrl+L: To run the syntax checking on your php file
Ctrl+P: On any class/function definition to add php doc strings
“:PhpCs”: To run PHP Code sniffer on your php script. (this requires code sniffer to be installed).
Ctrl+n: On any word to use Auto completion feature of PHP.

I will soon write another howto to explain how can you use further features of your IDE. You should subscribe to the feed or follow me on twitter to stay updated. 🙂

Develop Your First Android Application in Python

Android is getting popular among mobile users very rapidly, and the fact that Android’s user base is increasing the demand for more usable applications on Android is increasing too. The demand for more applications is causing more and more developers to get into Android development, unfortunately until now the only way to develop for Android was to develop in Java.

But thanks to Google that one of their employee has come up with a solution that allows not only Python programmers but Perl, lua and bash programmers to develop on Android. The new project that has come out from Google is called SL4A and it allows you to use Python to develop for Android. You can get to know more about SL4A from the home page of the project on Google Code. This article tells you the exact steps you can take to setup Android SDK, Install SL4a and Python for Android and then Write your first Android Application in Python and run it.

Setup Android SDK and Android Virtual Device.

First you will have to download latest Android SDK from Google and setup your Android Virtual Device. If you like you can directly develop your Android application on your phone device. Skip to “Installing SL4A and Python for Android” if you want to directly develop on your phone.

1. Download Android SDK. For Linux download the tar ball and for Windows download the executable (recommended).

2. Install the SDK. You might also want to read the Installing the SDK document on Android’s developer site.

On Linux:

Extract the tarball in any directory of your choice.

On Windows:

Run the executable to install the Android SDK.

3. Go into the “tools” directory inside the extracted or installed directory.

4. Run the “android” executable.

On Linux:

$ ./android

On Windows:

Double click the executable to run it.

5. The android executable will start the Android SDK and AVDManager.

AVD (Android Virtual Device) manager

6. Click on the Create New AVD to setup the new AVD for your Android application development.

Create new AVD

7. When the new AVD is created, select it and click on Start. You will see a Android device emulator screen and an Android Logo, the Android OS is booting, you will have to wait for some time. After some time you will get a fully loaded Android OS on your Android emulator to develop and test your Android Application.

Android Emulator

Installing SL4A and Python for Android

Scripting Layer For Android is the main Android Application you need to be able to run your Python applications on Android, so first you need to install SL4A on either your Android emulator or on the real Android device in case if you are going to do the development directly on your device. Follow the steps below to install the SL4A on your Android.

1. Open Android Browser and browse to the SL4A home page:

2. Tap on the QR code icon (the big square box) to download the SL4A application.

Android Browser SL4A home page

3. Tap on the download notification to install the app.

4. Once the installation is complete tap OK and then go back to SL4A home page on your Android Browser.

5. Tap on Python for Android in the Featured Downloads section to download Python for Android.

SL4a Python for Android Download

6. Tap on the download notification to install Python for Android.

7. Once the Installation is complete go to SL4A application which is located under your applications menu. You will see some python scripts that got Installed along with Python for Android.

SL4A Python for Android Test

8. Tap the, a menu will popup.

SL4A run menu

9. Tap the second icon from left. The script will execute and will demonstrate some of the possibilities of the SL4A API available for your Python programs.

Note: The most left icon is to run the application in terminal, the second from left is to run the application normally, the third from left is to edit the script, the fourth from left to rename the script and the last one from left is to delete the script.

Writing the First Android Application in Python

Now that our Android is ready and you have already tested that everything is working fine, its time to write your first Python application. You will write a very simplest version of hello world, this application will ask your name and then it will greet you. Thats it.

1. Copy the following code to on your computer.

import android
app = android.Android()
name = app.dialogGetInput("Enter your name:", "Please enter your name: ").result
app.dialogCreateAlert("Greetings!!!", "Hello %s, how are you?" % name)

2. Goto “platform-tools” directory which is found under the Android SDK directory.

3. Copy (push) the to your Android by running the following command.

$ ./adb push /sdcard/sl4a/scripts/
4. Press the menu button on your Android device or Android emulator, and tap Refresh.

5. will appear in the script listing, tap the script.

6. The SL4A run menu will appear, click the second icon from left.

SL4A First Python Android Application

7. A popup will appear asking you for your name, enter your name and click OK.

SL4a first Python Android Application running

8. Another popup will appear with a greeting message for you.

SL4A Greetings


Congratulations!!! You are done here. Its now up to you how you make use of the Android API available via SL4A. Best of luck.

You should subscribe to the feed to stay updated about the next article that will describe how you can build a stand alone .APK application from your Python script.

Vim as PHP IDE

If you think Vim is just another text editor then think again. Vim is not a text editor, neither its an IDE, its everything.

Here is just a small screenshot of Vim on my machine being used as IDE for the PHP project, a howto and other details will soon be up on this blog as soon as I finish the project.

Vim as PHP IDE

UPDATE: I have wrote “How to Setup Vim IDE for PHP Development“.

You might want to follow me on twitter or subscribe to RSS Feed to get future updates on the topic.

Howto Enable HTML5 Offline Cache For Your Web Site

Web Sites are getting more and more responsive every day and are literally competing with desktop applications and hence they are now called web applications rather then web sites. If your website or web application is not responsive enough then chances are that your user might leave your website and goto some other similar app which is more responsive.

The faster your web site is the more enjoying and productive experience it brings to your users. There are many ways to speed up you web site specially like using extended expiry dates, compressing the contents, etc etc. But with the HTML5 you have got the offline storage which allows you to not only cache your static content locally on the browser but allows your users to view your site even when they are offline.

Lets see how we can make our website HTML5 compatible and enable offline storage for browsers that support it (almost all latest browsers).

Add HTML5 Doctype

First you need to add HTML5 Doctype to your html, Doctype tells your browser what type of Document Type Definition applies to this particular HTML document. HTML5 comes with the most simplest Doctype as compare to other versions. The Doctype needs to be added to the first line of your HTML document and it should be the first thing of your HTML document. The Doctype of HTML5 is as follows:

<!DOCTYPE html>

Your document should look like this after adding the doctype:

<!DOCTYPE html>

Create a Cache manifest file

The Cache manifest file lists all of your static resources that should be cached. The Cache manifest file’s syntax is very easy but provides all sort of possibilities to list your resources which should be cached and which shouldn’t be. The whole post can be dedicated to explain different possibilities of offline caching, but for this very first post on the topic we will stick to the basic cache manifest file which will list few css, javascript and image files to be stored offline.

Create a cache manifest file named ‘offlinecache.manifest‘ and add the following content:

# version: 01
# List files that should be cached under CACHE
# List the resources that shouldn't be cached and requires network
# Note you can use * to specify all the resources that are not listed under CACHE

Add Cache manifest Mime-Type

You can name your cache manifest file anything the only requirement is that it should be sent to browser with the mime type “text/cache-manifest“. Assuming that your web site is hosted on Apache, and you have named your cache mainfest file as “.manifest”, you will need to add the following to the your .htaccess file:

AddType text/cache-manifest manifest

Publish your Cache manifest file

Now that your cache manifest file is ready to be served to the browser, you need to tell your browser about the manifest file location. The manifest file location needs to be added to the opening tag of html element with manifest attribute like following:

<html manifest="offlinecache.manifest">

You can specify absolute path or relative paths in the same way as you specify other URIs, if you have store your manifest file in the root of your document tree then your html file might look something like:

<!DOCTYPE html>
<html manifest="/offlinecache.manifest">


Congratulations!!, If you have followed everything till here, your website will now make use of HTML5 offline storage as cache for static resources.