logo

Setup your own (free) private VPN service on Amazon EC2 with OpenVPN

This tutorial will show you how to create your own VPN server on Amazon Web Services – Elastic Compute Cloud (in short: EC2).

A VPN service can be used for a lot of things, for example:

  • Testing your websites or services from another countrys ip
  • Accessing content on some sites with ip address block, such as hulu or netflix
  • Connect your computer and/or mobile phones and tablets that support VPN
  • Safely accessing internet on public unsecure wifi networks!

I find that last point especially important. A VPN connection can prevent someone from picking up your login details if you are using a public wifi network; If some of the programs/apps you are using, send sensitive data such as login details or cookies over http instead of https, the details can be picked up by others sniffing around on the network.

There are many different VPN services available, most of them charge a couple of dollars per month (e.g strongvpn.com charges $21 for 3 months), and many are often on shared connections, often giving you a slow or unstable connection.

By setting up your own VPN service, you can fully control access to it, and even allow others to use your VPN server. Depending on your level of skills, setting this VPN server up can take as little as 15 minutes.

Why Amazon EC2

EC2 is Amazons virtual servers in the cloud, where you can set up your own virtual private server (VPS). EC2 instances come in a lot of different sizes, and are charged hourly and by usage. You can of course set up a VPN service on almost any VPS, but heres the reasons why I chose EC2:

  • It’s widely available to everyone
  • They have a lot of services available from one web interface
  • They have a large library of Amazon Machine Images (AMI’s) which are predefined images with different setups, often making installation and configuration a breeze.
    (We will be using an AMI later in this guide)
  • It’s not the cheapest, nor the most expensive place to setup a VPS
  • They have something called “AWS Free tier” which is a great offer to newcomers, letting people try out the different services for free!

So basically, if you are eligible for their free tier, you can get a free VPS server for a whole year. With this, you can for example setup a VPN server like we are about to right now!

As an alternative, you could for example use a Linode VPS to create this VPN server on.

Continue reading

Android AVD with HW acceleration complaining about ‘memory exceeds the driver limit’

Having problem with the Android AVD manager complaining about the memory limit of your AVD when trying to boot an hardware accelerated android emulator?

Starting emulator for AVD 'android-avd-name'
emulator: The memory needed by this VM exceeds the driver limit.
HAX is not working and emulator runs in emulation mode

The problem is that the memory allocated by the device preconfigurations has been set higher than the memory limit you allocated to Intel HAXM when you installed it.

Change the RAM value under Memory options to a lower value, save the avd, and try starting it again.

avd-settings

When working properly, the emulator output should instead show:

Starting emulator for AVD 'android-avd-name'
HAX is working and emulator runs in fast virt mode

And the emulator should boot rather quickly.

Note: Remember to check the “Use host GPU” option for x86 images, and also remember to look for updates to your Intel HAXM installation, as it has been known to contain different bugs.

dialog-300x249

Creating a nice looking List dialog with images and text

This tutorial, will demonstrate how you can create a great looking selectiondialog, containing both text and images.

alt text

This list can then be used either directly in an Activity, Fragment, or as an Activity looking like a dialog. In this example, I will go with the latter, and create an activity that looks like a selection dialog window, that, in this case will be used to choose a country.

Creating such a selection list is easy if it should contain text only, but a bit more complicated if you also want to include images.

Continue reading

lp-mini-review2

LastPass Mini Review

I have been trying out Lastpass as chrome extion, and mobile app for a few days, and heres a couple of things I have come across, as an avid Keepass user.

Feature requests

  • Tags – So I can group together items for different situations
  • Item duplicate – To avoid having to copy paste a lot of data
  • Ability to move a folder into another folder. Now I have to create a new folder where I want to move the items, move all the items, then delete the old foler.
  • Secure notes with a password and username field. Just like a “site”, except it does not have a url. It would be perfect to use in e.g mobile app logins. Why does this not exist?

Things I wonder about

  • Are all data encrypted? Also comment fields?
  • Why does the “view my deleted items” go to a lastpass.com website, instead of the chrome plugin?
  • How often does LastPass synchronize items, and does it do delta-sync? (and is that one item at a time?)
  • The security. Having my (encrypted) data stored at some companys server
  • Why does “secure notes” have a “copy username” and “copy password” context menu, when a regular secure note does not have these fields?

Problems importing data from Keepass

I have tried to import entries from Keepass, using the keepass xml export functionality. The basic import works, however there is quite a few quirks.

  • Import from Keepass is automatically turned into Lastpass “secure notes” if they are missing and url. I then have to create a new “site entry”, enter an url, and copy the data over there. Instead of being able to just add an url field afterwards, if it is missing.
  • Import from Keepass, sometimes triples, or quadruples all the text in the comment field!
  • Import from Keepass messes up special norwegian characters “æøå”

