Skip to content

Instantly share code, notes, and snippets.

View Geogboe's full-sized avatar

geogboe Geogboe

View GitHub Profile
@Geogboe
Geogboe / vscode-snippet-copy-paste.ps1
Last active January 5, 2021 17:05
vscode-snippet-copy-paste - Convert Code Block to VSCode Snippet
# 2021 - George Bowen
# Usage:
# Add this to your vscode powershell profile "code $profile",
# then, select any text in your editor, type alt+shift+s, select Convert Code Block to Snippet,
# which will return a json code block for you to add to your vscode snippets file
function ConvertTo-JsonCodeBlock {
<#
.SYNOPSIS
@KROSF
KROSF / taskfile.schema.json
Created October 24, 2020 12:58
Taskfile YAML Schema
{
"$schema": "http://json-schema.org/draft-07/schema",
"description": "Taskfile YAML Schema",
"oneOf": [
{
"type": "object",
"properties": {
"version": {
"description": "Specify the Taskfile format that this file conforms to.",
"anyOf": [
@HighwayofLife
HighwayofLife / cloud_init.yaml
Last active August 1, 2024 20:25
Install Docker via Cloud Init on Ubuntu VM
#cloud-config
packages:
- apt-transport-https
- ca-certificates
- curl
- gnupg-agent
- software-properties-common
# Enable ipv4 forwarding, required on CIS hardened machines
@jerblack
jerblack / Elevate when needed in Go.md
Last active May 19, 2024 09:08
Relaunch Windows Golang program with UAC elevation when admin rights needed.

I'm buiding a command line tool in Go that has an option to install itself as a service on Windows, which it needs admin rights for. I wanted to be able to have it reliably detect if it was running as admin already and if not, relaunch itself as admin. When the user runs the tool with the specific switch to trigger this functionality (-install or -uninstall in my case) they are prompted by UAC (User Account Control) to run the program as admin, which allows the tool to relaunch itself with the necessary rights.

To detect if I was admin, I tried the method described here first:
https://coolaj86.com/articles/golang-and-windows-and-admins-oh-my/
This wasn't accurately detecting that I was elevated, and was reporting that I was not elevated even when running the tool in CMD prompt started with "Run as Administrator" so I needed a more reliable method.

I didn't want to try writing to an Admin protected area of the filesystem or registry because Windows has the ability to transparently virtualize those writes

@ju2wheels
ju2wheels / my_action_plugin.py
Created February 9, 2018 15:09
Ansible 2.4 Action Plugin Template
# For a high level over see video at https://www.ansible.com/blog/how-to-extend-ansible-through-plugins
# Standard base includes and define this as a metaclass of type
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
# Important contants
from ansible import constants as C
# Common error handlers
from ansible.errors import AnsibleError
@MyITGuy
MyITGuy / Get-MsiProducts.ps1
Last active October 4, 2024 15:12
PowerShell: Get-MsiProducts / Get Windows Installer Products
function Get-MsiProducts {
[CmdletBinding()]
param()
function ConvertFrom-PackedGuid {
<#
.SYNOPSIS
Converts a packed globally unique identifier (GUID) string into a GUID string.
.DESCRIPTION
Takes a packed GUID string and breaks it into 6 parts. It then loops through the first five parts and reversing the order. It loops through the sixth part and reversing the order of every 2 characters. It then joins the parts back together and returns a GUID.
@Jaykul
Jaykul / PoshStep.psm1
Created January 26, 2017 06:35
Invoke-Step with dependencies
class DependsOn : System.Attribute {
[string[]]$Name
DependsOn([string[]]$name) {
$this.Name = $name
}
}
function Invoke-Step {
@mihow
mihow / load_dotenv.sh
Last active October 22, 2024 08:26
Load environment variables from dotenv / .env file in Bash
# The initial version
if [ ! -f .env ]
then
export $(cat .env | xargs)
fi
# My favorite from the comments. Thanks @richarddewit & others!
set -a && source .env && set +a
Import-Module -Name Lability
$hotfixes = @(
#region Normal Patches
@{
Id = 'windows8.1-kb2939087-x64_76a6b26de1edc9114c11e3da7394dfbcabe4afd8.cab'
Uri = 'http://download.windowsupdate.com/d/msdownload/update/software/crup/2014/03/windows8.1-kb2939087-x64_76a6b26de1edc9114c11e3da7394dfbcabe4afd8.cab'
},
@{
Id = 'windows8.1-kb2954879-v2-x64_7e2146477888153e6308977bfc2bc14fea2f56b9.cab'
@andreicristianpetcu
andreicristianpetcu / ansible-summary.md
Created May 30, 2016 19:25
This is an ANSIBLE Cheat Sheet from Jon Warbrick

An Ansible summary

Jon Warbrick, July 2014, V3.2 (for Ansible 1.7)

Configuration file

intro_configuration.html

First one found from of