Skip to content

Instantly share code, notes, and snippets.

View bender-the-greatest's full-sized avatar

bender-the-greatest

  • CSG International
  • Omaha, NE
View GitHub Profile
@bender-the-greatest
bender-the-greatest / watch-function.ps1
Last active October 21, 2016 15:13
Rudimentary implementation of *nix watch command for Powershell
# Rudimentary implementation of *nix watch command for Powershell
# Tested under 2.0 and 5.1
# Example usage:
# watch ls
# watch 'echo "Command with parameters"'
# watch -n 1 'echo "Display this every second"'
# watch -n 1 -command 'echo "Explicit use of the command parameter"'
function watch {
Param(
@bender-the-greatest
bender-the-greatest / format-json-function.ps1
Created December 5, 2016 20:18
Format-Json Function, allowing to specify the indent level.
function Format-Json {
Param(
[Parameter(ValueFromPipeline=$True,Mandatory=$True)]
[string]$jsondata,
[int]$indent=2
)
# Processing blocks are useful for multiline JSON strings
begin { $fullpipeline = "" }
process { $fullpipeline += $jsondata }
end {
@bender-the-greatest
bender-the-greatest / Convert-MultilineToSingleLine.ps1
Created December 27, 2016 15:40
Powershell function to convert a multiline string to a single line string with line break characters
# Powershell function to convert a multiline string to a single line string with line break characters
#
# Example usage:
# # Replace line breaks with \r\n (Windows-style line endings)
# cat 'nginx.cer' | Convert-MultilineToSingleLine
# # Replace line breaks with \n (Unix/Linux-style line endings)
# cat 'nginx.cer' | Convert-MultilineToSingleLine -n
function Convert-MultilineToSingleLine {
Param(
@bender-the-greatest
bender-the-greatest / time-function.ps1
Last active November 4, 2022 11:54
Alternative implementation of Measure-Command, works similarly to Linux `time` command
# Alternative (improved?) implementation of Measure-Command
# Works similarly to the Linux/Unix `time` command
#
# Function which times how long a command takes to completion
# Note that this function outputs to Write-Host so as to
# protect the proper return value. Note that a time will be
# returned even if the command fails.
#
# Unless `-quiet` is specified, command output is sent directly
# to `Write-Host` to allow for the simultaneous return of the
@bender-the-greatest
bender-the-greatest / install-and-import.ps1
Created January 3, 2017 03:55
Installs modules if they are missing prior to import
# Installs modules if they are missing prior to importing
# Does not upgrade modules, only installs them if they are missing
#
# Example usage:
# install-and-import pscx
function install-and-import {
Param(
[Parameter(Mandatory=$true)]
[string]$moduleName
#Requires -Version 5.1
# This is more of a backup of my profile but if you like it use it I guess.
# Some of the custom functions I have sourced on Github as gists, which are
# commented and documented, unlike these here.
function install-and-import {
Param(
[Parameter(Mandatory=$true)]
[string]$moduleName,
[string]$Scope = 'CurrentUser'
@bender-the-greatest
bender-the-greatest / conemu.ahk
Last active January 5, 2017 05:48
Autohotkey script for ConEmu
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir C:\Projects ; Ensures a consistent starting directory.
^!t::GoSub, FocusOrStartConEmu
;; This will probably not act as intended if you have more than one ConEmu64 process running
FocusOrStartConemu:
if WinExist("ahk_exe ConEmu64.exe")
@bender-the-greatest
bender-the-greatest / mousemap.ahk
Created January 5, 2017 04:07
AutoHotKey script for mouse button emulation
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
; Right clicks
^LButton::RButton
; Middle clicks
^+LButton::MButton
@bender-the-greatest
bender-the-greatest / open-containingfolder.ps1
Created January 5, 2017 05:47
Powershell function which opens the containing folder of a given file
# Powershell function which opens the containing folder of a given file
# in the default program (this will be Windows Explorer 99% of the time).
#
# Note that if -File is actually a folder, it will open that folder's
# parent folder.
#
# Usage:
# Open-ContainingFolder $env:AppData
# Open-ContainingFolder .\somefile.txt
# Open-ContainingFolder C:\Windows\System32\ping.exe
<!--
Mostly this contains custom keybindings, theme, and enables Quake style sliding
-->
<?xml version="1.0" encoding="utf-8"?>
<key name="Software">
<key name="ConEmu">
<key name=".Vanilla" modified="2017-01-05 20:41:54" build="161206">
<value name="StartType" type="hex" data="02"/>
<value name="CmdLine" type="string" data=""/>
<value name="StartTasksFile" type="string" data=""/>