Monday, December 19, 2011

RESTful Windows Client

Good tutorial
WCF REST Starter Kit

AWS - Amazon Web Services

Credentials

Monday, December 12, 2011

Certificate error when redirecting http://localhost to https://localhost

On IE, after the certificate error page is shown, clicking "Continue ..." link doesn't work.



  • "http://localhost" is by default is assigned to "Locked-down Local Machine Zone" by Windows (later than XP SP2)
  • When "http://localhost/" is redirected to "https://localhost/", IE detect server SSL certificate error and shows an error page. 
  • This error page is internally has URL "res://ieframe.dll/invalidcert.htm?SSLError=50331648#http://localhost/" and is considered to be in "Internet Zone".
  • "Locked-down Local Machine Zone" by default doesn't allow navigation into its zone from a less privileged zone (e.g. "Internet zone"). Thus clicking continue button is ignored.


Workaround for this problem

  • Acces "https://localhost/". "https://localhost" is by default considered "Local Intranet zone" thus navigating from "res://ieframe" is possible.
  • Access "http://127.0.0.1/". "http://127.0.0.1/" is by default considered "Internet zone" thus navigating from "res://ieframe" is possible.
  • Add "http://localhost" to "Trusted Zone". "Trusted Zone" allows navigation from "Internet Zione" thus navigating from "res://ieframe" is possible. 
  • Using Group policy editor (gpedit.msc), edit User Configuration - Administrative Templates - Windows Components - Internet Explorer - Internet Control Panel - Security Page - Locked-down Local Machine Zone, and set "Web sites in less privileged Web content zones can navigate into this zone" to Enabled (don't forget to set the Options part inside the dialog to "Enabled" too).


Notes: Adding "http://localhost" to "Trusted zone" (or any other zones) internally remove it from "Locked-down Local Machine Zone". If "http://localhost" is afterwards removed from "Trusted zone", it will no longer explicitly bound to any zone and will be considered to belong to "Internet zone". Thus the problem reported here won't reappear after the removal.

Friday, November 18, 2011

Cryptography

Shared-key encryption
  • c = Enc(key, msg) ----(c)---- msg = Dec(key, c)

Shared-key signature
  • m,a = h(key, m) ----(m,a)---- m,a =? h(key, m) 

Public-key encryption
  • c = Enc(P-recv, m) ----(c)---- m=Dec(S-recv,m)

Public-key signature
  • m,a = f(S-send, m) ----(m,a)---- m,a =? g(P-send,m)

Certificate is basically a message signatured by a Certificate Authority (CA)
  • m,a = f(S-CA, m) ----(m,a)---- m,a =? g(P-CA, m)

SSH see a good summary at http://aperiodic.net/phil/ssh/
  • Host sends its public key to client for authentication
  • Key authentication
    • Client generate public-private key pair
    • public key is sent to Host
    • Client doesn't need password anymore (it needs to input passphrase for accessing the private key though)
    • ssl-agent is used to remember the passphrase so that client can log into host without being asked anything
  • Sequence for Key authentication
    • Client connect to Server
    • Server returns a 'challenge'
    • Client create an 'authenticator' from the challenge and its private key, and send it back to Server
    • Server check the 'authenticator' using the Client's public key
  • SSH-Transport layer uses Key Exchange algorithm

Tuesday, October 11, 2011

prototype to jQuery


new Element -> $elem(...)
element.getDimensions() -> $dimensions(element)
element.className = -> $j(element).{has,add,remove}Class
element.addClassName(...) -> $j(element).addClass(...)
element.setStyle(...) -> $j(element).css(...)
element.select(selector) -> $j(selector, element)
$(element).readAttribute(..) -> $j(element).attr(...)
element.show -> $j(element).show()
element.hide -> $j(element).hide()
array.last() -> array[array.length-1]
array.clear() -> array.length=0

Thursday, September 8, 2011

Medical Image Visualization

http://www.vismd.de/doku.php?id=publications:paperall
* MevisLab: http://www.mevislab.de/fileadmin/docs/current/MeVisLab/Resources/Documentation/Publish/index.html
* Medical Imaging Toolkit: http://www.metk.net/help.html

Coding guidelines

Taken from ACCU mailing list:

 * Applied Informatics (2008). /C++ Coding Style Guide, Rules and
   Recommendations/. Retrieved on 20 August 2008.
   http://www.appinf.com/download/CppCodingStyleGuide.pdf

 * Construx (2008). /CxOne General Coding Standard/. Retrieved on 29 August 2008.
   http://www.construx.com/File.ashx?cid=787

 * Gabryelski, Keith (1997). /Wildfire C++ Programming Style, With Rationale/.
   Retrieved on 20 August 2008.
   http://www.chris-lott.org/resources/cstyle/Wildfire-C++Style.html

 * Geotechnical Software Services (April 2007). /C++ Programming Style
   Guidelines/. Retrieved on 20 August 2008.
   http://geosoft.no/development/cppstyle.html

 * Google (2008). /Google C++ Style Guide/. Retrieved on 26 August 2008.

 * Henricson, Mats , Erik Nyquist and Ellemtel Utvecklings AB (1997).
   /Industrial Strength C++/. Retrieved on 20 August 2008.
   http://hem.passagen.se/erinyq/industrial/

 * Hoff, Todd (1 March 2008). /C++ Coding Standard/. Retrieved on 20 August 2008.
   http://www.possibility.com/Cpp/CppCodingStandard.html

 * Lockheed Martin Corporation (December 2005). /Joint Strike Fighter Air
   Vehicle C++ Coding Standards/. Retrieved on 20 August 2008.
   http://www.research.att.com/%7Ebs/JSF-AV-rules.pdf

 * Philips Medical Systems (19 May 2005). Coding Standard: C#". Retrieved on
   20 August 2008.
   http://www.tiobe.com/standards/gemrcsharpcs.pdf

 * Stroustrup, Bjarne (2 May 2008). /C++ Style and Technique FAQ/. Retrieved
   on 20 August 2008.
   http://www.research.att.com/%7Ebs/bs_faq2.html

 * Sutter, Herb and Andrei Alexandrescu (November 2004). C++ Coding Standards.
   Addison–Wesley. ISBN-10 0321113586, ISBN-13 978-0321113580.
   http://www.gotw.ca/publications/c++cs.htm

 * The Programming Research Group (May 2004). /High-integrity C++ Coding
   Standard Manual, Version 2.2/. Requested from
   http://www.codingstandard.com/.

Tuesday, September 6, 2011

How to kill a process tree on Windows

Option 1: Query the system to generate the process tree, then kill each process in the tree as noted below.


http://stackoverflow.com/questions/3235218/how-terminate-child-processes-when-parent-process-terminated-in-c/5680096#5680096

However, there is a corner case that if some of the processes in the tree invokes some other processes between the step collect process <=> create tree, then we will miss the newly created process.

Option 2: Use Job Objects mechanism provided by Windows

On the topmost parent, create a Job Object and assign the current process to it. This way, the later invoked descendant processes are automatically added into the Job Object. Then we can kill the Job Object to kill the entire tree.

http://msdn.microsoft.com/en-us/library/ms684161%28VS.85%29.aspx

This option avoid the corner case on Option 1, however, we need to program the code into the parent process in order to do this. 


Example of using Job Objects from C#

http://stackoverflow.com/questions/3342941/kill-child-process-when-parent-process-is-killed


DLL Init/Cleanup sequence

See ctrdll.c 
- crtdll.c: BOOL WINAPI _CRT_INIT()
- crtdll.c: BOOL __cdecl __DllMainCRTStartup()
  ... this call _CRT_INIT()
- crtexe.c: int __tmainCRTStartup()
  ... similar to __DllMainCRTStartup()


Basic sequence for DLL_PROCESS_ATTACH
for each DLL
 - Call __CRT_INIT() -> invoke C initializers then C++ constructors
 - Call DllMain hook


Basic sequence for DLL_PROCESS_DETACH
for each DLL
 - Call DllMain hook
 - Call __CRT_INIT() -> invoke C+_ destructors and C atexit()/_onexit() ... reverse order of initialization


Basic sequence for DLL_THREAD_ATTACH and DLL_THREAD_DETACH
for each DLL
 - Call DllMain hook


CWinApp::InitInstance and CWinApp::ExitInstance are called as part of DllMain hook (they are only called for DLL_PROCESS_ATTACH and DLL_PROCESS_DETACH).


Article regarding the order of DLL loading:
http://blogs.msdn.com/b/oleglv/archive/2003/10/28/56142.aspx

"Well, turns out that the loader seems to be preserving the order in which the imported DLLs are listed in the Imports Section of the loading executable."







Sunday, July 3, 2011

Bull's eye

Bull's eve fusion on Volume Rendering
Technical Aspects of Bull's eye

Hearts
- {Left,Right} x {Atrium,Ventricle}
- Diastole, Systole
- Left Ventricle -> Apex ... Base
- Coronary arteries:
  - RCA: Right Coronary Artery
  - LAD: Left Anterior Descending
  - LCX: Left Circumflex

Good introduction inside the thesis

Saturday, June 25, 2011

Javascript HTML CSS

* Non-integer offsetWidth and offsetHeight in IE9 and FF4
http://vadikom.com/dailies/offsetwidth-offsetheight-useless-in-ie9-firefox4/


* Memory Leak:
http://www.javascriptkit.com/javatutors/closuresleak/index.shtml
http://msdn.microsoft.com/en-us/library/Bb250448
http://stackoverflow.com/questions/1051090/how-can-i-control-ie6jqueryjquery-ui-memory-leaks
http://www.reigndropsfall.net/2011/01/05/internet-explorer-event-handler-leaks/
http://kirblog.idetalk.com/2011/06/prototype-17-memory-leak.html
Drip http://outofhanwell.com/ieleak/index.php?title=Main_Page

* How to handle IE6
http://www.virtuosimedia.com/dev/css/ultimate-ie6-cheatsheet-how-to-fix-25-internet-explorer-6-bugs


* Speeding up access
http://developer.yahoo.com/performance/rules.html

* Cache control

Four headers:
◆ Last-Modified
◆ Expires
◆ Pragma
◆ Cache-Control
   - public:             Can be cached anywhere
   - private:            Only cacheable by browsers
   - no-cache:           Cannot be cached anywhere
   - must-revalidate:    Caches must check for newer versions
   - proxy-revalidate:   Proxy caches must check for newer versions
   - max-age:            A duration, in seconds, that the content is cacheable
   - s-maxage:           Overrides the max-age value for shared cachesC

Conditional GET and Etag http://jagbarcelo.blogspot.jp/2009/03/conditional-get-and-etag-implementation.html

Caching tutorial http://www.mnot.net/cache_docs/