Find and replace with regular expressions in Visual Studio 2013.

Lets say you have this:

FOO(Main)(int a);
FOO(Main_Bar)(int a);
FOO(Main_Foo)(int a);

And you want to convert it into this:

BAR MyClass::Main(int a);
BAR MyClass::Main_Bar(int a);
BAR MyClass::Main_Foo(int a);

Notice FOO is replaced with BAR MyClass:: and parenthesis around the method name are removed.

To make this happen, find this:

FOO\(([a-z_]*)\)

Notice that [a-z_]* is surrounded by an extra pair of parenthesis. That makes this match (capture group) reusable in the replace expression.

Then replace with this:

BAR MyClass::$1

$1 is replaced with the value of the first capture grou, if we put more capture groups in the find expression, $2 will be the value of the second capture group and so on.

One more thing, capture groups values can be used in the same find expression, e.g., to go from this:

int MyClass::Main_Bar(int a);
double MyClass::Main_Foo(int a);
double MyClass::Main_Fizz(double a);

To this:

Object MyClass::Main_Bar(Object a);
double MyClass::Main_Foo(int a);
Object MyClass::Main_Fizz(Object a);

Find this:

([a-z_]*) MyClass::([a-z_]*)\(\1 a\)

\1 matches the value of the first capture group in the same find expression.

And replace with this:

Object MyClass::$2(Object a)

Notice the value type was only modified on those methods that have the same value type in the input parameter and in the return value.

Source: http://stackoverflow.com/questions/7848329/search-and-replace-in-visual-studio

WinDbg go up (gu) without hitting any other breakpoint.

Today I defined hundreds of breakpoints, including breakpoints in functions A, B and C.

When I break into function A, I want to go up (run until the current function returns) without breaking into other breakpoint.

MyApp!A <--- First break.
MyApp!main <--- I want to go back to main without breaking anywhere else.

Unfortunately, function A calls B and B calls C. So I have to break into B:

MyApp!B <--- Second break.
MyApp!A
MyApp!main

And then into C:

MyApp!C <--- Third break.
MyApp!B
MyApp!A
MyApp!main

Before coming back to main.

And easy solution to this problem is to disable all breakpoints, go up, and re-enable all breakpoints, i.e.:

bd *; gu; be *;

You don’t have to remove B and C breakpoints and define them again after going up.

 

 

Make a permanent command line alias for Notepad++ in Windows.

Are you a huge fan of Notepad++ like I am?

Well, if it is not enough with adding Notepad++ to the path:

c:\> set path=%path%;c:\Program Files (x86)\Notepad++

And registering the Notepad++ shell extensions:

regsvr32.exe "c:\Program Files (x86)\Notepad++\NppShell_05.dll"

Then, you may want to create a command line alias, so instead of:

c:\> notepad++ something.txt

You only type:

c:\> np something.txt

And still enjoy the benefits of not renaming the notepad.exe binary.

Step 1

Create the batch script that registers the alias and save it as notepadAlias.cmd

@echo off
doskey np=notepad++ $*

Step 2

Create a Registry Editor script. Make sure to replace C:\\path\\to with the path where you saved the batch script:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Command Processor]
"CompletionChar"=dword:00000009
"DefaultColor"=dword:00000000
"EnableExtensions"=dword:00000001
"PathCompletionChar"=dword:00000009
"Autorun"="c:\\path\\to\\notepadAlias.cmd"

This will execute the batch script each time a command line is started.

Step 3

Execute the Registry Editor script (double click  > Yes > Yes > Ok).

Step 4

Open a new command line, type np and see Notepad++ opening.

Upgrading from HDD to SSD (2014)

I have a 4 years old Sony Vaio EA with a Hard Disk Drive (HDD) with 5400 RPM rotation rate. Today I had nothing to do, so I decided to replace its HDD with a Solid State Drive (SSD). This should be a good performance improvement. I made some analysis using CrystalDiskMark before and after replacing the drive, and the images speak by themselves:

CrystalDiskMark Sony Vaio VPCEA37FL Before

Sony Vaio EA Before Upgrade

Sony Vaio EA After Upgrade

Sony Vaio EA After Upgrade

The results are awesome. Roughly, the read and write speeds increased 196%. But, how does this compare with modern machines in the market? Here are the Lenovo Yoga 2 Pro results, a machine that comes with a SSD by default:

CrystalDiskMark Lenovo Yoga 2 Pro

Lenovo Yoga 2 Pro Results

The Lenovo machine is 100% faster reading, however writing both machines have almost the same performance.

Emoji characters in all web browsers running on Windows?

The following CSS snippet will display your Emoji characters correclty in all browsers running on Windows, including Internet Explorer and Google Chrome.

.emojiText {
    font-family:"Segoe UI Symbol";
}

Then apply the CSS style to your text:

<p>
    Websites are funnier with
    <span class="emojiText">&amp;#128565; &amp;#128126;</span>
</p>

Click here for a live example.

HttpMultipartFormDataContent vs HttpMultipartContent

Here is an example of how to use the HttpMultipartFormDataContent class from the Windows.Web.Http namespace:

HttpClient client = new HttpClient();
HttpMultipartFormDataContent multipart = new HttpMultipartFormDataContent("xxXXxxXXXxXXXxXXXxX");
multipart.Add(new HttpStringContent("hello"), "Thing1");
multipart.Add(new HttpStringContent("world"), "Thing2", "foo.txt");
multipart.Add(new HttpBufferContent((new byte[] { 0x21, 0x22, 0x23, 0x24 }).AsBuffer()), "Thing3");
HttpResponseMessage response = await client.PostAsync(uri, multipart);
Debug.WriteLine(response);

Output:

POST / HTTP/1.1
Accept-Encoding: gzip, deflate
Content-Length: 446
Content-Type: multipart/form-data; boundary=xxXXxxXXXxXXXxXXXxX
Host: localhost
Connection: Keep-Alive
Cache-Control: no-cache

--xxXXxxXXXxXXXxXXXxX
Content-Length: 5
Content-Type: text/plain; charset=UTF-8
Content-Disposition: form-data; name="Thing1"

hello
--xxXXxxXXXxXXXxXXXxX
Content-Length: 5
Content-Type: text/plain; charset=UTF-8
Content-Disposition: form-data; name="Thing2"; filename="foo.txt"; filename*=UTF-8''foo.txt

world
--xxXXxxXXXxXXXxXXXxX
Content-Length: 4
Content-Disposition: form-data; name="Thing3"

!"#$
--xxXXxxXXXxXXXxXXXxX--

Doing the same thing with HttpMultipartContent takes a little bit more of effort:

HttpClient client = new HttpClient();
HttpMultipartContent multipart = new HttpMultipartContent("form-data", "xxXXxxXXXxXXXxXXXxX");
IHttpContent content1 = new HttpStringContent("hello");
content1.Headers.Add("Content-Disposition", " form-data; name=\"Thing1\"");
multipart.Add(content1);
IHttpContent content2 = new HttpStringContent("world");
content2.Headers.Add("Content-Disposition", " form-data; name=\"Thing2\"; filename=\"foo.txt\"; filename*=UTF-8''foo.txt");
multipart.Add(content2);
IHttpContent content3 = new HttpBufferContent((new byte[] { 0x21, 0x22, 0x23, 0x24 }).AsBuffer());
content3.Headers.Add("Content-Disposition", " form-data; name=\"Thing3\"");
multipart.Add(content3);
HttpResponseMessage response = await client.PostAsync(uri, multipart);

Obviously HttpMultipartContent has more flexibility than HttpMultipartFormDataContent. There are more multipart content types other than multipart/form-data, e.g.: multipart/mixed, multipart/digest, multipart/message, multipart/alternative, multipart/related, etc.

 

 

 

Disable the touchpad swipe that opens Windows 8.1 charms in Lenovo Yoga 2 Pro.

To disable the touchpad gestures that open app bars and show Windows 8.1 charm bars:

  1. Open Mouse Properties.
  2. Click Device Settings tab.
  3. In Devices list select Synaptics ClickPad V8.1 on PS/2 Port and click Settings…
  4. In Edge Swipe section uncheck Enable Edge Swipes.

Mouse and Touchpad Swipe Settings

Additionally, if you don’t like at all the feature of opening the charm bars when placing the mouse in the left-upper corner or right-upper corner, you can disable by:

  1. Right click in the task bar.
  2. Click Properties.
  3. In the Taskbar and Navigation properties window, click Navigation tab.
  4.  Uncheck When I point to the upper-right corner, show the charms.
  5. Uncheck When I click the upper-left corner, switch between my recent apps.

Navigation Settings