Sunday, March 30, 2014

How to stop Thread.Wait

Thead.Wait can't be stop easily, you need to use an alternative solution, by using
ManualResetEvent

ManualResetEvent mre=new ManualResetEvent(false);
//......
var signalled=mre.WaitOne(TimeSpan.FromSeconds(8));
if(signalled)
{
    //cancel the event
}
elsewhere (before the 8 seconds is up):
mre.Set(); //unfreezes paused Thread and causes signalled==true
and allow the unblocked thread to terminate gracefully. Thread.Abort is evil and should be avoided.
Once  mre.Set(), mre.WaitOne(TimeSpan.FromSeconds(8)); mre always return a signal, you need to "unset" the ManualResetEvent by
mre.Reset()

Source

Saturday, March 29, 2014

Visual SVN [Note to myself]

What to do after you restore the computer and Visual SVN dissapper?
Install Visual SVN
Right Click the VisualSVN Server (Local)
Choose the existing repository root at D:\C_Drive\Repositories, that's all.

ListView in C#

Why only one columns displayed, and not seeing columns and items in GUI?
Set View Property of Listview to Details

Adding Columns to ListView
GListView.Columns.Add("a");
GListView.Columns.Add("b");
GListView.Columns.Add("c");

Adding Items to ListView
var item1 = new ListViewItem(new[] { "id123", "Tom", "24" });
GListView.Items.Add(item1);

-or-

 var item1 = new ListViewItem();
item1.Text = "id123";
item1.SubItems.Add("Tom");
item1.SubItems.Add("24");
GListView.Items.Add(item1);

