# Logging Experiences

## Using Git with Github on Windows

Posted in Git by Sina Iravanian on May 5, 2012

If you’re new to Git and don’t know how to install Git on Windows, read my earlier post: How to Setup Git for Windows

In an earlier post, I described the preliminary steps required to work with git on CodePlex. However using git with Github requires more initial steps.

Generating SSH Keys. Before proceeding to Git operations we need to create SSH public and private keys, and register the public key on the Github site. In order to generate the keys we can use PuTTY Key Generator, which is already bundled with TortoiseGit fortunately. This program is called “Puttygen” and can be found in start-menu under TortoiseGit:

After running Puttygen you need to press “Generate“, and make some crazy mouse movements in the spotted area to provide some random data for the program (wow, what a brilliant idea). When finished you will have the public key generated. It is recommended that you provide a passphrase so that you would have a more secure private key. After that save your public and private keys using the 2 save buttons near the bottom of the window. But these are not all that you need to save! The public key format that Github and some other applications require you to provide is not the one that this program has saved for you. The topmost field which is labeled “Public key for passing into OpenSSH authorized_keys file” is the one that Github needs. It should be in one line (i.e., with no line-breaks), therefore we would refer to it later as the one-line-public-key. Please save the contents of this field and the next “key fingerprint” field somewhere for future references.

Registering SSH Keys in Github. Browse to Github, and go to your Account Seetings, and select SSH Keys therein. Press the Add SSH key button on the right. Provide a name for the key (I chose TortoiseGit), and paste the one-line-public-key in the Key field. Press Add Key. You may be prompted for your Github account password next. When finished, Github adds this key to its list of keys and provides a fingerprint. Make sure this fingerprint matches the key fingerprint that Puttygen created for you.

Creating a Repository in Github. Browse to the Github page and press the “Create a New Repo” button at the top of the page.

In the new form that appears, enter desired values for your project’s name and description. Currently there’s an option to add a README file or an appropriate .gitignore file to the repository. While making use of these options are recommended, in this tutorial I intend to start from a completely empty repository; therefore I unchecked those options. When finished press the “Create repository” button. With these steps I created a project called “PdfRenamer“.

Setting up TortoiseGit for the new project. After creating the repository, Github introduces some helpful basic commands to start working with the repository. We don’t intend to use the command-line, however this page contains useful information such as user-name and email with which Github recognizes you, and the git repository address, as highlighted below:

We need to do the following steps next:

1. Right click somewhere in the Windows explorer window, and from the context-menu go to: TortoiseGit > Settings >> Git branch; and fill the user-name and email fields with the ones suggested by Github, and press OK.
2. Create a folder preferably with the same name as your project (in my case PdfRenamer), and browse into it with Windows explorer.
3. Right click somewhere in the folder and from the context menu select “Git Create repository here…“. A window pops-up. Make sure that “Make it Bare” is not checked; and press OK.
4. Right click somewhere in the folder and from the context menu go to: TortoiseGit > Settings >> Git branch >> Remote sub-branch. In the “Remote” field enter “origin“, in the URL field enter the git repository address which was highlighted above and is in the form of git@github.com:[username]/[projectname].git; and finally in front of “putty key” provide the address to the SSH private key which we saved earlier in this tutorial, and has the .ppk extension. When finished press the “Add New/Save” button. After that origin should be added to the list of Remotes.

Add files to the project structure. With git, adding a file to a project structure and having it reflected in the remote repository requires 3 operations: add, commit, and push. The first 2 operations are required for adding the file to the local repository, and the third one reflects the changes to the remote repository. This last operation can be postponed to a later time when you want to push a bundle of changes all at once.

To start, create a Readme.txt file in the root folder. Right click on the newly added file, from the context menu select: TortoiseGit > add; check the files to be added, and press OK. This was the first operation: add. In the new window press “commit …“, provide a meaningful commit message in the new window, and press OK when finished. This was the second operation: commit which reflects the changes to your local repository, the one in your hard-drive. You can push the changes in the next window if you want, however it’s not a good idea to push every local commit to the remote repository (that’s why we are using a DVCS after all).

Before continuing to the push command, let’s talk about some naming conventions in the Git world. With DVCSs such as git you can have different remote repositories which you may choose from to push your changes to. By convention, the default name for the remote repository is “origin“. In our case origin is the remote repository at the Github server, for which we manually added the link before. On the other hand, each project may have several branches. Conceptually a branch is another copy of the same project where other features are developed and tested. For example imagine that at a certain stage of development you may decide to add a new feature to your project. You may create a new branch called “test”, develop and test the feature there, and finally merge the changes with the code at the main branch. By convention, the main branch is called “master“.

