Skip to content

Instantly share code, notes, and snippets.

View dennisroche's full-sized avatar
🐱

Dennis Roche dennisroche

🐱
View GitHub Profile
@dennisroche
dennisroche / Peek-Cmdlet.ps1
Last active February 22, 2024 19:59
Reflect Powershell CmdLet using Jetbrains DotPeek
function Peek-Cmdlet {
param(
[Management.Automation.CommandInfo]$command
)
if ($input) {
trap { $_; break }
$command = $input | select -first 1
}
@dennisroche
dennisroche / Retry.ps1
Last active August 29, 2015 14:05
Retry Powershell Cmdlet
function Retry {
[CmdletBinding()]
param (
[Parameter(Mandatory=$false)]
[Alias("Attemps")]
[int]$maxAttempts = 3,
[Parameter(Mandatory=$false)]
[Alias("Delay")]
[int]$secondsBeforeRetrying = 5,
@dennisroche
dennisroche / TeamCityBackup.ps1
Last active August 29, 2015 14:11
Backup TeamCity
#TeamCityBackup
#Requires –Version 4
#Requires -RunAsAdministrator
Param
(
[Parameter(Mandatory, HelpMessage="Team City installation directory, e.g. C:\TeamCity")]
[ValidateNotNullOrEmpty()]
[ValidateScript({ Test-Path $_ })]
[String]$TeamCityInstallation = "C:\TeamCity",
@dennisroche
dennisroche / gist:4b7c84756f2556d0b024
Created June 16, 2015 05:04
Attempt at Xamarin Renderer that forces a page to be displayed as Landscape or Portrait. It currently does not work.
public class OrientationNavigationRenderer : NavigationRenderer
{
protected override Task<bool> OnPushAsync(Page page, bool animated)
{
if (page is RequestSignaturePadView)
{
var landscapePage = new ForceLandscapeViewController(page);
PushViewController(landscapePage, animated);
return Task.FromResult(true);
}
@dennisroche
dennisroche / PruneRemoteBranches.sh
Last active March 16, 2016 06:15
Git, Prune Remote Branches that have been merged into origin/master
# Needs to executed in git bash, powershell with posh-git won't work.
# NB, change grep -v master to be the branch you want to check, e.g. grep -v development
# Preview
git fetch -p origin && git branch -r --merged | grep origin | grep -v '>' | grep -v master | xargs -L1 | cut -d"/" -f2- | xargs -d ' '
# Actual
git fetch -p origin && git branch -r --merged | grep origin | grep -v '>' | grep -v master | xargs -L1 | cut -d"/" -f2- | xargs git push origin --delete
@dennisroche
dennisroche / posh-git-helpers.ps1
Last active May 2, 2016 10:15
PoshGit Helpers
# clean remote and local branches
function Git-Prune {
git fetch origin
Write-Host "Pruning remote branches" -ForegroundColor Magenta
git remote prune origin
Write-Host "Pruning local branches that have been merged to master" -ForegroundColor Magenta
git branch --merged $Commit |
? { $_ -notmatch '(^\*)|(^. master$)' } |
% { git branch $(if($Force) { '-D' } else { "-d" }) $_.Substring(2) }
}
@dennisroche
dennisroche / posh-cntlm.ps1
Last active January 30, 2020 15:46
Powershell script that sets your Internet Proxy settings and npm (if found) and auto-restarts Cntlm Authenication Proxy
#Requires -RunAsAdministrator
[CmdletBinding()]
param()
$ErrorActionPreference = "Stop"
trap
{
Pop-Location
Write-Error "$_"
Exit 1
@dennisroche
dennisroche / RunPSAsAdministrator.bat
Created May 3, 2016 01:50
Powershell, Add 'Run As Administrator' to right-click menu
@ECHO OFF
TITLE Enable right-click 'Run as Admin' for PowerShell
ECHO.
ECHO Enabling right-click 'Run as Admin' for PowerShell
ECHO.
:: Add value for UAC shield icon:
REG ADD "HKCR\Microsoft.PowerShellScript.1\Shell\runas" /v HasLUAShield /t REG_SZ /d "" /f
:: Add value to create context menu item:
@dennisroche
dennisroche / MessagingCenterEx.cs
Created May 4, 2016 05:27
Xamarin.Forms type-safe MessagingCenter
using System;
using Xamarin.Forms;
// ReSharper disable CheckNamespace
// Using global:: namespace
public static class MessagingCenterEx
{
private class MessagingCenterSender
{