Sunday, December 8, 2013

Daikon on Windows 7

Make sure you set the Classpath (not path) environment variable to the following:
.;C:\Program Files\Java\jdk1.7.0_17\lib\*;D:\C Drive\Desktop\Daikon\daikon\daikon.jar;
or
.;C:\Program Files\Java\jdk1.7.0_17\lib\*;D:\C Drive\Desktop\Daikon\daikon\daikon.jar

Command to compile
cd /d "D:\C Drive\Desktop\Daikon\daikon\examples\java-examples\StackAr"
javac -g -source 5 -target 5 DataStructures/*.java

Method A. Combine the Intrumentor and invariant detector (sometimes it does not work)
java daikon.Chicory --daikon DataStructures.StackArTester

Method B. Split the Intrumentor and invariant detector
java daikon.Chicory  DataStructures.StackArTester
java daikon.Daikon StackArTester.dtrace.gz

Friday, November 8, 2013

Changing All Fonts in Powerpoint

Want to replace all font for powerpoint slides?
This feature is support directly in powerpoint 2007, 2010.

Under Home Tab

Choose Replace Font under Replace (Editing Section)

And choose the font you want to replace!



That's it!

Saturday, October 19, 2013

Highlighting the different between Latex Documents in Windows 7 using Latexdiff

Wondering is there a way how to make a diff for latex files or documents?
The answer is a definite Yes! You need latexdiff which comes with Miktex

Following is a step by step guide for installing it in Windows 7:
Prerequisite
You need to install:
  1. Miktex (http://miktex.org/2.9/setup)
  2. Perl (can use Strawberry Perl: http://strawberryperl.com/releases.html)

Step By Step Guide
Assume Miktex and Perl Interpreter are installed, and Miktex is installed in "C:\Program Files (x86)\MiKTeX 2.9\" (Other directory is fine, just adapt accordingly)

  1. Go to  "C:\Program Files (x86)\MiKTeX 2.9\scripts\latexdiff\"
  2. Create a a new folder "perl" in "C:\Program Files (x86)\MiKTeX 2.9\scripts\latexdiff\"
  3. Copy all files in "C:\Program Files (x86)\MiKTeX 2.9\scripts\latexdiff\" to new folder "C:\Program Files (x86)\MiKTeX 2.9\scripts\latexdiff\perl"
  4. Rename all files (without extension) in "C:\Program Files (x86)\MiKTeX 2.9\scripts\latexdiff\perl", with an extension .ple.g., latexdiff to latexdiff.pl
  5. Add "C:\Program Files (x86)\MiKTeX 2.9\scripts\latexdiff\perl" to the PATH environment (if you are not sure how to do so, see here)
  6. Open Command Prompt, and type in
    latexdiff.pl --flatten PreviousFile CurrentFile> diffe.g., latexdiff.pl --flatten "C:\old.tex" "C:\new.tex" > "C:\Diff.tex"

Sample
Below is  a sample for Diff.tex, where you can see what's old (cross out, red color) and new (underline, blue color) easily, pretty cool right :)







Google Chrome - Adobe Acrobat has Crashed

There is a pretty straightforward solution for it:

Go to Chrome plugins page by typing this in your browser: chrome://plugins/
Look for "Chrome PDF Viewer" and Enable it.

Monday, September 9, 2013

ISynchronizeInvoke implementation example

Put the following code for classes you want to implement ISynchronizeInvoke should do the job
        private readonly object _sync= new object();

        public IAsyncResult BeginInvoke(Delegate method, object[] args)
        {
            var result = new SimpleAsyncResult();

            ThreadPool.QueueUserWorkItem(
                delegate
            {

                result.AsyncWaitHandle = new ManualResetEvent(false);
                try
                {
                    result.AsyncState = Invoke(method, args);
                }
                catch (Exception exception)
                {
                    Debug.WriteLine(exception.Message);
                    Debug.WriteLine(exception.StackTrace);
                    result.Exception = exception;
                }
                result.IsCompleted = true;
            });


            return result;
        }


        public object EndInvoke(IAsyncResult result)
        {
            if (!result.IsCompleted)
            {
                result.AsyncWaitHandle.WaitOne();
            }


            return result.AsyncState;
        }


        public object Invoke(Delegate method, object[] args)
        {
            lock (_sync)
            {
                return method.DynamicInvoke(args);
            }
        }


        public bool InvokeRequired
        {
            get { return true; }
        }
        public class SimpleAsyncResult : IAsyncResult
        {
            private object _state;


            public bool IsCompleted { get; set; }


            public WaitHandle AsyncWaitHandle { get; internal set; }


            public object AsyncState
            {
                get
                {
                    if (Exception != null)
                    {
                        throw Exception;
                    }
                    return _state;
                }
                internal set { _state = value; }
            }

            public bool CompletedSynchronously
            {
                get { return IsCompleted; }
            }


            internal Exception Exception { get; set; }

        }
        
  

Want to read more?

How to put code snippet into blogger like blogspot


// Comment
public class Testing {
public Testing() {
}
 
public void Method() {
/* Another Comment
on multiple lines */
int x = 9;
}
}
Reference here: http://www.craftyfella.com/2010/01/syntax-highlighting-with-blogger-engine.html

