Skip to content

Instantly share code, notes, and snippets.

View mishrsud's full-sized avatar
🎯
Focusing

Sudhanshu Mishra mishrsud

🎯
Focusing
View GitHub Profile
@mishrsud
mishrsud / docker-commands.sh
Last active April 4, 2025 04:32
Docker attach execute shell command
# PS: If running Linux containers on Windows, the command shell must be running as admin
# Attach to the default shell of a running container
sudo docker attach 665b4a1e17b6
# Access a shell and run custom commands inside a container
# 665b4a1e17b6 is the ID of the container obtained from docker ps
sudo docker exec -i -t 665b4a1e17b6 /bin/bash
[System.Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\Users\mails\AppData\Local\Programs\Python\Python36-32", [System.EnvironmentVariableTarget]::Machine)
Get-ChildItem -Recurse -Depth 3 | where { $_.Name -clike "*Worker.Host.csproj" } | Select-Object
@mishrsud
mishrsud / CsProjUpdater
Created October 22, 2017 11:47
Modify Csproj Programmatically
// Add Refernce to Microsoft.Build.BuildEngine
// SO: https://stackoverflow.com/a/8492560/190476
using Microsoft.Build.BuildEngine;
namespace UpdateVsProjects
{
class Program
{
static void Main(string[] args)
{
# Run this from the directory that contains all project directories underneath
Get-ChildItem -Recurse | where { $_.Name -eq "bin" -or $_.Name -eq "obj" } | Remove-Item -Recurse
# If you really know what you're doing
Get-ChildItem -Recurse | where { $_.Name -eq "bin" -or $_.Name -eq "obj" } | Remove-Item -Recurse -Force
@mishrsud
mishrsud / AccessPropIfNotNull.ts
Created August 27, 2017 09:51
TypeScript: Use generics to access property if object is not null
class Person {
firstname: string;
lastname: string;
constructor(firstname: string, lastname: string) {
this.firstname = firstname;
this.lastname = lastname;
}
}
let p = new Person('Sudhanshu', 'Mishra');
# Source: https://stackoverflow.com/a/3495491/190476
Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -recurse |
Get-ItemProperty -name Version,Release -EA 0 |
Where { $_.PSChildName -match '^(?!S)\p{L}'} |
Select PSChildName, Version, Release, @{
name="Product"
expression={
switch -regex ($_.Release) {
"378389" { [Version]"4.5" }
"378675|378758" { [Version]"4.5.1" }

Summary

This is a collection of most commonly used Regular Expressions. The format is specific to .NET.

Examples

Uses System.Text.RegularExpressions

  • A Number pattern, starting with a specific set of digits
// Will match a numeric string literal starting with 12 or 13 followed by any number of digits

Summary

Makes a PowerShell alias for a command with parameters

Code

Function Git-Status { git status }
New-Alias -Force st Git-Status

Summary

Describes an issue when Cmder is launched that prevents the emulator to run successfully unles run as administrator.

Description

Getting this error when running ConEmu or Cmder:

Failed to backup ConEmu.xml file to ./config folder

Symptoms