Mount a usb drive or hard disk on Raspbian

What’s the best way to auto mount a usb drive or hard disk? What if the filesystem is ntfs?

To get a list of connected usb disks you can:

sudo blkid

In the screenshot above you can see there are two usb devices:

  • /dev/sda1: UUID=”E89484EA9484BC96″ TYPE=”ntfs” PARTUUID=”008ffb75-01″
  • /dev/sdb1: LABEL=”Extern station” UUID=”92FA278AFA2769A5″ TYPE=”ntfs” PARTUUID=” 0009a8db-01″

To be able to use these devices, you have to mount them in a folder. Let’s create two folders:

sudo mkdir /mnt/usb1
sudo mkdir /mnt/hd1

The usb1 folder I’ve created for my usb stick. The hd1 folder for my external hard drive.

We need to take ownership of these folders:

sudo chown -R pi:pi /mnt/usb1
sudo chown -R pi:pi /mnt/hd1

If any of the usb devices is formatted in ntfs, you best install ntfs-3g:

sudo apt-get install ntfs-3g

Now let’s edit our file system table, so that the usb stick & external hard drive are mounted every time the system boots:

sudo nano /etc/fstab

As you can see in the screenshot above I’ve used the disk UUID as name to find it. This way, if you unplug your usb flash drive and put it in another usb port, it still works. As type, make sure to use ntfs-3g.

Now you just need to reboot and the disks are both mounted!

sudo reboot

For completeness, you could also mount the usb stick just once with this:

sudo mount -o uid=pi -o gid=pi -t ntfs-3g /dev/sda1 /mnt/usb1

Sources

 

iBeacon Scanner Android

At In The Pocket‘s Harald I’ve developed a library for Android: the iBeacon Scanner Android library.

This library takes the pain away when you want to scan for iBeacons on Android. You register the iBeacons you are interested in and via a callback you are notified when you enter or exit the range of an iBeacon.

You can read more about this on In The Pockets developer blog.

On top of that I created 2 apps that build upon this library:

  • iBeacon Scanner scans for all the iBeacons around you and displays them.
  • iBacon allows you to broadcast an iBeacon via your bluetooth chip on your Android phone.

The singleton

While I agree that a Singleton shouldn’t be used to often, I do want to share my favourite way to implement the singleton pattern for reference.

public class Example
{
    private static Example instance;

    private Example()
    {
        // this class cannot get instantiated
    }

    public static Example getInstance()
    {
        if (instance == null)
        {
            instance = new Example();
        }

        return instance;
    }
}

Going to Choquequirao!

In October of 2015, my girlfriend and I went to Peru. One of the highlights of the trip was our trek to Choquequirao! I want to share what we have learned about this fantastic trek!

Choquequiroa

They call it the sister of Machu Picchu! It’s a city built by the Incas and abandoned in 1572 because of the Spanish invasion. In regard to Machu Picchu, the city is not sacred. Probably more like a  civil centre, a city for the nobility. The location is awesome, it’s located in the Andean at 3000 kilometres. You really feel like close to the gods!

You can’t get there by car, bus or cable lift. Despite that this will probably change in the near future, now is the perfect moment to go there!

The hike is really exhausting, the path is about 15 to 20 kilometres and you have the cross a valley. This means 1 kilometre down and up. Unfortunately there is only 1 way, so you will walk the same path twice. The view of the Andean along the way is really stunning and the city itself is amazing because how hard it is to get there!

A trek?

Yes, we did this trek with BioAndean Expeditions. It’s really a luxury. This is what you get:

  • A porter with some mules to carry all the equipment and your spare stuff.
  • A cook who makes brilliant food.
  • A guide (in our case, he was a big disappointment).

If you have a good guide he will take care of you and tell loads along the way. Because there is so much to like:

  • Tarantula’s!
  • Kolibries & other awesome birds!
  • Wild avocado!
  • Exotic plants
  • Spiders
  • Butterflies

Spending so much money on this guided trek was a big mistake, given the poor service we have got. This is why I wrote this article, so you can do it on your own!

How busy is it?

There are not too many people, but you are also no longer alone on this trek. Adventurous people start to know, and it’s only normal! Most people we have met prefer Choquequiroa above Machu Picchu!

Being on the same path, you will see the same people quite often again because most people have about the same pace but take breaks on different spots. About half of the people we met were doing this on their own!

Do it by yourself!

The price

With a trekking organisation you can easily pay about 1500 soles per person to the organisation, and like 50 for water and other (not included) things. And on top of that you should also pay tips, like 150 or more soles. So this could total 1700 more or less.

Whereas if you walk on your own you probably have enough with 200 – 500 soles. The difference is big!

Getting there

You have to use public transport to go to Cachora. You can easily ask this in the Tourist Office of Cuzco. A bus or 2 will you take there, and it is absolutely cheap!

The hike

Camping equipment

Renting a small tent is possible in Cuzco, one French couple told us they paid 140 soles to rent a very good looking tent for 5 days. We went in spring, and a regular sleeping bag should be enough. I used a very small one to save space. Only 1 night I had cold, and wearing clothes inside my sleeping bag has enough to not feel the cold. And please you don’t need walking sticks. Many Peruvians leave their bamboo walking sticks at the first shop/restaurant where the path really begins.

Sleep

Every 3 hours you almost meet a place where you can camp. As you can see on the map. They are very welcoming, sleeping was 5 soles a night and included the toilet and cold shower.

Food and drinks

Don’t bring too much water. The most expensive water we bought from one of the shops was 12 soles for 2 litres. Given the effort to get the water there, that’s a very fair price I think. Most of the camp sites offer food and can prepare you a good meal. They also sell snacks and coke. And don’t worry, you only need to speak a few Spanish words. If you can say “Hi” and can count you will be fine. Don’t worry about this, many tourists walk this trail, so if needed you can always ask help from them, as they maybe speak more Spanish.

Compare objects in java

If you want to compare if plain old java objects have the same properties, it is easiest to override the equals method.  This way, if you initialise objects on different places, you can be certain when comparing that they are the same.

We will show you how to do it with this simple class:

public class Insect
{
    private int legs;
    private int eyes;
    private int colour;
    private String sortName;
}

Override equals

@Override
public boolean equals(Object o)
{
    if (this == o)
    {
        return true;
    }

    if (o == null || this.getClass() != o.getClass())
    {
        return false;
    }

    final Insect that = (Insect) o;

    if (this.legs != that.legs)
    {
        return false;
    }

    if (this.eyes != that.eyes)
    {
        return false;
    }

    if (this.colour != that.colour)
    {
        return false;
    }

    if (this.sortName != null ? (this.sortName != that.sortName) : (that.sortName != null))
    {
        return false;
    }

    return true;
}

Override hashCode()

@Override
public int hashCode()
{
    int hash = super.hashCode();
    hash = 14 * hash + this.legs;
    hash = 14 * hash + this.eyes;
    hash = 14 * hash + this.colour;
    hash = 14 * hash + (this.sortName != null ? this.sortName.hashCode() : 0);
    return hash;
}