Creating SSH keys in Eclipse on Windows 10

If you want to use SSH keys in Eclipse, such as if you’re going to connect an Eclipse Git repository with GitHub or BitBucket, you may want to use Eclipse to create and manage the keys for you.  It’s pretty easy to do.

Where to store your keys

I recommend storing your keys in a folder named .ssh underneath your home folder.  Most programs that use SSH keys expect that, including Eclipse, so unless you’ve got a really good reason to do it differently, go with the standard.

What type of key to use

You’ve got two choices for type of key to use with Eclipse: RSA and DSA.  According to this page on StackExchange, you want to use RSA.

The next thing you need to decide is how long your key is.  Ideally, we’d use a key length of 2048 or 4096; unfortunately, Eclipse only generates a 1024 bit key.  There is a bug report filed against Eclipse to change this, but it’s been open since 2013, so I’m guessing it’s not going to be changed soon.  So, I guess I lied — you don’t need to decide how long your key is, because it’s going to be 1024 bits!

Generating the key

Open Eclipse, then from the menu, select Window, and from the Window menu, select Preferences.  You’ll get a window that looks like this:

On the left side, expand General (click on the > beside General), then expand Network Connections, and finally select SSH2:

You’ll see here that it defaults to storing the keys in the .ssh folder of your home folder — that’s good, that’s what we want.

Select the Key Management tab:

We want to create an RSA Key, so click the “Generate RSA Key…” button.  You’ll get something like this:

So, what’s happened?  Eclipse has generated a “key pair”, a pair of matching keys that you can use to authenticate who you are.  The idea is that you keep one of the keys secret (the “private” key), and you don’t ever let anyone else ever see that.  The other key (the “public” key) you can let anybody see; in fact, they’re going to need to know your public key so that you can authenticate with them.  The public key is what’s shown in the “You can paste this public key into the remote authorized_keys file:” box.

The private key is not shown.  You will want to save it to your .ssh folder.  Before saving it, you need to decide if you want to encrypt the key.  If you don’t, anyone who gets access to your .ssh folder can get your private key and pretend they’re you.  But, if you do encrypt it, every time you go to use the key, you’re going to have to type in a password. I generally encrypt my private key.

To specify a password to encrypt your private key, enter it into the “Passphrase” field.  Type it again into the “Confirm passphrase” field. Be sure to choose a good password! If you don’t type anything into those two fields, your private key will be stored unencrypted.  Eclipse will warn you when you try to save your private key:

In this example, I have typed in a passphrase.  When I press the “Save Private Key…” button, I get this dialog box:

You can ignore the “known_hosts” file in there; that’s from something else I’ve done.  You probably don’t have it. Anyways, it defaults to saving your private key in a file called “id_rsa”; unless you’ve got a really good reason to change it, just go with the default.

Actually, when I save it, it creates two files: one called “id_rsa” that contains my encrypted private key, and another called “id_rsa.pub” that contains my public key that I can share with anybody.

Done!  Now I can share my public key with GitHub or BitBucket, and I can easily authenticate with those systems with Eclipse.  Click the “Apply and Close” button, and you’re good to go!

Installing Google Fonts on Windows 10

A quick how-to guide on how to install Google Fonts into Windows 10.

Google Fonts is a collection of fonts intended for use on the Web.  From the Google Fonts About page:

Google Fonts makes it quick and easy for everyone to use web fonts, including professional designers and developers. We believe that everyone should be able to bring quality typography to their web pages and applications.

Our goal is to create a directory of web fonts for the world to use. Our API service makes it easy to add Google Fonts to a website in seconds. The service runs on Google’s servers which are fast, reliable and tested. Google provides this service free of charge.

I was trying to make a graphic that used Ultra, one of the fonts, and I wanted to use Inkspace to make it.  But, Google Fonts are web fonts, and I wanted to have Ultra as a font installed on my computer so I could use it.  It turns out that it’s not that hard to do.  I’ll show the steps for installing Open Sans.

First, go to the Google Fonts homepage.  In the upper left corner is a search box:

The Google Fonts search box
The Google Fonts search box

Type in the name of the font you’re looking for, in this case, Open Sans.  The Google Fonts website will filter down all of the fonts it knows about, and only show the ones matching what you’ve typed in.  For me, it showed me two fonts: Open Sans and Open Sans condensed.

GoogleFonts2

With each of the fonts displayed, there’s a blue “Add to Collection” button.  Click that button, and that font will be added to a collection of fonts, displayed at the bottom of the page.

GoogleFonts3

Next, we’re going to want to download a Zip file that contains a TTF file (short for True Type font, one of the types of fonts that Windows understands) of the font we’ve selected.  If we add more than one font to our collection, all the fonts will be in the Zip file.  Anyways, there’s a download button on the page, but it’s not real obvious.  It’s in the upper right corner of the page, and looks like a down arrow:

GoogleFonts4

