Skip to content

Instantly share code, notes, and snippets.

View chrisdpa-tvx's full-sized avatar

Chris Atkinson chrisdpa-tvx

View GitHub Profile
@chrisdpa-tvx
chrisdpa-tvx / install_java.ps1
Last active June 1, 2021 18:00
Install Java JRE on windows silently using powershell
$URL=(Invoke-WebRequest -UseBasicParsing https://www.java.com/en/download/manual.jsp).Content | %{[regex]::matches($_, '(?:<a title="Download Java software for Windows Online" href=")(.*)(?:">)').Groups[1].Value}
Invoke-WebRequest -UseBasicParsing -OutFile jre8.exe $URL
Start-Process .\jre8.exe '/s REBOOT=0 SPONSORS=0 AUTO_UPDATE=0' -wait
echo $?
@chrisdpa-tvx
chrisdpa-tvx / entropy.py
Last active July 16, 2018 15:01
Hide high entropy strings
#!/usr/bin/python -u
import math
import sys
def entropy(string):
prob = [float(string.count(c)) / len(string) for c in dict.fromkeys(list(string))]
return - sum([p * math.log(p) / math.log(2.0) for p in prob])
@chrisdpa-tvx
chrisdpa-tvx / capybara cheat sheet
Last active June 28, 2018 08:42 — forked from zhengjia/capybara cheat sheet
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@chrisdpa-tvx
chrisdpa-tvx / Unix to powershell Cheatsheet.rst
Last active October 10, 2018 15:45
Cross over commands for those forced to use powershell

Recursive Grep

unix:

grep -R 'bruce'

Powershell

@chrisdpa-tvx
chrisdpa-tvx / python_update.rst
Last active April 19, 2018 08:04
Updating Python 2.7 to use TLS1.2

Updating python to use TLS1.2 is now required (this is the problem the guys in devops encountered) and here is how to do it.

If you are using virtualenv you’ll need to deactivate it:

deactivate

then use brew to install the latest version of python and openssl:

brew install python@2
@chrisdpa-tvx
chrisdpa-tvx / Resize-PartitionMax.ps1
Created March 27, 2018 11:10
AWS Resize a windows volume
Resize-Partition -DiskNumber 3 -PartitionNumber 2 -Size $((get-disk -Number 3 | Get-PartitionSupportedSize -PartitionNumber 2).sizemax)
@chrisdpa-tvx
chrisdpa-tvx / sendmail.py
Created March 12, 2018 15:04
Send Mail using docker as a relay
#!/usr/bin/env python3
# Start a mail relay using docker:
#
# docker run -p 25:25 namshi/smtp
#
import smtplib
from email.message import EmailMessage
from email.headerregistry import Address
@chrisdpa-tvx
chrisdpa-tvx / remove_volumes.sh
Last active October 18, 2017 15:19
Remove unattached volumes
# Remove any volumes that are not attached to an AWS instance
aws ec2 describe-volumes | \
jq -r '.Volumes[] | select( (.Attachments|length)==0 ) | .VolumeId ' | \
xargs -J % -n 1 aws ec2 delete-volume --volume-id %
# Remove DB snapshots that are older than a month
aws rds describe-db-snapshots | \
jq -r ".DBSnapshots[] | select( (.SnapshotCreateTime<\"$(date -v-1m -u +%Y-%m-%dT%H:%M:%S.000Z)\") and (.SnapshotType==\"manual\")) | .DBSnapshotIdentifier" | \
xargs -J % -n 1 sts aws rds delete-db-snapshot --db-snapshot-identifier %
@chrisdpa-tvx
chrisdpa-tvx / userdata.rst
Last active October 25, 2018 12:53
AWS userdata/boot debuggin

Run command lives here:

/var/lib/cloud/instance/scripts/runcmd

Config is in:

/var/lib/cloud/instance/cloud-config.txt

Check (powershell):

@chrisdpa-tvx
chrisdpa-tvx / kms encrypt-decrypt of text or file
Last active September 14, 2017 11:09
Encrypt a file using KMS keys
aws kms create-key
# Encrypt the contents of the file
aws kms encrypt \
--key-id ${key_id_from_create_key_step} \
--plaintext fileb://super_secret_file \
--output text \
--query CiphertextBlob > super_secret_file.enc.b64
# Decrypt the contents of the file