Posts

Showing posts from 2009

WCF - Reading from Application Configuration File - config section - system.serviceModel

I can't find any example on the web for this, so i guess it could be helpful. This is a simple example to show a way to read the system.serviceModel configuration section in application/web configuration file. Something like for ConnectionString, there is a straightforward class for that, ConfigurationManager.ConnectionStrings["keyname"].ConnectionString Codes snippet below ServiceModelSectionGroup group = ServiceModelSectionGroup.GetSectionGroup(ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)); //suppose if there is only one endpoint if(group.Client.Endpoints.Count < 0) { uri = group.Client.Endpoints[0].Address.AbsoluteUri; }

Stop Symantec Endpoint Protection Weekly Scheduled Scan Momentary

The intention of weekly scheduled scan is good, it helps to safeguard and diagnose your computer from malware. It is a setting set by the most system administrator that any computer with endpoint protection installed would need to oblige this and have it scan every week. It is a centralized setting where users can't change it at the user end. However, for an advanced user like myself who knows how to take care of my computer, running a PC scanning even on my peak hours are really intrusive. Therefore, after some trial and error, i notice if I use process explorer to kill the rtvscan.exe while it is running, it would force the scanning to terminate itself. And the best thing is antivirus would still be up and running and no restart required. Probably you would need to enable back the protection at the setting where it would prompt you too. That is all you need to do. (this is my backdoor trick, use it at your own risk.)

Visual Studio .NET 2008 - Some conditional breakpoints not getting triggered and workaround.

If you read some debugging tips or reference on conditional breakpoint. You would notice that what is in the instruction should be straightforward and there is no reason why it won't work when you try it out. However, there are times when you set conditional breakpoint , a very simple one like say in you code, string a[] = {"21", "123", "32", "1234", "sds"}; foreach (string myString in stringArray) { Console.WriteLine("myString = " + myString); //conditional breakpoint set here. } conditional breakpoint set as myString == "1234" but to your surprise, it would not break and stop there. It is a very simple thing you would do but it just seems not working. For most people, they would just set normal breakpoint there and run a few more iterations and bypass the use of the conditional breakpoints but this is not my liking. This is a VS.NET function that I would really like it to work. It is af...

C# 2.0 syntax reference

readonly - member variable of class where can only be initialized once in constructor. yield - contruct return for IEnumerable e.g. IEnumerable GetNumbers() { yield return 1; yield return 2; yield return 3; yield return 4; yield break; } This is return a 1,2,3,4 list. this() - calling class constructor this[] - [] operator override e.g public int this[int i] { get { return 1; } } generic programming //where TbaseClass is use for T calling function class C1<T>:D1 where T:TbaseClass class B1 : C1<myInherittedTbaseClass>

C# pass-by-value and reference type

If you are coming from C/C++ programming background. You would be accustomed with heavy use of pass by reference (or pass by pointer) as a way to improve the performance, update the variable passed in and reducing memory consumption. It is so common, that most C/C++ function written to be efficient would be passing by constant reference (if they do not wish to allow variable passed in get updated) Like void myFunction(const MyClass & param) So, you are rest assured that variable pass in would not get updated. For C#, there is no such thing as const reference. But, there is pass-by-ref, unsafe pointer and pass-by-value. So, to ensure that your variable passed in to function not get updated. You would naturally think of using pass-by-value. However, there is a catch for pass-by-value if your object is of reference type (class, interface, delegate, objet, string) Value type variable store value but reference type variable store references to object. So, even the reference is passe...

Smart Thinking & Lateral Thinking (Edward De Bono)

