Skip to content

Instantly share code, notes, and snippets.

@johnallers
johnallers / gist:1674845
Created January 25, 2012 05:06
Demonstration of the C# compiler using duck typing for the foreach keyword.
namespace Samples
{
using System;
using System.Collections.Generic;
public class CustomEnumerableDemoConsole
{
public static void Main(params string[] args)
{
CustomEnumerable enumerable = new CustomEnumerable("One", "Two", "Three");
@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 / SlackHotkeys.ahk
Last active June 29, 2021 10:19
AutoHotKey script for changing Slack status
:://call::
SendInput, /status :phone: Call{enter}
Return
:://clear::
SendInput, /status clear{enter}
Return
:://wfh::
SendInput, /status :house_with_garden: Working From Home{enter}
@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 / FindAssemblyVersionConflicts.cs
Last active July 28, 2020 14:57
FindAssemblyVersionConflicts
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
namespace FindAssemblyVersionConflicts
{
class Program
{
@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"
}
#Run this every 1/2 hour and in an 8 hour work day there will be approximately 3 times per day that your victim hears a cat fact
if ((Get-Random -Maximum 10000) -lt 1875) {
Add-Type -AssemblyName System.Speech
$SpeechSynth = New-Object System.Speech.Synthesis.SpeechSynthesizer
$CatFact = (ConvertFrom-Json (Invoke-WebRequest -Uri 'http://catfacts-api.appspot.com/api/facts')).facts
$SpeechSynth.Speak("did you know?")
$SpeechSynth.Speak($CatFact)
}
@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("=", "");