Skip to content

Instantly share code, notes, and snippets.

@johnallers
johnallers / Update-WSL2-IP-In-Hosts.ps1
Created December 23, 2021 18:56
Sets wsl2.local in HOSTS file to current WSL2 IP
$wsl2IP = (wsl hostname -I).Split(" ")[0]
Write-Host "Setting wsl2.local IP to the WSL2 IP ($wsl2IP)"
$hostsPath = "$env:windir\System32\drivers\etc\hosts"
$dockerHostsPattern = '^((\d{1,3}\.){3}\d{1,3}) wsl2\.local$'
$hosts = get-content $hostsPath
$hosts = $hosts | Foreach {
if ($_ -match $dockerHostsPattern)
{
$oldIP = $Matches.1
@johnallers
johnallers / jira-copy-story-summary.js
Last active November 13, 2020 22:05 — forked from codycraven/jira-copy-story-summary.js
TamperMonkey Jira Copy Story Summary
// ==UserScript==
// @name Jira copy story summary
// @namespace https://cravencode.com/
// @version 0.1
// @description Copies summary, issue link, and people associated with story to clipboard
// @match https://*.atlassian.net/*
// @copyright 2019, Cody Craven
// ==/UserScript==
(function(d) {
@johnallers
johnallers / Clean-GitLocalMerged.ps1
Created June 8, 2020 21:08
PowerShell functions for finding and removing local branches that have been merged
function Find-GitLocalMerged {
Write-Host "git branch --merged | %{$_.trim()} | ?{$_ -notmatch 'develop' -and $_ -notmatch 'master'}}"
& git branch --merged | %{$_.trim()} | ?{$_ -notmatch 'develop' -and $_ -notmatch 'master'}
}
function Clean-GitLocalMerged {
Write-Host "git branch --merged | %{$_.trim()} | ?{$_ -notmatch 'develop' -and $_ -notmatch 'master'} | %{git branch -d $_}"
& git branch --merged | %{$_.trim()} | ?{$_ -notmatch 'develop' -and $_ -notmatch 'master'} | %{git branch -d $_}
}
@johnallers
johnallers / Reset-Git.ps1
Created June 8, 2020 21:07
PowerShell function to fetch a repo and reset the current branch to the latest
function Reset-Git {
$target = ''
if ($args){
$target = "origin/$args"
}
else {
$current = (&git rev-parse --abbrev-ref HEAD)
$target = "origin/$current"
}
@johnallers
johnallers / Liberal Regex Pattern for Web URLs
Created April 24, 2019 13:04 — forked from gruber/Liberal Regex Pattern for Web URLs
Liberal, Accurate Regex Pattern for Matching Web URLs
The regex patterns in this gist are intended only to match web URLs -- http,
https, and naked domains like "example.com". For a pattern that attempts to
match all URLs, regardless of protocol, see: https://gist.github.com/gruber/249502
# Single-line version:
(?i)\b((?:https?:(?:/{1,3}|[a-z0-9%])|[a-z0-9.\-]+[.](?:com|net|org|edu|gov|mil|aero|asia|biz|cat|coop|info|int|jobs|mobi|museum|name|post|pro|tel|travel|xxx|ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cs|cu|cv|cx|cy|cz|dd|de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|s
// https://tools.ietf.org/html/rfc4648#section-5
public class Base64Url
{
public static string Encode(byte[] inArray)
{
var base64 = Convert.ToBase64String(inArray);
return base64
.Replace("+", "-")
.Replace("/", "_")
.Replace("=", "");
@johnallers
johnallers / watch-and-copy.cs
Last active November 15, 2018 21:09
Watch temp folder and make a copy of created files
class Program
{
static void Main()
{
const string COPIED_EXTENSION = ".copy";
var cts = new CancellationTokenSource();
Console.CancelKeyPress += (sender, args) =>
{
@johnallers
johnallers / main.cpp
Last active October 31, 2018 13:25
Test basic CNG API methods
#include <stdio.h>
#include <Windows.h>
#include <ncrypt.h>
#ifndef NT_SUCCESS
#define NT_SUCCESS(Status) ((NTSTATUS)(Status) >= 0)
#endif
#define CAVIUM_KEYSTORE_PROVIDER L"Cavium Key Storage Provider"
#define MS_KEY_STORAGE_PROVIDER L"Microsoft Software Key Storage Provider"
$Path = $env:TEMP; $Installer = "firefox_installer.exe"; Invoke-WebRequest "https://download.mozilla.org/?product=firefox-latest&os=win64&lang=en-US" -OutFile $Path$Installer; Start-Process -FilePath $Path$Installer -Args "/S" -Verb RunAs -Wait; Remove-Item $Path$Installer
@johnallers
johnallers / Install-Chrome.ps1
Last active October 5, 2018 15:13 — forked from kurokikaze/gist:350fe1713591641b3b42
install chrome from powershell
$Path = $env:TEMP; $Installer = "chrome_installer.exe"; Invoke-WebRequest "https://dl.google.com/chrome/install/latest/chrome_installer.exe" -OutFile $Path$Installer; Start-Process -FilePath $Path$Installer -Args "/silent /install" -Verb RunAs -Wait; Remove-Item $Path$Installer