How to draw a spring in Inkscape

Update: Check out the new spring drawing method here. The old one on this page is still useful, but the new one is a bit faster.

I’ve been working on some free-body diagrams lately, and in my last paper I needed to draw a spring. Since I didn’t find any simple way to do this, I thought I should give a quick tutorial here.

First of all, turn on the grid by clicking SHIFT + 3 on your keyboard (the # key).

When your grid is turned on, enable the bezier curve editor by clicking this button:

Continue reading How to draw a spring in Inkscape

Automount an SSH server in Ubuntu

If you ever need to mount an SSH server in Ubuntu, this is probably the easiest way to do it. This method uses a public/private key pair to authenticate with the server, making the whole process work without passwords.

If you don’t  have SSH available to host, but you’ve got a Windows shared directory, I suggest you have a look at a tutorial I’ve written earlier on that topic.

Generating a key pair

You are probably used to connect to your SSH host using a login and a password. This might seem secure, but there is actually another way which is much more convenient, and much more secure. That way is the way of a public/private key pair. If it sounds a bit advanced I will give you a short explanation in a moment, but first you should know that you are not to worry about doing this. It’s quite easy to set up an SSH key pair in Ubuntu.

A private/public key pair has a pretty easy way of functioning. First of all, you should know that the “keys” we are talking about are two small files. They contain a long text which makes up the two keys. These two keys are used to encrypt and decrypt other messages. For instance the data sent back and forth to your SSH host.

The amazing part with these keys, are that they are the only keys which can decrypt whatever message was encrypted with the other key. This makes sure that the server is the only computer able to read your messages, and that your computer is the only which might read the server’s messages. A huge problem with sending passwords over the Internet is the fact that even though the password was encrypted, it might get picked up by someone else who’s sniffing on your wireless connection. That way it might be reused in the encrypted form to log back in on the server. SSH is a bit more sophisticated by encrypting the password differently every time, but essentially it follows a pattern which is easily decrypted.

With a key pair the connection is way more secure, and in short terms it works like this:

  1. Your computer connects to your host
  2. The server sends back a message, for instance “hi!”, encrypted with your public key
  3. Your computer decrypts the message with your private key, reads it as “hi!”, and encrypts it again
  4. The server recieves your encrypted message, decrypts it with the public key, and checks that the message is the same as when it was sent out. You are now logged in.

This way the server knows that you are who you say you are for two reasons: You are the only one who could decrypt the message with your key, and you are the only one who could encrypt the message again so that it could be decrypted by the server.

The reason we call them private and public keys are pretty obvious. The private key should be kept private so that nobody else may pretend they are you, but the public key may be spread around (thereby ‘public’) since it is useless for anything but encrypting messages for you.

Enough with the theory, get to the tutorial already!

To generate a key pair in Ubuntu, go to Applications > Accessories > Passwords and Encryption keys. A window like this should show up:

Screenshot-Passwords and Encryption KeysClick File > New…

Screenshot-Create New ...Choose Secure Shell Key and click Continue.

Screenshot-New Secure Shell KeyType in your e-mail address and click Create and Set Up.

Screenshot-Passphrase for New Secure Shell KeyAdd a passphrase for the key. This might be anything you’d like. It just makes the key a bit more secure.

Screenshot-Set Up Computer for SSH ConnectionNow, type in the address of your host and your username and click Set Up.

You will be prompted for your SSH password. Type this in and click OK.

Ubuntu will now take care of the rest for you, and you should be able to connect to the server without any hassle.

So, how do we mount it automatically?

After you have generated your keypair, you just go to System > Preferences > Startup Applications and add the following command:

sshfs /home/username/myssh

That is how easy it is. If you, like me, are using a server which formats the folder names with norwegian characters, you might want to add

-o modules=iconv,from_code=ISO-8859-1

to the end of the command, making the whole command look like:

sshfs /home/username/myssh -o modules=iconv,from_code=ISO-8859-1

Revision and build numbers for your NetBeans apps

After going through a couple of guides on the net, I figured out how to add build numbers and revision numbers to my NetBeans projects. The build number will be incremented for each build, and the revision number is gathered from your subversion repository. If you don’t use Subversion just skip that part and add the revision number manually.

In this tutorial I assume you are creating an application based on the NetBeans Desktop Application wizard. Otherwise, you may just follow along and use whatever fits into your project. All you need is a java project being built by Ant (as all NetBeans projects are).

Adding a build number

First of all, figure out where the properties file for your application is located. This should be in [package name].resources (or if you are browsing the files, you will find it under /src/[package name]/resources) and is named the same as your application with the suffix “.properties“.

This could for instance be myapp.resources/ or /src/myapp/resources/

Open it up and find the version property. It should look something like this:

Application.version = 1.0

Change this to the following

Application.version = 1.0.0.${Application.buildnumber}

Now, we are ready to add a build number to your build.xml file. This is found in the nbproject folder if you browse for files (not in the Projects browser).

Add the following lines below the

<import file="nbproject/build-impl.xml"/>

by replacing [Package Name] and [App Name] with your own values.

<target name="-post-jar" description="Sets the buildversion for the current build">
    <propertyfile file="${src.dir}/[Package Name]/[App Name].properties">
        <entry key="Application.buildnumber" value="1" type="int" operation="+"/>

This should now add your build number to your version number. If you want to have the version in the main title bar of your application just go back into the properties file and change the Application.title property to something like this:

Application.title = My Application Name ${Application.version}

Adding the Subversion revision number

Go back to your build.xml file and add the following below everything else:

<target name="-post-init" description="Sets the buildversion for the current build">
    <exec outputproperty="svna.version" executable="svnversion">
        <arg value="-c" />
                    <replaceregex pattern="^[0-9]*:?" replace="" flags="g"/>
                    <replaceregex pattern="M" replace="" flags="g"/>
    <propertyfile file="${src.dir}/[Package Name]/[App Name].properties">
        <entry key="Application.revision" value="${svna.version}" type="int" operation="="/>
    <echo>Revision found from SVN: ${svna.version}</echo>

Then, add the revision number to your version number by editing changing the Application.version property to something like this:

Application.version = 1.0.${Application.revision}.${Application.buildnumber}

This should be all it takes. Just leave a comment if it does not work out as expected.

Working with national characters

If you’d like to use national characters, you have to edit the propertyfile line like this:

<propertyfile file="${src.dir}/[Package Name]/[App Name].properties" jdkproperties="true">

Thanks to Poli for this tip!

Mounting a Windows share folder in Ubuntu

I have been connecting to my home folder at the Universitiy of Oslo for quite some time now, and since they use the Windows file-sharing protocol for this purpose, there has been room for quite som headaches.

After some googling I was able to figure out how to connect and mount a folder temporarily, but I had to re-mount it with my password every time I rebooted the computer. Finally, after realizing I actually tried this when I first figured the temporary method, I am now able to mount it permanently. I’ll show you how, in just a few, simple steps:

First of all, we need to install the samba file system. Type the following in to a terminal:

sudo apt-get install smbfs

Next, we need to get our username and password ready. Type the following into a terminal while replacing [your username] with your username:

gksudo gedit /home/[your username]/.smbcredentials

In the new file, add the following while using your own username and password:

username=[your username on the windows (smb) server]
password=[your password on the windows (smb) server]

Close the file, and type the following in to your terminal:

sudo mkdir /media/sambamount
sudo cp /etc/fstab /etc/fstab.backup
sudo gedit /etc/fstab

We have now made a backup of the current fstab (the file managing your mounted file systems) and opened it for editing. Add the following line to the file while substituting the brackets with your own values:

//[server name or DNS]/[folder on server to mount] /media/sambamount cifs credentials=/home/svenni/.smbcredentials,uid=[your local username],gid=users,iocharset=utf8 0 0

Save and close the file.

Everything should now be ready for the directory to be mounted when you boot the computer, but you could test it before you have to close the browser and take a two minute break away from your precious desktop.

Type the following into your terminal to test the mount:

sudo mount -a

Your shared windows directory should now appear on the desktop as a hard drive icon with the name «sambamount».