Click that, and you’ll get a dialog box telling you that you don’t need to download the font.  If you’re just using it for the web, that’s right, but we want to install the font into Windows 10.

GoogleFonts5

We want to choose the first option, “Download the font families in your Collection as a .zip file”.  Click on the .zip file link, and your browser will download a zip file to your computer — in my case, it was called Open_Sans.zip.  Go to wherever that file was downloaded (likely your Downloads folder), right-click on the file, and select “Extract All…”.  You’ll be asked where to extract the files to, and it will default to the current directory.  Click the Extract button, and a new folder will be created containing a LICENSE.txt file and one or more TTF files.

The next thing to do is to install the TTF file (or files) into Windows 10.  Open up the Control Panel (type Control Panel into the Windows search box if you’re not sure how to open it), and you’ll get this window:

GoogleFonts6

Click on the Appearance and Personalization heading to get:

GoogleFonts7

Under Fonts, click on “Preview, delete, or show and hide fonts”.  You’ll be taken to a window showing all the fonts installed on your system:

GoogleFonts8

Finally, from that folder of downloaded fonts, drag the fonts you want to install into this new window, and the fonts should now be installed!

Installing “PortableGit from msysgit” on Windows 7

I wanted to install Aptana Studio 3 onto my Windows 7 machine at work, and according to Aptana’s Getting Started Guide, I needed to have Git installed.  According to the Aptana website, the Aptana Studio installer should install “PortableGit from msysgit” for me if I want, but that didn’t seem to happen.  So, I did a little searching for some instructions on installing PortableGit, but when I couldn’t really find anything helpful, I came up with a set of instructions on my own.

PortableGit is an implementation of the Git version control system for Windows machines.  It uses the very handy MSYS system to provide a Bourne Shell (bash) command line interpreter system. There’s at least a couple different versions of Git for Windows available from these msysgit guys; I like the PortableGit version because it doesn’t mess with my registry, it doesn’t install anything in my Start menu, and if I want to delete it, I only need to delete the files, not run an uninstall program.  It’s very self-contained, and I don’t have to worry about it mucking about with my computer. This isn’t the most user-friendly version, but if you’re an old command-line hack like myself, it’s fine.  And, for what I’m going to be using it for (letting Aptana Studio use it!), it’s all right.

I grabbed PortableGit from http://code.google.com/p/msysgit/downloads/list (see image below — click the image to see a readable full-size screenshot!).

Listing of all of the Git for Windows files available

I selected the file called PortableGit-1.7.11-preview20120710.7z.  This was the latest version at the time I downloaded it; of course, if you’re reading this anytime after the day I post it, there may be a newer version!  Clicking on that link takes you to this page (again, click the image to see the full-size screenshot):

I clicked on the little arrow on the left side of the filename, and it downloaded the file for me.

Although this is an executable installer, the file can’t be executed as-is – the file extension needs to be renamed from .7z to .exe.  Once I did that, I was able to run it.

Note that, depending on your Windows setup, you may need to run the installer as an administrator.  For me, I had to find the file in Windows Explorer (I saved it to my Downloads library), then right-click on the file, and select “Run as administrator”.  When I did that, I was greeted with the following dialog box:

That location was exactly where I wanted to install it, so I left it at that.  Click OK, and the program is installed.  If you get an “access denied” error, it means that you need administrator permission AND you didn’t run it as an administrator, so try again.

Once you’ve got the program installed, if you want to learn more about the “Portable” aspect of PortableGit, navigate to the C:\Program Files (x86)\Git folder.  There’s a README.portable file that explains everything.

Once we’ve got PortableGit installed, we’re going to want to be able to run it.  The program we’ll be running is called git-bash.bat, and that will give you a Bash shell that you can run Git commands in.  To be able to run that program, we’ll need to add Git to my list of executable folders (my “path”) so that I can run it from the command prompt.  To do so, do the following.  Open the Start menu, then right-click on Computer:

From the pop-up menu that comes up, select Properties.

You’ll get a window that is titled “View basic information about your computer”.  On the left-hand side of the window, there’s a menu titled “Control Panel Home”; select “Advanced system settings”.

You’ll get a System Properties window.  Select the Advanced tab, and then click the Environment Variables… button:

You will get a list of all the environment variables in the system, similar to this:

Right now, I have no Path user variable, but I do have a Path system variable (if I had been smart, I would have scrolled down to show it in my screenshot!).  The Path variable tells Windows which folders contain programs to execute from the command prompt or the “Search programs and files” box on the Start menu.

You now have a choice: if you want to add Git to the path for all users, you’ll want to add Git’s folder in the Path environment variable in the “System variables” section (and you’ll need to be an Administrator to do it); if you only want to add it for yourself, you’ll need to add it to (or create) the Path environment variable in the “User variables” section.  I’ll just add it for myself.  If you have a Path variable, select the Path variable and then click the Edit… button; if you don’t have one (which I didn’t), just click the New… button.