When it comes to push, you need to know which branch of the code you want to push to which remote repository. In our simple case we want to push the master branch to the origin repository. For this purpose, right click somewhere on the Windows explorer that shows the project root folder, and select: TortoiseGit > Push…. Make sure the name of the branches for local and remote repositories and the name of the remote repository are selected correctly. More importantly make sure that the “Autoload Putty Key” check-box is also checked, and press OK. Next, the TortoiseGit will prompt you for the private-key passphrase. Note that this is not your Github account password, this is the passphrase that you chose when creating the private key with Puttygen. After finishing the push operation, check the sources in the project’s Github page to make sure the changes have been reflected there. Note that after the first push, the PuTTY authentication agent (Pageant) get’s run in the background, so that you won’t need to enter the passphrase anytime you want to push to Github.

Updating the local repository with the latest changes made by other team members to the remote repository. Well, there are two solutions. The one that I prefer is using git pull. You can easily find this command in the TortoiseGit’s context menu. The pull command, preserves the history of changes made by different people and makes a final merge afterwards. The other solution is git fetch and rebase. The fetch command only receives the latest changes from the remote repository but does not apply them. The rebase command first applies the remote changes to the repository, then applies your changes. Therefore it always seems that you have made the recent changes, while it may not be true. See this stackoverflow question for a better explanation.

Note: At any stage, if git complains about connecting through a null proxy, then you will have to remove proxy settings from the global .gitconfig file. For more information see tip 7 on my earlier post

You may also want to see my earlier post that describes using git with CodePlex on Windows.

## Using Git with CodePlex on Windows

Posted in Git by Sina Iravanian on May 4, 2012

If you’re new to Git and don’t know how to install Git on Windows, read my earlier post: How to Setup Git for Windows

On 21 March 2012, the CodePlex team announced their support for Git.

Creating a project with Git source control is very easy in CodePlex and is done with a few clicks at no time. Suppose the project name is CodePlexGitTest. In order to make any changes to the project structure you need to clone the project first. This way you will have your own copy of the repository on your hard disk. To do this the path to the git repository is needed. This can be obtained from the Source Code tab of the project’s CodePlex page, by pressing the Git link/button under “Source Control” section on the right pane, as seen below:

In order to clone the project, move to the folder that is going to host the project directory. Right click somewhere in the Windows explorer window and choose Git Clone. In the opened window set the “Url” field to the “Clone URL” value above, leave other options unchanged, and press OK. After prompting for your CodePlex user-name and password, it should now create the folder structure for your empty repository (Note: in case that git complains about connecting through a null proxy, then you will have to remove proxy settings from the global .gitconfig file. For more information see tip 7 on my earlier post).

Now that you have the currently empty project structure at your hard-drive, it’s time to add some files to it. Using git, adding a file to a project structure and having it reflected in the remote repository requires 3 operations: add, commit, and push. The first 2 operations are required for adding the file to the local repository, and the third one reflects the changes to the remote repository. This last operation can be postponed to a later time when you want to push a bundle of changes all at once.

To start, create a Readme.txt file in the root folder. Right click on the newly added file, from the context menu select: TortoiseGit > add; check the files to be added, and press OK. This was the first operation: add. In the new window press “commit …“, provide a meaningful commit message in the new window, and press OK when finished. This was the second operation: commit which reflects the changes to your local repository, the one in your hard-drive. You can push the changes in the next window if you want, however it’s not a good idea to push every local commit to the remote repository (that’s why we are using a DVCS after all).

Before continuing to the push command, let’s talk about some naming conventions in the git world. With DVCSs such as git you can have different remote repositories which you may choose from to push your changes to. By convention, the default name for the remote repository is “origin“. In our case origin is the remote repository at the CodePlex server. On the other hand, each project may have several branches. Conceptually a branch is another copy of the same project where other features are developed and tested. For example imagine that at a certain stage of development you may decide to add a new feature to your project. You may create a new branch called “test”, develop and test the feature there, and finally merge the changes with the code at the main branch. By convention, the main branch is called “master“.