(These are just my own "personal" summary to Edward De Bono smart thinking & lateral thinking materials where I have came across some of his books lately. (for my own reference) Please visit authorized Edward De Bono web sites if you are interested in these topics. http://www.edwdebono.com/) Lateral Thinking - 6 thinking hats White Hat - Based on hard data, facts, figures and numbers Red Hat - Based on hunch, gut feeling emotional point of view Black Hat - Pessimistic, sad & negative view but logical. Yellow Hat - Glad and possitive but logical view. Green Hat - Alternative, creative and sprouting new idea. Blue Hat - Step back and take care of process of thinking. Deciding hats to be used and summarize what have been thought. Critical Thinking - A way to minimize mistake in thinking. Creative Thinking Provocative Operation - Come up with an absurd idea. Then, think of "movement". Movement - Think of ways to make provocative operation / ran...

DOS prompt batch

Was trying out something on batch file, quite interesting though has limited features. But would be a quick way to delivery some solutions. Always check what batch can do before want to write a program for it. Good place to start on batch programming at -> http://www.allenware.com/icsw/icswidx.htm SET MYLOCATION = C:\Folder REM A reversible CD command where you can go back where you REM came from. pushd %MYLOCATION% REM check for file existent if not exist *.txt goto ERROR for %%file in (*txt) do type "%%file" >> mySingleFile.txt IF ERRORLEVEL 1 goto ERROR popd :ERROR echo Error occurredEXIT /B 1

XSL - Altering child attribute with original parent attribute

XML <?xml version="1.0" encoding="utf-8"?> <Items xmlns="http://www.abc.com" xmlns:myns="http://www.abc.com"> <Item attr="1"> <field1>My Content 1</field1> </Item> <Item attr="2"> <field1>My Content 1</field1> </Item> <Item attr="3"> <field1>My Content 1</field1> <field2 innerAttr="a">My Content 2</field2> </Item> </Items> XSL <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:myns="http://www.abc.com" xmlns="http://www.abc.com" > <xsl:output omit-xml-declaration="no" indent="yes"/> <xsl:namespace-alias stylesheet-prefix="#default" result-prefix="#default...

Resumeable Windows File Copying

Recently having need to copy huge files or a whole set of files more often over the network. Thinking of finding a tool like getright. So, this is the tool I found really useful. Robocopy - http://en.wikipedia.org/wiki/Robocopy How it fit my usage is with command like below. robocopy \\source\dir \\destination\dir /W:15 /R:30 /E /Z W = 15 seconds pause should it failed R = Retry of 30 times Z = Restartable mode E = Copying content recursively (including subfolders content) (use /MIR if want to mirror both side of content instead of /E. /MIR would remove the destination file if not found in source)

Adding notepad, command prompt, powershell run here context menu

Create a text file, name it temp.reg. Then, for each application you want to add it context menu. Copy and paste to the temp.reg. Then, just execute the temp.reg by double clicking it. For Powershell -------------- Windows Registry Editor Version 5.00[HKEY_CLASSES_ROOT\Directory\shell\powershell]@="PowerShell Here"[HKEY_CLASSES_ROOT\Directory\shell\powershell\command]@="C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -Command Set-Location -LiteralPath '%L'" Command Prompt ----------------- Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\Directory\shell\CommandPrompt] @="Command Prompt Here" [HKEY_CLASSES_ROOT\Directory\shell\CommandPrompt\command] @="C:\\Windows\\system32\\cmd.exe /k pushd %1" Notepad ---------- Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\*\shell\Edit in Notepad] [HKEY_CLASSES_ROOT\*\shell\Edit in Notepad\command] @="notepad.exe \"%l\""

Searching word/phrase in a very large text file in windows

1. Firstly, you need to have a grep tool (like Unix). For windows, you can try http://www.wingrep.com/ 2. Then, you just search a word/phrase in the text file with simple query or advanced regular expression query in the wingrep. 3. You should be getting the line number in the grep search result. 4. Then, start dos prompt. 5. Type command - "more +123 YourHugeFile.txt" where 123 for example is the line number you wish to see starting from. 6. Then, you should see some content in "more" dos screen. 7. If you wish to scroll line by line in "more", key in "enter/ret". if you wish to go page by page, key in "space" 9 Once you are done, type "CTRL + C" to exit.