Skip to content

Instantly share code, notes, and snippets.

@GeoffWilliams
GeoffWilliams / test_socket.py
Created October 16, 2022 21:55
test_socket.py
#!/usr/bin/env python3
import socket
import sys
s = socket.socket()
if len(sys.argv) != 3:
print(f"usage: {sys.argv[0]} HOSTNAME PORT")
sys.exit(1)
address = sys.argv[1]
DO
$$BEGIN
IF EXISTS (SELECT FROM pg_roles WHERE rolname = 'my_user') THEN
EXECUTE 'ALTER USER...';
ELSE
EXECUTE 'CREATE USER...';
END IF;
END$$;
@GeoffWilliams
GeoffWilliams / artifactory_download_size.py
Last active July 17, 2021 05:19
Quick and dirty python script to output human readable artifact names for large downloads
#!/usr/bin/env python
"""artifactory download size
Usage:
artifactory_download_size.py <filename>
artifactory_download_size.py (-h | --help)
Options:
-h --help Show this screen
"""
@GeoffWilliams
GeoffWilliams / boxcutter-windows-vmware15.patch
Created March 5, 2020 05:42
Support building eval copy of windows10 for vmware 15 - using upstream the virus checker usually fails the build and the virtual hardware is too old to work properly (get unknown error from vagrant, cannot power on error from vmware)
diff --git a/eval-win10x64-enterprise.json b/eval-win10x64-enterprise.json
index 6ec43db..d33e59c 100644
--- a/eval-win10x64-enterprise.json
+++ b/eval-win10x64-enterprise.json
@@ -186,10 +186,10 @@
"vm_suffix": "",
"cm": "chef",
"cm_version": "",
- "cpus": "2",
- "memory": "2048",
@GeoffWilliams
GeoffWilliams / ssm.yml
Created December 23, 2019 02:23
ansible playbook to install aws ssm on debian
---
- name: install ssm
hosts: all
tasks:
- name: script
shell: >
wget https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/debian_amd64/amazon-ssm-agent.deb &&
sudo dpkg -i amazon-ssm-agent.deb &&
sudo systemctl enable amazon-ssm-agent
@GeoffWilliams
GeoffWilliams / pydiskcomp.py
Created September 21, 2019 03:06
Compare disk images block-by-block, print out index of sectors with changes and save the different blocks to file
import os
afile = "sdcard.img"
bfile = "sdcard.img.manualworks"
afilediff = "sdcard.img.diff"
bfilediff = "sdcard.img.manualworks.diff"
afile_size = os.path.getsize(afile)
bfile_size = os.path.getsize(bfile)
@GeoffWilliams
GeoffWilliams / soy_examples.soy
Last active August 12, 2019 04:02
atlassian soy examples
/**
* @param? config
* @param? errors
* The annotations are essential to inject $config and $errors!
* If you don't use a doc-string variable you injected... Whole form crashes until you remove it!
* Browsers cache compiled soy.. clear cache and reload if its not updating!
*/
{template .view}
</h1>This is just a brain dump</h1>
@GeoffWilliams
GeoffWilliams / awkfoo.sh
Created June 4, 2019 11:27
read some stuff in and use awk to selectively edit inline and normalise spaces
awk '
{if ($0 ~ /^GRUB_CMDLINE_LINUX=/) {gsub("transparent_hugepage=[[:alnum:]]*[[:space:]]?", "", $0) ; gsub("[[:space:]]?\"$", " transparent_hugepage=never\""); print $0 } else {print}}
' < brett.txt
@GeoffWilliams
GeoffWilliams / puppet_node_purge.rb
Created May 13, 2019 06:21
Example of how to purge PE nodes using ruby. This is not usuable code but its a good example - the `puppet-ca` API is only accessable via whitelist and needs an SSL cert too. By the time you've organised this you could have just run `puppet node purge` on the master...
require 'excon'
require 'json'
module PuppetNodePurge
def self.setup()
@@ssldir = '/etc/puppetlabs/puppet/ssl'
@@fqdn = %x(facter fqdn).strip.downcase
end
def self.get_conf()
conf = {
@GeoffWilliams
GeoffWilliams / puppet_metadata2Puppetfile-git.sh
Created April 8, 2019 02:15
find all metadata .json files relative to current directory and convert them into `Puppetfile` format suitable for git checkouts
find . -iname 'metadata.json' -exec jq '"mod " + (.name | split("-"))[1] + ", :git => " + .source + ", :tag => " + .version' {} \;