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

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

Powershell cheatsheet for C++/C#

This is just a small post to help my ageing memory remember where things are located.

  • Powershell C#
    Locate the dll, System.Management.Automation.dll, and add it to your project, (or add it via Nuget).

    • See this blog for a good introduction on creating a project, (works for vs2015).
  • Check what version is installed
    • According to the official site you need to check the registry
      HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1
      or
      HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\3
      And check that the value Install is set to ‘1’.
  • Debuging
    • The external program is C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
    • But the actual location is:
      • Powershell 1: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\PowerShellEngine\{ApplicationBase}
      • Powershell 3:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine\{ApplicationBase}
    • Launching from debuger:
      • For a script:
        PowerShell -Command “& {.\myscript.ps1}” or
        PowerShell -File “.\myscript.ps1”
      • For a CmdLet/Module:
        -noexit -command “&{ import-module .\AMPowerShellCmdLets.dll -Verbose}”
  • Some links

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

Add your changes to the branch

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

Delete your branch

To remotely delete it

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

To locally delete it


git branch --delete <branch-name>

Source

How to compare multiple folders with BeyondCompare 4 and Piger

Why?

In some cases you might often need to compare folders using beyond compare and using a Piger command might just do the trick.

The problem is that you might want to open/compare more than one folder at a time, so here is how to do it.

How

First of all, go and download your version of Beyond compare and get the latest version of Piger.

Open a blank file with your favourite editor, we will create a LUA file in this case.

— the path to the BC4 exe.
local bCompare = [[%ProgramFiles%\Beyond Compare 4\BCompare.exe]];

— compare folder A and folder B
am_execute( bCompare, [[/filters=”-bin\;-*.exe” “c:\folderA” “c:\folderB”]]);

— also compare folder X and folder Y
am_execute( bCompare, [[/filters=”-lib\;-*.user” “c:\folderX” “c:\folderY”]]);

The part “/filter=” contains the files you want to filter out, in the first example, the folder(s) “bin\” will be filtered out as well as files with the executable extension, (*.exe).

Finally, the 2 folders are listed one after the other, I suggest that you add quotes around them, especially if they have spaces, (but do it anyway).

Admin or not?

You might not access to all the folders, (for whatever reason), but you might have access as an admin, so, when in doubt, set the admin flag to true, this might help a little.

But it is not generally needed…

am_execute( bCompare, [[/filters=”-lib” “c:\X” “c:\Y”]], true);

String in LUA

A small note about the way I escaped the strings in my example.

normally special characters are ‘escaped’ in LUA, (characters like quotes and so on).

local x = “This is how you do it, \”normally\””

but you can use double square brackets to make your life slightly easier, (and more importantly, easier to read).

local x = [[This is how you do it, “normally”]]

See Lua String for more info.

Finally

Save you file with whatever command you want to call it, for example “compare.lua”, make sure that it has the “.lua” extension.

Move the file to your command folder, ( located in “%appdata%\MyOddWeb\ActionMonitor\RootCommands\” by default).

Reload Piger, (use the command “this.reload”).

And your new command should now appear.

Move MySQL data directory from one folder to another

Moving your MySQL data from one folder to another sounds like a big job, but in reality it is not really.
Before we get started you need to bear a couple of things in mind

  • Be sure to read this entire post before you do anything.
  • Especially read the part about the ‘socket’.
  • Be sure to understand everything that is in the post
  • Some versions of unix/linux use different terminology, (for example to stop/start a service), be sure that you use the correct command.
  • Be sure you are logged in as root.
  • Remember that there will be down time!
    The length of time depends a lot on the size of the data and where you are transferring to/from.
  • Be prepared to roll back the changes if things don’t work!
    • Stop the service.
    • Copy the original my.cnf file, (see below to locate it)
    • Start the service.
  • This is all done at your own risk! If you are not careful you could really trash your data!
  • Read the errors you might get, learn about your system, normally the error should help you solve most issues.
  • Try it on your test/dev server before you do anything, (you have a test server don’t you!!)

