### Archive

Archive for the ‘Cheat-sheet’ Category

## First the basics

am_execute( cmd, args, admin);

The first argument is the command we wish to execute, the second one is the command line argument and the last one is if we wish to run as administrator or not, (with privileged access).

## How to get the arguments?

You have various commands to get the arguments entered.

You can get the ones typed by the user

-- the number of arguments
local sizeOf = am_getCommandCount();

-- argument number 0 is the action itself, (what he user typed in).
local action= am_getCommand( 0 );
...
-- argument number 1
local cmd= am_getCommand( 1 );

Or you can also get the selected folder if there is one

Remember that we could have selected more than one folder

-- do we have a folder?
local thisFolder =  am_getfolder( 0, false );

## Putting it all together

If you have an app like cmder or even the default command line app you can put it all together

-- the location of the cmder.exe if it is not in the path.
local cmderPath = [[c:\path\to\your\cmder\Cmder.exe]];

-- do we have a folder?
local thisFolder =  am_getfolder( 0, false );

-- if we don't have a folder, guess what we are looking for.
if thisFolder == false  then
local sizeOf = am_getCommandCount();
if sizeOf == 0  then
-- no arguments.
am_say( "<i>Going to <b>home</b> drive</i>.", 400, 10  )
am_execute( cmderPath, [[/START %HOMEDRIVE%\]], true );
else
local thisWord = am_getCommand( 1 );
if thisWord == "home" or thisWord == "h" then
am_say( "<i>Going to <b>home</b> drive</i>.", 400, 10  )
am_execute( cmderPath, [[/START %HOMEDRIVE%\]], true );
elseif thisWord == "system" or thisWord == "s" then
am_say( "<i>Going to <b>system</b> drive</i>.", 400, 10  )
am_execute( cmderPath, [[/START %SYSTEMDRIVE%\]], true );
else
am_execute( cmderPath, "", true );
end
end
else
-- go to the selected folder and in case of multiple drives, change the drive letter.
am_say( "<i>Going to <b>".. thisFolder .."</b></i>.", 400, 10  )
am_execute( cmderPath, "/START \"" .. thisFolder .. "\"", true);
end


And save the file and call it “cmder.lua” and save it in your root command folder, (or subdirectory).

Then if the user types

• cmder home – they will go to their home directory
• cmder – they will go to their system drive
• cmder (with the cursor over a folder name) – they will go to that folder.

## More?

Categories: Tags:

## Design principles – SOLID

We often ask people in interview to explain the solid principles and what they mean.

The other day I found a series that goes into details about the SOLID principles

Those are rather long videos, but they go into great details explaining the SOLID principle.

Categories: Tags:

## Why?

While it is easy(ish) enough to add google test using various packages, you might want to add it directly to your project, (to debug your tests and so on).

I also found that packages are not always as often as you might want, so it might be because you need a new feature or something added to your test.

## Before we start

