Logging Experiences

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: +

Advertisements

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: ,

Problem in finding local resources in Intellij IDEA

Posted in Java, Programming, Tips and Tricks by Sina Iravanian on May 10, 2011

Some classes use external data files which are located in the same directory as the one that the .java file is located, or somewhere nearby which can be easily addressed with a relative path. This happens a lot for me, esp. when I am running open source programs developed by someone else. As an example, imagine a class called SampleClass located in a directory in which there exists a text file with the name of “SomeFile.txt”. One way to have access to the file is through calling the class loader’s getResource function:

URL theURL = this.getClass().getResource("SomeFile.txt");
System.out.println(theURL.toString());

I tested this piece of code in NetBeans and it works fine. But not in Intellij IDEA! To solve this (annoying) problem, I needed to add the path of the source directory to classpath. For this purpose I did the following steps in Intellij IDEA 10.0.3 Community Edition:

  1. Right click on the module name and select "Open Module Settings"
  2. Select "Modules" from the leftmost pane
  3. Select "Dependencies" tab
  4. Press "Add…" button and select "1 Single-Entry Module Library…" from the popup menu
  5. Find and select the "src" folder of your sources.
  6. Under the "Scope" column, change the scope to "Runtime"
  7. Press Apply and OK

Dealing with ListView control, in the details mode

Posted in C#, Programming, Snippets, Tips and Tricks by Sina Iravanian on May 9, 2011

I needed a piece of code to manage list-view controllers. I needed to use ListView controls in the details mode, which automatically sort its contents when I click on the header, and also pastes the content in a tabular format when I press Ctrl+C or Ctrl+Insert on it. So I created the following classes. It is necessary to note that the code that carries out the sorting stuff when the header is clicked is taken from the following MSDN article:
http://msdn.microsoft.com/en-us/library/ms996467.aspx

So these are the contributions of these pieces of code: 1) Sorting ListView items automatically when the header is clicked, 2) Pasting the contents of the ListView control to the clipboard in a tabular format, and 3) Providing an easy to use API to append data to a ListView control.

The following gist contains the code to accomplish this. It consists of 3 files. The ListViewColumnSorter.cs file is responsible for the sorting stuff. The ListViewUtils.cs file provides the utility methods for a ListView control. The main methods that perform the job are located in the ListViewUtils class. The two needed methods are InitListView and AppendToListView. And finally the Usage.cs file provides a small sample demo of the utility methods.