[Self Reference] Bug Lists

20 Sep 2013
  1. if…else.. do not consider last redundant assignment
  2. when dividing, denumerator can be zero
8 Sep 2013
  1. Do not initialize class values before using it - Do not initialize the RuntimeAdapter for InitialState (leave empty), when using RuntimeAdapter
  2. == and !=, if(root.Count==1) throw (only allow once) -> Suppose to be !=1
-----
  1. wrong sequence - Clear the ConcreteServices at the wrong place just after populating it, it should be just before populating it
  2. missed item - case.execute() is not implemented
  3. missed item - the switch does exert the event to partialModelState
  4. redundant call - put two calls in start and internal start for simulate()
  5. wrong name - when copy paste forget to change all the names
  6. Not setting global one - declare a lobal Simulator sm, and didn't set to global one
  7. terminate event not sent -  skip is never called as it won't evoluate to that event, correct way to send terminate event is via the Bprocess execute()
  8. Unexpected - parallel.run(…), in … throw exception (a duplicate var can solve the problem)
  9. parallel.invoke bug can't throw outside: http://stackoverflow.com/q/18764007/1497720
----


Previous two days
  1. not initialize v with maximum when doing v=min(v, value)
  2. not initialize v with zero and maximum separately, when v has to do with min and plus
  3. in switch, change the case activity value
  4. does not understand that geteventid, is a state with previous edges
  5. using a the terminal states without initializing it with value


  1. Index out of bound - action0Col[1] == "if", but action0Col may not have index 1 (e.g., for atomic action)
  2. copy paste - result.Add(new ActionPair(actionPair.Value[0], actionPair.Value[1], action0Col[2] == "c"));
  3. not assigning value to instance - not assigning the value to Available of Nonfunctional Attribute, but assign to a variable totAvailability
  4. split value problem(knowledge problem) - [if:0:c] split becomes {"[if","0","c]"}
  5. copy paste -  avgResponseTime += nf.ResponseTime;  should be  avgResponseTime += nf.avgResponseTime;
  6. Concept problem - in AggregateActions firstResponseTime and firstAvgResponseTime treat the same
  7. "a:name:<empty>", string split, then only have two columns, access 2 index out of bound



  1. Value is null, lock{..}{}..this .. is empty!
  2. Queue and trace not initialize when accessed

Sunday, August 11, 2013

Singnet and NUS Proxy Server

Singnet:
proxy.singnet.com.sg
8080

NUS:
pali.nus.edu.sg
3128

Thursday, March 28, 2013

How to prevent a page open in IFRAME

Set
X-FRAME-OPTIONS: SAMEORIGIN
 in the header will do.

Thursday, March 21, 2013

Good links for PHP


Here's some good links accumulated from the answers below/Found myself for understanding the OO architecture/Unique Features in PHP, of course, it is meant for people from other areas like java and .net to have an overview of PHP features.

OO

Using namespace
http://php.net/manual/en/language.namespaces.basics.php

Fallback for global namespace
http://www.php.net/manual/en/language.namespaces.fallback.php