If you’re adding to an existing variable, you’ll get a window that is similar to this:

To the end of the existing value, type a semi-colon (“;”) followed by the complete path to the folder that you installed git in (in my case, C:\Program Files (x86)\Git).  The semi-colon is used to separate all the folders on your path.

If you’re creating a new variable, you’ll get an almost identical window that looks like this:

For the Variable name, type in Path.  For the Variable value, type in the complete path to the folder that you installed git in (in my case, C:\Program Files (x86)\Git):

Press OK, and you should be good!  You can now finish up by pressing OK on the Environment Variables window, OK on the System Properties window, and then close the “View basic information about your computer” window.

Next, let’s make sure it’s installed.  We’ll want to run the git-bash.bat file from the command line.  Click on the Start menu, then in the “Search programs and files” box in the bottom left corner, type git-bash and press the Enter key:

Your Start menu will go blank, and there will be a “Searching” message displayed, but soon you’ll see the git-bash command prompt:

If you see that, you’ve successfully installed PortableGit!

If you want to learn HOW to use git, I recommend the Git site: http://git-scm.com/.  I’d especially read the Pro Git book on that site.

Formatting percentages in Microsoft Word mail merges

When I mark student assignments, I usually put the students’ marks and comments in a spreadsheet, then I do a mail merge to send out the marks to the students.  I like doing it this way because then I’ve got a copy of all the comments and marks that I’ve given the students, and I can do some simple calculations to see how effective my teaching has been in different areas of the course material.  I’m also more able to be sure that I’m giving similar comments and marks for similar work.

The only problem I have, though, is that when I do a mail merge, the formatting of my calculated numbers is thrown off, and the worst is the percentages.  I know that there’s a way to format them correctly, but I can never remember how to do it, and the notes I’ve kept don’t seem to always work, and I’ve never quite got my head wrapped around the way it works. Until now!!!

I ran across this web page that really helped me to understand what’s going on.  While it’s still fresh in my mind, I wanted to write a blog post explaining it so that the next time I need to do this, I’ve got something to reference, and hopefully it will be helpful for other people, too!

Note that I’m using Microsoft Office 2010, although that webpage is for Office 2003, so I’m sure it works with other versions.

Update, Feb. 25, 2014: In the comments below, “Anna” mentioned that she’s verified that this also works in Office 2013.

Let’s start off with a simple spreadsheet.  I’ll assume I’ve got an assignment with 3 questions on it, each worth 10 marks.  I’ll record the marks for the students in that spreadsheet, then have a column that calculates the total marks, and another that calculates the percentage.  The spreadsheet looks like this:

Then, I set up a mail merge document in Word, add in the fields from the spreadsheet, and get a document that looks like this:

So that looks OK, but when I look at it in preview mode, I’ve lost all of the formatting on my percentage field:

The problem is that when I do a mail merge, the number is transferred from Excel to Word, but the formatting is not. The solution is to tell Word how I want to format this percentage field. To do that, I need to mess around with “field codes”. A better explanation is probably given here, but here’s a step-by-step description of how I do this.

First, we need to see the field codes. Press ALT-F9 to display the field codes (pressing ALT-F9 again will undo this). You’ll see:

We need to specify that we want to format this field differently. Place the insertion point after the “MERGEFIELD Pct”, and type in:

\# #0.0

The “\#” tells Word that it should format this field as a number, and the “#0.0” tells it which specific format it should use for the number. I find it a little confusing because the octothorpe character is being used for multiple things: both to say that this field should be formatted as a number, and to say how that number is to be formatted. Anyways, “#0.0” tells Word to use up to two numbers before the decimal point and to include a single zero if the integer part of the number is zero, and to use exactly one number after the decimal point, even if that number is 0. As I understand it, “#” means display the digit if you need it or a space if you don’t (when you’ve got a leading or trailing zero), and “0” means always display the digit.  Anyways, our field now looks like:

Let’s look at how this gets formatted. Press ALT-F9, then turn off and turn back on the preview results. Now we see:

Well, that’s close, but it’s not quite right, obviously. The problem is that the number is 0.8, not 80 (a decimal number, not a percentage). To get it to display it as a percentage, we need to tell Word to multiply that value by 100. To do this, first we need to highlight the merge field. Highlight “MERGEFIELD” and the name of the field, as shown:

Once you’ve done that, press CTRL-F9 to embed this mergefield into another field. Now we’ve got:

Notice the extra set of curly braces around the mergefield. It is extremely important that the curly braces be added by pressing CTRL-F9; if you type in the braces manually, it’s not going to work.

Once you’ve got this merge field embedded in another field, we can tell Word to do a calculation with it. Add an equals sign in front of the merge field, and “*100” after it; this tells it to multiply the value of that field by 100, making it a percentage rather than a decimal. It should look like:

Now, press ALT-F9 to turn off the display of the field codes, turn the merge preview results off then back on, and then we should see what we want!

I hope this helps!!!