When it comes to push, you need to know which branch of the code you want to push to which remote repository. In our simple case we want to push the master branch to the origin repository. For this purpose, right click somewhere on the Windows explorer that shows the project root folder, and select: TortoiseGit > Push…. Make sure the name of the branches for local and remote repositories and the name of the remote repository are selected correctly, and press OK. Enter CodePlex user-name and passwords which are prompted. Now check the sources in the project’s CodePlex site to make sure the changes have been reflected there.

How to update the local repository with the latest changes made by other team members to the remote repository? Well, there are two solutions. The one that I prefer is using git pull. You can easily find this command in the TortoiseGit’s context menu. The pull command, preserves the history of changes made by different people and makes a final merge afterwards. The other solution is git fetch and rebase. The fetch command only receives the latest changes from the remote repository but does not apply them. The rebase command first applies the remote changes to the repository, then applies your changes. Therefore it always seems that you have made the recent changes, while it may not be true. See this stackoverflow question for a better explanation.

## How to setup Git for Windows

Posted in Git, Programming by Sina Iravanian on May 1, 2012

These are some easy steps required to setup Git for Windows:

1. Download msysGit from: http://code.google.com/p/msysgit.
I prefer to use the portable version. At the time of this writing there’s no difference between 32 bit and 64 bit versions and the filename for the portable version is: PortableGit-1.7.10-preview20120409.7z. Currently it seems that the development of the project has been moved to Github, but the releases are still located in Google Code.

2. Extract the contents in a proper location. I made them into:
D:\PortableProgs\msysGit

3. If you intend to use the git command-line for every git operation simply run git-bash.bat in the root folder of msysGit. Yes, this is the old lovely Cygwin command-line.

4. If you don’t intend to use command-line (like me) install TortoiseGit. It is hosted at Google Code:
Note that it comes with different releases for 32-bit and 64-bit systems. At the time of this writing the latest version is 1.7.8.0. After installing TortoiseGit you may need to restart Windows, or the explorer process, or none.

5. Right click somewhere on a Windows Explorer window, and from the context menu select: TortoiseGit > Settings. There will be a message-box appearing begging for adjusting the path to msysGit. Click on “Set MSysGit path” button (If you have ever missed this window, or want to change the path to an already existing msysGit, simply go to: TortoiseGit > Settings >> the General branch).
In the field titled as “Git.exe path:” enter the path to the bin folder of the msysGit installation/copy.

6. You don’t have to, but it is highly recommended that before starting any git operations you set some global settings such as your name, email, and AutoCrlf. To this aim in the Windows explorer’s context menu go to: TortoiseGit > Settings >> the Git branch. Fill in the fields labeled Name and Email with proper values. Then make sure that AutoCrlf check-box is unchecked, so that you don’t touch every file in order to change their line-endings. Read more about this kind of problem here, and see here to know more what AutoCrlf and SafeCrlf options do for you.

7. [UPDATED on 3 May 2012] When performing some git operations, git may complain that it cannot connect through a null proxy. It may happen for some versions if in git settings the value for proxy is assigned to an empty string. If this is the case for you, simply remove proxy settings in the global .gitconfig file. To do this, right click somewhere in Windows explorer, go to: TortoiseGit > Settings >> The Git Branch >> Edit Global .gitconfig button. From there remove the line that assigns proxy, or the whole “[http]” section if it only contains proxy settings.

Tagged with: , ,

## Sample Variance vs. Population Variance: Bessel’s Correction

Posted in Math, Statistics by Sina Iravanian on August 21, 2011

Consider that you have a database of $N$ items. This database forms the whole population of the statistical operations that comes. If you calculate the mean, variance, and standard deviation of these items, then you are actually computing the population mean ($\mu$), the population variance ($\sigma^2$), and the population standard deviation ($\sigma$).

But if you draw some random samples out of the population, then you are actually sampling the population, and estimating the true statistics using those samples (maybe because it is expensive to do the calculations for the whole population). Statisticians usually use different names and notations for the values calculated from samples, e.g., the sample mean ($\bar{x}$).

The sample variance which is calculated using the same formula of calculating population variance is biased towards the sample items. More formally its expected value does not equal the population variance:

$\mathbb{E}[\sigma^2_{sample}] \neq \sigma^2$

To solve this problem, the sample variance is corrected by multiplying it by $\frac{n}{n-1}$ or simply using $n-1$ instead of $n$ when calculating the mean of squared deviations, i.e.:

$s^2 = \frac{1}{n-1} \, \sum_{i = 1}^{n} (x_i - \bar{x})^2$

This value is called the unbiased sample variance ($s^2$), for it is proved that [+]:

$\mathbb{E}[s^2] = \sigma^2$

To have different notations, the biased sample variance is shown by $s_n^2$.

Using $n - 1$ instead of $n$ in the formula for variance is called Bessel’s correction.

## Some Notes about Expected Values

Posted in Math, Statistics by Sina Iravanian on August 21, 2011

Expected value of a continuous random variable is given by:

$\mathbb{E}[X] = \int_{-\infty}^{+\infty} x\,f(x)\,dx$

where $f$ is the probability density function of the random variable $x$. Now the question is how do we calculate $\mathbb{E}[g(X)]$, e.g., $\mathbb{E}[X^2]$? Do we know $f(g(x))$ for $x \in X$? The answer is that we don’t need to. No matter what we do with $x \in X$, by applying $g$ to it, we have:

$f(g(x)) = f(x)$

therefore:

$\mathbb{E}[g(X)] = \int_{-\infty}^{+\infty} g(x)\,f(x)\,dx$.

Tagged with: , ,

## How I built my first Qt Application in Visual Studio 2010

Posted in C++, Qt, Tips and Tricks by Sina Iravanian on July 4, 2011

I downloaded the Qt SDK (offline installer version which was 1.7 GB) from:

At the time of this writing, the Qt libraries version was 4.7.3.

After installing both SDK, and the VS-Addin on my system, I started Visual Studio 2010. I tried to create a sample project by selecting: File > New > Project… > Qt4 Projects > Qt Application, and specified proper values for Name and Location. After going through the Qt wizard to the end, I encountered the following error message:

unable to find Qt Build!
To solve this problem specify Qt Build!

By going to the Qt setup directory, one sees that there are Qt SDKs available for different target platforms. For example I installed Qt in "D:\QtSDK\" and in that directory I see some folders which correspond to different target platforms such as Desktop, Madde, Symbian, and others. An appropriate platform directory should contain a bin folder inside. This is true about Madde, and Symbian, but the Desktop folder is a root for subdirectories related to different Qt versions and C++ compilers. Since I wanted to develop Qt applications with Microsoft Visual C++ for the Windows Desktop platform I went to the following directory which contains the required bin folder:
D:\QtSDK\Desktop\Qt\4.7.3\msvc2008

For the next step, I had to introduce this directory for the Qt VS-addin. From the main menu, I selected Qt > Qt Options > Qt Versions. I pressed the Add button, and entered "Win 4.7.3" in the  "Version name" field, and entered the above path in the "Path" field, and pressed OK. The path that I specified was added to the gird. Then I made sure that in the Default Qt/Win version, the version that I have just specified (i.e., Win 4.7.3) is selected. I pressed OK, and tried once more with the Qt New Project wizard. This time everything went OK, and I succeeded to create and build my first Qt Application in the VS 2010 environment.

Note: In fact the current Qt binaries are targeted for Visual Studio 2008. I was able to use the binaries (i.e., libs and dlls) because I had also Visual Studio 2008 and the corresponding C++ compiler installed on my machine. Otherwise, I presume that I would need to recompile the sources with the VS-2010 C++ compiler.

Tagged with: ,

## How to disable hibernate and free some disk space in Windows 7

Posted in Tips and Tricks by Sina Iravanian on May 26, 2011

Run a command prompt as administrator.

Run the following command:

powercfg.exe -h off


The disk space is freed immediately. To turn it back on run:

powercfg.exe -h on


Reference: +

## Including .eps images with pdflatex

Posted in LaTeX, Tips and Tricks by Sina Iravanian on May 21, 2011

PdfLaTeX does not support eps files by default. Add the following imports in the beginning:

\usepackage{graphicx} % already added
\usepackage{epstopdf}


After that the includegraphics commands with eps arguments should produce no problems.

Reference: +

Tagged with: ,

## Code Snippet: Mean, Variance, and Standard Deviation Methods

Posted in C#, Programming, Snippets by Sina Iravanian on May 15, 2011

The methods to calculate mean, variance, and standard deviation of a vector of values. These are put here for easy reference, so that I do not need to rewrite them again.

## A Helper Method for Performing K-Fold Cross Validation

Posted in C#, Programming, Snippets by Sina Iravanian on May 15, 2011

The following method is a utility method for creating the K divisions upon which one is going to perform the K-fold cross validation operation. The input of the method is the length of the training data, and the number K. The output says which indices of the training-data is to be put in each division.

Tagged with: ,