(items1 is the first columns, and it contains subitems (other columns)


Modifying
First Column (both below are ok)
GListView.Items[0].Text = "haha";

 GListView.Items[0].SubItems[0].Text= "haha1";

Second Column
 GListView.Items[0].SubItems[1].Text= "haha1";

Wednesday, March 19, 2014

Macrium Reflect Imaging

I use this Macrium Reflect to replace Acronis True Image for Windows 7 Drive Cloning.
Reason is that I encounter Archive Error during disk recovery when I am using Acronis True Image.

To compare with Macrium Reflect and Acronis True Image, Acronis True Image would run faster in terms of backup(1-2 minutes) compared to Macrium Reflect (11 minutes).
But for restore time they are similar.

Here are some tutorials on how to backup and install the image:

(Create Backup Image)
https://www.youtube.com/watch?v=KQA7NlLvxg8
Note:
1. You need to create a bootable DVD for recovery
2. Select the C drive (2nd one, no need for the first Active section) and click Image this disk


(Restore Backup Image)
https://www.youtube.com/watch?v=xuyD2Wm4y9Q
Note:
1. You need to press a key to enter the DVD options after inserting the bootable drive
2. The restoration progress is quite intuitive.

Restore from Acronis [For My Ref]

Restore (What I remember in mind)
1. Boot using the Acronis CD
2. Choose safe mode
3. Select the E:\Win7_64BitFull.tib
4. Choose C Drive (Not the MBR)
5. Choose the D Drive (it is actually the C Drive)
6. Select Primary (not active or backup)
7. That's all.

Audio converter and editor

Audio converter
FreeStudio (e.g., convert from m4a to wav)
(Be careful not to install other software from the installer, if you think it gonna be useless for you)

Audio Editor
Audacity

Running GUI using Eclipse

Use Windows Builder
http://download.eclipse.org/windowbuilder/WB/release/R201309271200/4.3/

Monday, March 10, 2014

Serialize Object to XML file in java

XStream xstream=new XStream();
EvaluationResult ae=new EvaluationResult();
FileOutputStream fileOut =new FileOutputStream("result.txt");
ObjectOutputStream out = xstream.createObjectOutputStream(fileOut);

out.writeObject(ae);
out.close();
fileOut.close();

FileInputStream inputStream = new FileInputStream("result.txt");
ObjectInputStream in = xstream.createObjectInputStream(inputStream);
EvaluationResult be=(EvaluationResult)in.readObject();


Tutorial:
http://xstream.codehaus.org/objectstream.html

Need:(download jar file from the url above)
xstream-1.4.7.jar
kxml2-2.3.0.jar
kxml2-min-2.3.0.jar

Thursday, March 6, 2014

\bigstrut undefined control sequence

Put

 \usepackage{multirow}
\usepackage{bigstrut}


in the preamble will do

Reading App

http://elitedaily.com/news/technology/this-insane-new-app-will-allow-you-to-read-novels-in-under-90-minutes/

pitch project and pitch deck

pitch project - go present proposal for project
pitch deck - the presentation slides

Wednesday, March 5, 2014

Disable opening of PDF in Chrome after download

Go to chrome://plugins
Disable the Chrome PDF Viewer

Include EPS graphics

\usepackage{epstopdf}

\includegraphics[width=1.5in]{image/bpel.eps}

Tuesday, March 4, 2014

Eclipse Error

ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2JDWP exit error AGENT_ERROR_NO_JNI_ENV(183): [../../../src/share/back/util.c:820]

http://www.fantasypublishings.com/morePhpHelp/java__ERROR_JDWP_Unable_to_get_JNI_12_environment__Stack_Overflow_page86817.php


Check eclipse 32 bit or 64 bit
http://stackoverflow.com/questions/5103366/how-to-find-out-if-an-installed-eclipse-is-32-or-64-bit-version

java logger

http://www.vogella.com/tutorials/Logging/article.html


  Regarding hierarchical of class: When a logger decides to produce a LogRecord, the logger not only passes the LogRecord to all its attached Handler(s), but it also forwards the LogRecord to its parent logger. The parent logger forwards the LogRecord to all its attached Handler(s) and its parent, without performing level or filter check. Eventually, the LogRecord reaches the root logger. By default, the root logger has a ConsoleHandler (that writes to System.err) with level of INFO.

http://www.ntu.edu.sg/home/ehchua/programming/java/JavaLogging.html

Not printing to output
http://stackoverflow.com/questions/920654/java-logger-only-to-file-no-screen-output

Monday, March 3, 2014

Java to C# converter

C# to Java converter can use CS2J
Command:
CS2jTranslator\bin\cs2j.exe -net-templates-dir=.\NetFramework\ -out-java-dir=..\Code_SPL_java -app-dir=..\Code_SPL -cs-dir=..\Code_SPL

..\Code_SPL is input directory (.net directory)
..\Code_SPL_java is output directory (generated java directory)

Java to C# converter (Microsoft's JLCA)


I have used both tools before, both provide reasonable conversion, but still need to change the code by your own.

Saturday, March 1, 2014

JMetals

1. How to change the initialize population (in algorithms)
2. How to encode in int[] (solution type)
3. How to make it evaluate fitness function (in problem, evaluate, set objective value for a solution(gene))
4. What is the use of evaluateConstraints (in problem, evaluate, set #constraintsViolated for a solution(gene))
5. How to sort the population (there is a sort function in algorithm.execute())
6. How to change the evaluation of crossover and mutation (is it working on clone)? (Yes)
7. What I should do about for quality indicator
8. The objective functions in the problem are to be minimized (the smaller the better).


Main(Problem, Algorithm, Operator, parameters)
Problem (the problem to be solve, #obj,#constraint,#var) ->SolutionType(Types that is used by the genes) -> CreateVariables(Create contents in the genes for initial population)

Algorithm (e.g., GA, execute()) -> create initial population (SolutionSet(Population) -> Solution (Gene Instance))


For IBEA
Spread, etc. are just quality indicators that it is used to judged the multiobjective optimization, it is not used in the process. The indicator used in the process is the hypervolume indicator.

Keyboard shortcuts Eclipse

Debug Mode in Eclipse for Source Not Found
"window->Preferences->Java->Debug" and disable the "suspend execution of uncaught exceptions"
http://stackoverflow.com/questions/10121214/has-myeclipse-implicit-breakpoint-in-debugging-mode-in-class-urlclasspath

If I'm reading you right, you want to specify some classes that you 
don't want to step into? I think what you want is...

Window -> Preferences -> Java -> Debug -> Step Filtering
http://www.eclipse.org/forums/index.php/t/101609/

Task Windows (Windows>Show View>Tasks, find Todo in Eclipse)
See the following on how to change configure Task Windows
http://www.mooreds.com/wordpress/archives/446

Add shortcut key to bookmarks
Windows>preference>Key>search for "add bookmark"
set alt+b (in windows)
http://stackoverflow.com/questions/3141493/bookmarks-in-eclipse-set-and-go-using-hotkeys-do-they-exist

Adding bookmark / Open bookmark windows
http://sandarenu.blogspot.sg/2008/02/using-bookmarks-in-eclipse.html

Finding classes/packages (ctrl+shift+h)
http://stackoverflow.com/questions/8944994/how-to-find-package-by-name-in-eclipse

Find usage (ctrl+shift+g)

Find type declaration (ctrl+g)

Eclipse Shortcut (alt+left arrow)

Generate Constructor (Alt+Shift+S, O)
http://www.eclipseonetips.com/2010/03/08/generate-class-constructors-in-eclipse-based-on-fields-or-superclass-constructors/

includes import
ctrl+shift+o

Open file in explorer
http://basti1302.github.io/startexplorer/

Formatting code
ctrl+shift+f

Formatting code upon save
http://www.eclipseonetips.com/2009/12/13/automatically-format-and-cleanup-code-every-time-you-save/

Automatic put semicolon at the end
http://www.eclipseonetips.com/2010/02/22/place-a-semicolon-at-the-end-of-a-java-statement-in-eclipse/

Duplicate Lines
Ctrl-Alt-Down: copies current line or selected lines to below
Ctrl-Alt-Up:: copies current line or selected lines to above
Ctrl-Shift-L: brings up a List of shortcut keys

Rename variable
ALT+SHIFT+R 


Time different
long beginTime = System.currentTimeMillis();

//Some operations. Let us asssume some database operations etc. which are time consuming.

//

long endTime = System.currentTimeMillis();

long difference = endTime - beginTime;


I prefer visual presentation:
╔══════════════╦═════════════════════╦═══════════════════╦══════════════════════╗
   Property          HashMap             TreeMap           LinkedHashMap    
╠══════════════╬═════════════════════╬═══════════════════╬══════════════════════╣
                no guarantee order  sorted according                        
   Order       will remain constant to the natural        insertion-order   
                    over time          ordering                             
╠══════════════╬═════════════════════╬═══════════════════╬══════════════════════╣
  Get/put                                                                   
   remove              O(1)              O(log(n))             O(1)         
 containsKey                                                                
╠══════════════╬═════════════════════╬═══════════════════╬══════════════════════╣
                                      NavigableMap                          
  Interfaces           Map                Map                  Map          
                                       SortedMap                            
╠══════════════╬═════════════════════╬═══════════════════╬══════════════════════╣
                                                                            
     Null            allowed           only values           allowed        
 values/keys                                                                
╠══════════════╬═════════════════════╩═══════════════════╩══════════════════════╣
                 Fail-fast behavior of an iterator cannot be guaranteed       
   Fail-fast   impossible to make any hard guarantees in the presence of      
   behavior              unsynchronized concurrent modification               
╠══════════════╬═════════════════════╦═══════════════════╦══════════════════════╣
                                                                            
Implementation      buckets           Red-Black Tree      double-linked     
                                                             buckets        
╠══════════════╬═════════════════════╩═══════════════════╩══════════════════════╣
      Is                                                                      
 synchronized               implementation is not synchronized                
╚══════════════╩════════════════════════════════════════════════════════════════╝

http://eclipse.dzone.com/news/effective-eclipse-shortcut-key