January 04, 2021

How to remove all local git branches except master through Powershell

 git branch -D @(git branch --format '%(refname:lstrip=2)' | where {$_ -ne 'master'} )

October 16, 2020

How to remove annoying items from windows explorer context menu

Menu items should be removed from registry.


Share with skype:
Remove HKEY_CLASSES_ROOT\*\shell\Share with skype
Remove HKEY_LOCAL_MACHINE\SOFTWARE\Classes\PackagedCom\Package\Microsoft.SkypeApp(XXXXXXX and so on)\Class\{xxxxxx}
Create a new string key to forbid Skyep to create this menu again HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Blocked\{776DBC8D-7347-478C-8D71-791E12EF49D8}

Move to OneDrive:
Create a new string key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Blocked\{CB3D0F55-BC2C-4C1A-85ED-23ED75B5106B}

October 07, 2020

Deterministic builds for .NET in .csproj

There is a feature to produce equivalent byte output for the same code https://gist.github.com/aelij/b20271f4bd0ab1298e49068b388b54ae

To setup it in csproj file there should be next section:

<PropertyGroup>
  <Deterministic>true</Deterministic>
  <PathMap>$(MSBuildProjectDirectory)=C:\</PathMap>
</PropertyGroup>

August 21, 2020

April 06, 2017

Create and checkout branch in git

git checkout -b new_branch_name

April 05, 2017

Restart machine remotely

shutdown /r /m \\machine.name /d p:4:1 /c "1"

March 13, 2017

How to base your branch on different branch

Nice article describing the process
https://makandracards.com/makandra/10173-git-how-to-rebase-your-feature-branch-from-one-branch-to-another

git checkout feature/mybranch
git rebase --onto new_target_branch current_parent_branch

November 20, 2015

Useful git commands cheat-sheet

git commit --amend -m "New commit message"
git push origin --tags
git push --set-upstream origin name
git branch -u origin/foo - track remote branch
git remote -v - view list of remotes
git remote set-url origin - set remote
git branch -m newname - rename current branch

git push origin master -f - forced push

Rebase branch

git checkout feature/branch
git rebase master
git checkout master
git merge feature/branch // fast-forward here

Cleanup

git branch -D name - delete branch locally
git push origin --delete branchname or git push origin :branchname (:branchname should not exist locally then)git

git tag -d name - delete tag locally
git push origin :refs/tags/name - delete tag remotely

git reset --hard HEAD~1 - one commit back

git remote show origin (shows what is in origin and what is stale)
git remote prune origin (removes all local garbage from repo)
git branch -lvv (view list of branches with remotes and marks if remote gone)
git clean -df (remove all untracked files)
git checkout . (discard all the changes to tracked files)

Code snippet to investigate an object content without dances with debugger in C#

var investigated = ...; // assign your object here
System.IO.File.WriteAllText(
    @"D:\test.json",
    Newtonsoft.Json.JsonConvert.SerializeObject(
        investigated, 
        new Newtonsoft.Json.JsonSerializerSettings
        {
            Formatting = Newtonsoft.Json.Formatting.Indented,
            TypeNameHandling = Newtonsoft.Json.TypeNameHandling.Objects
        }));

November 09, 2015

Rethrow exception and preserve stack trace in.net 4.5

ExceptionDispatchInfo.Capture(myException).Throw();

April 02, 2015

Simplified module loading in powershell

There is a feature for automatic module discorvery in Powershell. It can search for modules based on paths from PsModulePath variable. It is easy to modify it in a script:

$env:PsModulePath += ";$PsScriptRoot/Modules"

Import-Module SomeModule -ArgumentList "foo" -Verbose // no need to specify path to the module

Get-OtherModuleThing // module will be loaded automatically

August 20, 2012

External program execution handling in Powershell

External command handling in Powershell is quite similar to .cmd-files. For example:
svn update
if ($lastexitcode -ne 0) { throw $lastexitcode }

UPD: it is better to use throw in powershell rather than exit