Skip to content

Instantly share code, notes, and snippets.

@onyxhat
onyxhat / Parse-ChocoParams.ps1
Last active July 15, 2016 15:24
Stub for parsing Chocolatey --params string into variables in the chocolateyinstall.ps1/chocolateyuninstall.ps1
#$packageParameters = $env:chocolateyPackageParameters
$packageParameters = "var1 = val1;var2=`"val2 with spaces -`""
$match_pattern = "(?<key>(\w+))\s*=\s*(?<value>([`"'])?([\w- _\\:\.]+)([`"'])?)"
# Now parse the packageParameters using good old regular expression
if ($packageParameters -match $match_pattern ) {
$results = $packageParameters | Select-String $match_pattern -AllMatches
$results.matches | % {
Set-Variable -Name $_.Groups['key'].Value.Trim() -Value $_.Groups['value'].Value.Trim()
}
@onyxhat
onyxhat / win32.go
Last active June 24, 2016 02:55 — forked from nathan-osman/win32.go
Simple Windows GUI application written in Go
package main
import (
"log"
"syscall"
"unsafe"
)
var (
kernel32 = syscall.NewLazyDLL("kernel32.dll")
#! /bin/bash
set -e
#Re-run the script if not using sudo/root
detect_current_uid() {
echo $(id -u)
}
rerun_script_as_root() {
if [ $(detect_current_uid) -ne "0" ]; then
@onyxhat
onyxhat / sh_env_var_opts.sh
Created May 21, 2016 14:20 — forked from KylePDavis/sh_env_var_opts.sh
Simple bash shell script templates. There are two versions: 1) simple env var based options, and 2) with added command line argument parsing and error handling.
#!/bin/bash -e
# A SHORT DESCRIPTION OF YOUR SCRIPT GOES HERE
# USAGE:
# DESCRIPTION OF ENV VARS HERE
###############################################################################
set -e # exit on command errors (so you MUST handle exit codes properly!)
set -o pipefail # capture fail exit codes in piped commands
#set -x # execution tracing debug messages
# Get command info
Import-Module -Name D:\Temp\ACME-posh\ACMEPowerShell.psd1
$domain = "mydomain.com"
$certificiatePassword = "abcd1234"
$email = "[email protected]"
$vault = "D:\Vault\{0}\{1}" -f $domain, [guid]::NewGuid()
mkdir $vault
cd $vault
Initialize-ACMEVault -BaseURI https://acme-v01.api.letsencrypt.org/
New-ACMERegistration -Contacts mailto:$email
param ([string]$SrcDBInstance, [string]$DestDBInstance, [string]$DBName)
#Functions
function Exec-Query ([string]$DBServer,[string]$DBName,[string]$Query) {
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Server=$DBServer;Database=$DBName;Integrated Security=True"
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandTimeout = 0
$SqlCmd.CommandText = $Query
$SqlCmd.Connection = $SqlConnection
$Host.UI.RawUI.WindowTitle = "-=Windows Update=-"
$Script = $MyInvocation.MyCommand.Definition
Write-Host -NoNewline "Checking for Updates..."
$UpdateSession = New-Object -Com Microsoft.Update.Session
$UpdateSearcher = $UpdateSession.CreateUpdateSearcher()
$SearchResult = $UpdateSearcher.Search("IsInstalled=0 and Type='Software'")
For ($X = 0; $X -lt $SearchResult.Updates.Count; $X++) {
$Update = $SearchResult.Updates.Item($X)