Locate the datadir.
This is where MySQL currently has all the data saved, everything is saved in one place.

Run the script, (with phpMyAdmin or something), below and look for the entry that says “datadir”.

# locate the current data directory
SHOW VARIABLES WHERE Variable_Name LIKE “%dir”

Locate the my.cnf.
This is the file that contains the MySQL configuration, this is a very important point and you need to do it carefully.

There could be more than one file so you will need to check all of them!!!

# locate my.cnf, (the very fist line been returned from the cmd below).
# more than one could be given
mysqld –help –verbose

This will return a whole lot of information, but the very first line will contain the locations.

  • Not all the files will exist
  • Maybe _none_ of the files will exist
  • If none exist, create a file called “my.cnf” in the first folder in the list.
  • If any of the files exist, look in any of them for the entry “datadir=…”
    (of course making sure it corresponds to the datadir you located in the previous step.

Stop the MySQL service.
This is a typical case where you need to choose the right command for your repo… do your homework first…

service mysql stop
# or maybe
# /etc/init.d/mysql stop

Copy the data from the old folder to the new folder

# copy the data over, (change the directories).
# rm -rf /home/mysql/*
cp -R -p /var/lib/mysql /home/mysql

You must learn what this means, “cp -R -p” means, copy the data from the source folder to the destination folder, (“/var/lib/mysql” and “/home/mysql” in my case).

But what this also does is keep the permissions of the folder, normally a user “mysql” is created and has full permissions to that folder.

For things to keep working, you must make sure that the permissions remain.

Spend a bit of time making sure that …

  • All the files were copied
  • All the permissions have been kept.

Edit the datadir.
In the my.cnf that you edited/created earlier change, (or add), the datadir.

[mysqld]
datadir=/home/mysql
#innodb_data_home_dir
#innodb_log_group_home_dir=/home/mysql/

  • There could be other values, only edit/add the datadir=, don’t change anything else!
  • In your first step, where you located the directory, look for …
    • innodb_data_home_dir=, if the directory is the same/similar to the one you just moved, then either add an entry or edit the one that is there with the same folder.
    • innodb_log_group_home_dir=, same as above.

Start the MySQL service.

service mysql start
# or maybe
# /etc/init.d/mysql start

Immediately make sure that the server is up and running

mysqladmin status
# or using phpmyadmin# or using whatever tool you fancy…

If it is running ok, make sure that the directories are indeed valid, (same step as earlier).

# locate the current data directory
SHOW VARIABLES WHERE Variable_Name LIKE “%dir”

If the server is not started you might get a ‘socket’ error, in that case, look for where MySQL thinks it is…

SHOW VARIABLES WHERE Variable_name = “socket”

It might point to the old directory, in that case you need to edit the config one more time.

But first stop the service…

service mysql stop
# or maybe
# /etc/init.d/mysql stop

Add two socket section, (one for the client and one for mysql itself)

[client]
# …
socket=/home/mysql/mysql.sock

[mysqld]
# …
socket=/home/mysql/mysql.sock

Of course, in my example, I am using my directory and I am only showing what needs to be edited/added.

Restart the service…

service mysql start
# or maybe
# /etc/init.d/mysql start

And make sure that it is all good!

Delete the old data

If everything is working I would suggest that you back up the old data somewhere else.

To make really sure that all us good, simply rename the old folder, (don’t move it or anything, just rename), and make sure that things are working).

Apache webserver error on startup

I don’t use Apache that often, (not as often as I used to), but when I do I sometime get an error telling me that

(OS 10048)Only one usage of each socket address (protocol/network address/port) is normally permitted. : make_sock: could not bind to address 0.0.0.0:443 no listening sockets available, shutting down Unable to open logs

Now in my case the error was because of skype.exe that was using port 443

But if you need to know who is using it simply open the command line and type

netstat -ano

And, somewhere in the list, you will give see something that is using 0.0.0.0:443, but you will not see the name, you will see the pid, (the process id).

BTW: to get the error message, you can get it via the logs or you can open a command line and run the Apache server manually.

httpd.exe -k start