Class(overidden class, Const, static class) using ::
http://php.net/manual/en/language.oop5.paamayim-nekudotayim.php

Array

http://php.net/manual/en/language.types.array.php

An array can be created using the array() language construct. It takes any number of comma-separated key => value pairs as arguments.
array(
    key  => value,
    key2 => value2,
    key3 => value3,
    ...
)


the key can either be an integer or a string. The value can be of any type.
Additionally the following key casts will occur:
  • Strings containing valid integers will be cast to the integer type. E.g. the key "8" will actually be stored under 8. On the other hand "08" will not be cast, as it isn't a valid decimal integer.
  • Floats are also cast to integers, which means that the fractional part will be truncated. E.g. the key 8.7 will actually be stored under 8.
  • Bools are cast to integers, too, i.e. the key true will actually be stored under 1 and the key false under 0.
  • Null will be cast to the empty string, i.e. the key null will actually be stored under "".
  • Arrays and objectcan not be used as keys. Doing so will result in a warning: Illegal offset type.
If multiple elements in the array declaration use the same key, only the last one will be used as all others are overwritten.
Example #2 Type Casting and Overwriting example
<?php
$array 
= array(
    
1    => "a",
    
"1"  => "b",
    
1.5  => "c",
    
true => "d",
);
var_dump($array);?>
The above example will output:
array(1) {
  [1]=>
  string(1) "d"
}



The key is optional. If it is not specified, PHP will use the increment of the largest previously used integer key.
Example #4 Indexed arrays without key
<?php
$array 
= array("foo""bar""hallo""world");var_dump($array);?>
The above example will output:
array(4) {
  [0]=>
  string(3) "foo"
  [1]=>
  string(3) "bar"
  [2]=>
  string(5) "hallo"
  [3]=>
  string(5) "world"
}


It is possible to specify the key only for some elements and leave it out for others:
Example #5 Keys not on all elements
<?php
$array 
= array(
         
"a",
         
"b",
    
=> "c",
         
"d",
);
var_dump($array);?>
The above example will output:
array(4) {
  [0]=>
  string(1) "a"
  [1]=>
  string(1) "b"
  [6]=>
  string(1) "c"
  [7]=>
  string(1) "d"
}

Multidimentional array

Accessing array elements with square bracket syntax

Array elements can be accessed using the array[key] syntax.
Example #6 Accessing array elements
<?php
$array 
= array(
    
"foo" => "bar",
    
42    => 24,
    
"multi" => array(
         
"dimensional" => array(
             
"array" => "foo"
         
)
    )
);
var_dump($array["foo"]);var_dump($array[42]);var_dump($array["multi"]["dimensional"]["array"]);?>
The above example will output:
string(3) "bar"
int(24)
string(3) "foo"


Creating/modifying with square bracket syntax

An existing array can be modified by explicitly setting values in it.
This is done by assigning values to the array, specifying the key in brackets. The key can also be omitted, resulting in an empty pair of brackets ([]).
$arr[key] = value;
$arr[] = value;
// key may be an integer or string
// value may be any value of any type
If $arr doesn't exist yet, it will be created, so this is also an alternative way to create an array. This practice is however discouraged because if $arr already contains some value (e.g. string from request variable) then this value will stay in the place and [] may actually stand for string access operator. It is always better to initialize variable by a direct assignment.
To change a certain value, assign a new value to that element using its key. To remove a key/value pair, call the unset() function on it.
<?php
$arr 
= array(=> 112 => 2);$arr[] = 56;    // This is the same as $arr[13] = 56;
                // at this point of the script
$arr["x"] = 42// This adds a new element to
                // the array with key "x"
                
unset($arr[5]); // This removes the element from the arrayunset($arr);    // This deletes the whole array?>

Multidimentional array

Accessing array elements with square bracket syntax

