Sharing some Bits

To be a lean developer through sharing!

Swap parameters using regular expression

This issue is occurred to me many times while sending review request, for example when I use Assert.AreEqual() method and the parameters are not in the order ( expected value, actual value) is got swapped. It’s boring and long vexing job to correct all the Assert.AreEqual() parameter order. While searching on Internet found this easy way to swap the parameters using Regular Expression.

1
public static void AreEqual(object expected,object actual)  

For example, I wrote code like :

1
2
3
Assert.AreEqual("ActualString1", CretedString1);  
Assert.AreEqual("ActualString2", CretedString2);
Assert.AreEqual("ActualString3", CretedString3);

The parameter is reversed order, it’s not right and For sure I will get a review comment to change this. To swap this parameter we can use find and replace with regular expression.

Note : Regular Expression in Visual Studio is bit different.

Add this as Search Term
1
\((".*"),([^\)]*)  
Add this as Replace Term
1
($2, $1  
How its works

alt text
For information about regular expressions that are used in replacement patterns, see Substitutions in Regular Expressions. To use a numbered capture group, the syntax is $2 to specify the numbered group and (x) to specify the group in question.
For example, the grouped regular expression (\d)([a-z]) finds four matches in the following string: 1a 2b 3c 4d.
The replacement string z$1 converts that string to z1 z2 z3 z4.

Example Screenshots

Before :
alt text

After :
alt text

  • Be careful to select code part you want to swap parameter. Don’t apply for whole Document or Solution, It might do some harmful effects.
  • You can tweak the RegX for other use cases where parameter pattern is different.
  • There exist some shortcuts to reorder the parameter in VS but ii didn’t work for me and even if it work, We need to select each AreEqual method and apply those shortcut.
More Reference:

No Access Error in Visual Studio

The given below error is very common, frustrating and encountered by many Visual Studio users.

1
Unable to copy file "obj\Debug\project.pdb" to "bin\project.pdb". Access to the path 'bin\project.pdb' is denied.

It was caused by the pdb or dll file made read only or hidden by the Visual studio itself. If you just remove those attributes from that file this error will go away. But the process is little ve
StackOverflow question
No Access to the path error look like this:
Alt text

Unblock Dll Extension

A tiny helper to remove the ReadOnly and Hidden attribute from dll’s and executables which blocking the Visual Studio from building the project. Link to download

What does it do

Right click on the Error List window and click the Unblock Files menu item.
alt text
Result of the action will be shown in message box like this :
alt text

  • The extension will find all the files causing the error and remove all the Read Only and Hidden attribute.
    Please feel free to send the feedback, bug, or any suggestions.

Introduction

Between compiling and executing a High-Level programming language, Many intermediate steps like Lexical Analyzing, Syntax Analyzing, Semantic Analyzing, Pre Optimizing, Assembly Code generation, Post Optimizing, Assembling, Linking and Loading are happening. In this post we are mainly covering

  • Assembler
  • Linker
  • Loader
  • Disassembler

Assembler

Assembler will create object code from the assembly code. After Assembly Code generation and Post Optimizing, the generated assembly code is translated to Object code. Assembly Language aka asm is low-level programming language which is specific for CPU architecture. Its actually human readable representation of machine code.
For example:
Assembly Code for moving value 55 hex into register BL

MOV BL, 055H

Corresponding Machine Code

10111000

An assembler will generate object code by translating combinations of mnemonics and syntax for operations and addressing modes into their numerical equivalents. Each object code file combined to create the executable file.

In short, assembler will

  • Translate assembly instructions, macros, and pseudo-instructions into binary machine instructions
  • Convert decimal numbers, etc. specified by programmer into binary.
  • Put the translated instructions into a file for future use.

Types of Assemblers

** 1) Two pass assembler **
In two pass assembler we use two pass to complete generation of machine code. First pass we will create a symbol table (SYMTAB) where we keep all the symbols and their values. Any unknown values or addressed we encounter we will add it to the symbol table and update it when we encounter that value in future. For example

10 JMP LOOP_END 	\\ Address of label2 is unknown we add this to symbol table.
11 ADD  EAX EBX
12 LOOP_END:       \\ Here we update the symbol table with actual address.

Symbol Table 

| Symbol Name | Symbol Value |
|:-----------:|:------------:|
|    LOOP_END |      12      |
|    Label2   |      18      |

Using the symbol table we will create valid machine code on the second pass.

2) One pass assembler
In one pass assembler, we convert the whole assembly code in to machine code by one pass unlike two pass assembler. We keep different type of symbol table where each unknown symbols and all locations it used are stored. Whenever we encounter the initialization of the symbol we will check the symbol table and go back to update all places it used with the actual value.

Object File

Object files are group of blocks of information about the program in binary format. Blocks contain program code, program data, and data structures that guide the linker and loader. Its the output from the assembler there are different forms of object file based on how it used.:

  1. Relocatable object file. Contains binary code and data in a form that can be combined with other relocatable object files at compile time to create an executable object file.
  2. Executable object file. Contains binary code and data in a form that can be copied directly into memory and executed.
  3. Shared object file. A special type of relocatable object file that can be loaded into memory and linked dynamically, at either load time or run time.

Common object file formats

  • COFF : Common Object File format. Windows uses a variant of COFF called the Portable Executable (PE) format.
  • ELF : Executable and Linkable Format Mainly used in Linux.

Linker

Linker will take all the object file created by the assembler and combine them into a single executable file , library or another big object file.Which can be be loaded to the memory and execute. It enable separate compilation and gives modularity to big programs.

  • Symbol resolution.
    Object files define and reference symbols. The purpose of symbol resolution is to associate each symbol reference with exactly one symbol definition.

  • Relocation.
    Compilers and assemblers generate code and data sections that start at address 0. The linker relocates these sections by associating a memory location with each symbol definition, and then modifying all of the references to those symbols so that they point to this memory location.

  • Static linkers.
    Such as the Unix ld program take as input a collection of relocatable object files and command line arguments and generate as output a fully linked executable object file that can be loaded and run.

Stand Up Script

Powershell script that will alert at each hour by Desktop notification as well as using beep sound. To avoid continues sitting and working this script will help to remind to stand up or relax each hour. It will lock the PC at each hour too :)

What does it do

  • It will beep according to the time.
  • Show Desktop notification with time and message.
  • Lock the the computer automatically after the notification.

Screen Shot of Notification:
alt text

To Do

  • Get time interval for notification from user as command line parameter.
  • Change the busy waiting to sleep.
  • Re-factor the code.

How to Run it

  • Download the script from github.
  • Run powershell StandUpAlaram.ps1

Please feel free to send the feedback, bug, or any suggestions.

You’ve just pushed your local branch to a remote branch, but then realized that some errors happened.

Eg:

  • That there was some unacceptable typo in commit message.
  • You just added a unwanted file like ~files or class file.

Don’t worry you can revert it to back to your previous safe commit by reverting your current commit.

$ git reset HEAD^ –hard

$ git push origin master -f

First step reset the branch to the parent of the current commit.
Second step force-push it to the remote.


More Details: Revert a commit already pushed to a remote repository -Christoph Rüegg

0%