– I am using Visual Studio 2019, but it should work fine with 2017 and even 2015
– I am using the latest Google Test (v1.10 at the time of writing this, but the principle is the same for almost all versions and should work fine for a few versions.

## Getting started

• Go to Google test on Github and get the latest release, make sure you get the ‘source code’
• Don’t get it from anywhere else, you don’t know what has been changed and who changed it!
• Remember that google test is written to a test application, not your main application!
• Create a new console application, (File > New > Project …) and select “Console App”

• In your project, create a new ‘folder’, I normally prefer to have it mirror what it looks like in my actual windows source code directory, but you could call it whatever you want, (like I did below).
• Right-click on the ‘src’ folder and select “Add > Existing Items…”
• Navigate to the folder you extracted, and find the ‘googletest > src’ folder
• And then select ‘gtest_main.cc’ and ‘gtest-all.cc’, nothing else.
• Finally, right-click your project and select “properties” and edit the “Additional Include Directories”
You could enter the full path if you want, (but that … blah), or you could use macros …
Either way, make sure that the path is valid.
• Make sure that the changes you make apply to all your build configuration.
In the screenshot above I have x64 and Release but make sure that you choose all the configurations you will be using.
• Compile your code … nothing funny should happen, (’cause you did nothing really).
If you get an error, double check your paths and permissions.

## Write and run a test

Last but not least, write a very simple test in your main and run a test

## You do the rest

Now that a simple test is running, you can start creating tests for your own project.

### Example?

Have a look at my directory watcher project and see my own tests.

As an aside, I am alway looking for comments, reviews and so on, please have a look at the project and comment!

Categories: Tags:

## Delete a git branch local and remote

This is a continuation of my earlier post about pruning deleted branches

To delete a local branch

or you can ‘force’ a delete if you have uncommitted changes
The -D is the same as --delete --force

To delete the branch remotely, simply do …

You can also do it like that if you prefer.

Again, you can use -d.

If you want to delete a remote and local branch, it is easier to first delete the remote branch and then the local branch.

You can then go ahead and prune all the branches.

Categories: Tags:

## How to delete/prune old local git branches

When you delete a branch with git, and push those changes, you might see that your local repo still has that branch in the list

What this basically does is fetch all the branches and all the ones with a ‘gone’ attribute, (meaning deleted remotely), then we will remove them.

You can view the branches and what their attribute is yourself by typing

Of course, you need to prune the branches on the remote git server

To make sure all is good, just re-list your branches, (local and remote)

Categories: Tags:

## Migrating from MSTest to NUnit

I am using VS2015 and VS2017 and I needed to migrate from Microsoft Unit tests to NUnit.

Those are the steps are followed.

• In VS2015/2017 Select the “Package manager console” tab
Select the correct project, (drop down combo), and type

• Or using Nuget manager
• Select the correct project.
• Select NUnit, (just the plain ‘NUnit’ for now).
• In your test project, look for “using Microsoft.VisualStudio.TestTools.UnitTesting;
Replace with “using NUnit.Framework;“, (of course you will now have a whole bunch of errors.)
• Look and replace
• [TestClass] replace with [TestFixture]
• [TestMethod] replace with [Test]
• Remove code that looks like “[ExpectedException(typeof(xyz), “some text”)]” and surround the actual code that is expected to throw

NB: Note you might need to change a couple of other values

• [TestInitialize] to [SetUp]
• [TestCleanup] to [TearDown]
• [TestClassInitialize] to [TestFixtureSetUp]
• [TestClassCleanup] to [TestFixtureTearDown]

And a few other functions will need to change as well but for the most part they start with Assert.... and are fairly close(tm) to the Microsoft counterparts.

Categories: Tags:

## Deleting folders that refuse to be deleted…

Sometimes when you want to delete a folder in windows you get a very useful message “Could not find this item… this is no longer located in …”, (yes, the very item you just tried to delete).

So after a bit of cursing, making sure that you are indeed the admin of this box, praying to the windows gods you realise that maybe Windows Explorer is at fault.

Not to worry you think, you open up a cmd line console and navigate to the parent of the offending folder.

And like a true hacker you type

only to be told once again, “The system cannot find the file specified.”

At this point your realise that the folder has spaces… so you think “no problem, I will quote the folder” and you now type

with the correct number of spaces in the folder name.

Long story short… you cannot do that.

You cannot rename the folder, (I know you will try anyway, but you can’t)

So you Googled for a solution and here you are…

what you need to do is tell the command line to not trim the folder name and to do that, you have to add “\?\” in front, so now you type

Complete with the extra spaces and so on… (I added the /s and /q flags because you forgot that the directory is not empty)

Categories: Tags:

## vs2015/2013 – Cannot see unit tests in Test Explorer window

If have some unitests in Visual Studio 2015 or 2013 but you cannot see them in your “Test Explorer window”

If you look in your output window, (under “Show output from:” > “test)

An exception was thrown while initializing part “Microsoft.VisualStudio.TestWindow.UI.TestWindowToolWindowControl”.

The solution is just to delete the VS2013/VS2015 cache folder, located either in

%LOCALAPPDATA%\Microsoft\VisualStudio\12.0\ComponentModelCache

For VS2013, or

%LOCALAPPDATA%\Microsoft\VisualStudio\14.0\ComponentModelCache

For VS2015

Categories: Tags:

## Git and submodule

Sometimes things get a little out of sync in your submodule folder, your ‘root’ project sometimes report something like

\ In the git branch [branch = +0 ~1 -0 !]>

Or even  something along the lines of

\ In the submodule folder [(7cd98ce...)]>

Showing that you are no longer on the correct branch, (for the submodule).

One one way to clean it all up is to do.

\ In the submodule folder git checkout master git pull git push origin HEAD:master git checkout master 

Assuming that you have no other changes to commit

\ In the root folder git clean -fd git pull git submodule update --init --recursive git submodule update 

And that should clear everything

Categories: Tags:

## Using Github from command line

This assumes that you have all the permissions needed to access your repo, (passwords and so on).

Start Git Shell and navigate to your local repo.

Create a branch
 git checkout -b <branch-name> git push <remote-name> <branch-name> 

In the case of github the remote name is ‘origin’

Source

 git add . 

The ‘.’ means ‘everything’ that was changed.

You can use ‘status’ to check what needs to be staged, (or what has been staged).
 git status 

Commit branch
 git commit -m "You message here" 

Push branch
The first time you need to tell where you are pushing this to.
 git push --set-upstream <remote-name> <branch-name> 

The afterwards you just need to do…
 git push 

 git push <remote-name> --delete <branch-name> 
 git branch --delete <branch-name>