Bugs?

In addition to the bugs mentioned in the section above:

  • File attachments for secure notes in lastpass, loose their filenames. When saving such a file to disk from lastpass, the filname field is completely blank, but the file extension seems to be correct. This makes it impossible to know which file I am actually saving…
  • Updating sites and secure notes with file attachments is a mess, sometimes it does not work to delete attachments.
  • I cannot find the “History” tab for secure notes, to view a notes history, although it’s described here.

Things I miss from Keepass

  • Having the option in Keepass to use a password and a keyfile, for extra security.
  • Better control over the entries, with entry duplication, change history and more
  • Can use keyfile in addition to the password
  • Better overview of all folders and items
  • Being able to view attachment file sizes
  • Being able to see which entries that have attachments in the main list

Things I don’t like about Lastpass

  • The folder dropdown dialog when creating a new site or secure note. This list becomes quite ugly after adding a couple of folders

Things I like about LastPass

  • Browser integration
  • Syncing
  • Mobile app

Now, these things you may be able to do with Keepass and plugins, and by syncing the database over Dropbox, but that is a tad more cumbersome.

buttons-with-separators3

How to create simple view separators

This will show you three ways to create nice looking view separators, to use between a row of buttons for example.

The examples shows a LinearLayout with three buttons, that should get separators in between them.
The third example may be the easiest one to implement, while the other ones gives you better customizability.

buttons-with-separators3

 

 

Method one – Manually adding a view separator to the LinearLayout

We can create a simple View that represents the separator, and just add it in between our buttons.

As a separator, we can use a view like this:


<View

android:layout_height="fill_parent"
android:layout_width="1dp"
android:background="#90909090"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
/>

So the whole layout, as pictured, becomes:


 <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true"
    android:orientation="horizontal">

    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        style="?android:attr/buttonBarButtonStyle"
        android:text="Yes"
        android:layout_weight="1"
        android:id="@+id/button1"
        android:textColor="#00b0e4" />

    <View android:layout_height="fill_parent"
        android:layout_width="1px"
        android:background="#90909090"
        android:layout_marginBottom="5dp"
        android:layout_marginTop="5dp"
        android:id="@+id/separator1" />

    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        style="?android:attr/buttonBarButtonStyle"
        android:text="No"
        android:layout_weight="1"
        android:id="@+id/button2"
        android:textColor="#00b0e4" />

    <View android:layout_height="fill_parent"
        android:layout_width="1px"
        android:background="#90909090"
        android:layout_marginBottom="5dp"
        android:layout_marginTop="5dp"
        android:id="@+id/separator2" />

    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        style="?android:attr/buttonBarButtonStyle"
        android:text="Neutral"
        android:layout_weight="1"
        android:id="@+id/button3"
        android:textColor="#00b0e4" />

</LinearLayout>

Method two – Specifying a divider for the LinearLayout

As pointed out by Paul Burke in the comments, you can specify a view divider on the linearlayout. This is obviously a better solution (and the solution I was searching for), that also works when you are dealing with an unknown number of items.

This methods only works for API level 11 and higher.

Create a new file called separator.xml in the drawable folder:


<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
 <size android:width="1dp" />
 <solid android:color="#90909090" />
</shape>

We can then use this separator in our LinearLayout like this:


 <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true"
    android:divider="@drawable/separator"
    android:showDividers="middle"
    android:orientation="horizontal">

    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        style="?android:attr/buttonBarButtonStyle"
        android:text="Yes"
        android:layout_weight="1"
        android:id="@+id/button1"
        android:textColor="#00b0e4" />

    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        style="?android:attr/buttonBarButtonStyle"
        android:text="No"
        android:layout_weight="1"
        android:id="@+id/button2"
        android:textColor="#00b0e4" />

    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        style="?android:attr/buttonBarButtonStyle"
        android:text="Neutral"
        android:layout_weight="1"
        android:id="@+id/button3"
        android:textColor="#00b0e4" />

</LinearLayout>

The important part here is on the LinearLayout:

android:divider="@drawable/separator"
android:showDividers="middle"

 

Method three – ButtonBarStyle (the easiest way for default separators)

As danialgoodwin mentioned in the comments, adding the buttonBarStyle to the LinearLayout will show default separators.  This is also for api level 11 or higher only.

The important part here, is adding this line to the LinearLayout:


style="?android:buttonBarStyle"

And the whole code will look like this:


    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        style="?android:buttonBarStyle"
        android:dividerPadding="15dp"
        >

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="New Button"
            android:id="@+id/button1"
            android:layout_gravity="center_vertical" />

        <!-- more buttons/views -->
        
    </LinearLayout>

You can also adjust the paddings of the view separators with the “dividerPadding” setting.

 

The buttons will also use an equal amount of horizontal space, so they all get the same size.

You could also create gradient drawable shapes for separators.