Array elements can be accessed using the array[key] syntax.
Example #6 Accessing array elements
<?php
$array 
= array(
    
"foo" => "bar",
    
42    => 24,
    
"multi" => array(
         
"dimensional" => array(
             
"array" => "foo"
         
)
    )
);
var_dump($array["foo"]);var_dump($array[42]);var_dump($array["multi"]["dimensional"]["array"]);?>
The above example will output:
string(3) "bar"
int(24)
string(3) "foo"
Note:
Both square brackets and curly braces can be used interchangeably for accessing array elements (e.g. $array[42] and $array{42} will both do the same thing in the example above).

Useful functions

There are quite a few useful functions for working with arrays. See the array functions section.
Note:
The unset() function allows removing keys from an array. Be aware that the array will not be reindexed. If a true "remove and shift" behavior is desired, the array can be reindexed using the array_values() function.
<?php
$a 
= array(=> 'one'=> 'two'=> 'three');
unset(
$a[2]);/* will produce an array that would have been defined as
   $a = array(1 => 'one', 3 => 'three');
   and NOT
   $a = array(1 => 'one', 2 =>'three');
*/
$b array_values($a);// Now $b is array(0 => 'one', 1 =>'three')?>
The foreach control structure exists specifically for arrays. It provides an easy way to traverse an array.


Regarding modification of the array:
http://stackoverflow.com/questions/5179606/php-replace-array-value

Note
Array assignment always involves value copying. Use the reference operator to copy an array by reference.



Include and require

http://www.php.net/manual/en/function.include.php
require is identical to include except upon failure it will also produce a fatal E_COMPILE_ERROR level error. In other words, it will halt the script whereas includeonly emits a warning (E_WARNING) which allows the script to continue.


foreach

The foreach construct provides an easy way to iterate over arrays. foreach works only on arrays and objects, 
foreach (array_expression as $value)
    statement
foreach (array_expression as $key => $value)
    statement
<?php
$arr 
= array(1234);
foreach (
$arr as &$value) {
    
$value $value 2;
}
// $arr is now array(2, 4, 6, 8)unset($value); // break the reference with the last element?>
Reference of a $value and the last array element remain even after the foreach loop. It is recommended to destroy it by unset().

You may have noticed that the following are functionally identical:
<?php
$arr 
= array("one""two""three");reset($arr);
while (list(, 
$value) = each($arr)) {
    echo 
"Value: $value<br />\n";
}

foreach (
$arr as $value) {
    echo 
"Value: $value<br />\n";
}
?>

Wednesday, March 6, 2013

Issue regarding "You are NOT logged in to SoC-VPN"

This is mainly for National University of Singapore, School of Computing Students and Staffs.

You are NOT logged in to SoC-VPN

https://noc.comp.nus.edu.sg/netlogon?1.0.2


How to solve it:
Right click the SoC-VPN shortcut, 
Choose compatibility tab,
and check Run this program as an administrator

Monday, February 11, 2013

How to get google page rank?

Answer: You can use the php here -
http://code.google.com/p/seostats/

Source:
http://stackoverflow.com/questions/1344917/getting-google-pagerank-via-an-api-php

How to put counter in NUS SOC

To put counter on index.htm
1. pagecount -h www.comp.nus.edu.sg index.htm
2. Put

<!--#include virtual="/cgi-bin/pagecount"-->
on the webpage

How to not display on the counter
1. pagecount -h www.comp.nus.edu.sg -m /dev/null index.htm
2. Put 

<!--#include virtual="/cgi-bin/pagecount"-->

3. Use http://www.comp.nus.edu.sg/cgi-bin/pagecount?/~tianhuat/index.htm to view the webpage

What is the fastest way to delete folders and files on windows

Answer:

Fastest: 
The best I've found is a two line batch file with a first pass to delete files and outputs to nul to avoid the overhead of writing to screen for every singe file. A second pass then cleans up the remaining directory structure:
del /f/s/q foldername > nul
rmdir /s/q foldername
2nd: use rmdir /s/q foldername from the command line. del /f/s/q foldername is good too, but it leaves behind the directory structure.

3rd: shift+delete with Windows Explorer: it wastes loads of time checking the contents before starting deleting anything.

Slowest: Send to Recycle Bin, as you still need to delete them

Source:
http://stackoverflow.com/questions/186737/whats-the-fastest-way-to-delete-a-large-folder-in-windows/6208144#6208144