unix:
grep -R 'bruce'
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 $? |
#!/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]) | |
=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') |
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
Resize-Partition -DiskNumber 3 -PartitionNumber 2 -Size $((get-disk -Number 3 | Get-PartitionSupportedSize -PartitionNumber 2).sizemax) |
#!/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 |
# 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 % |
Run command lives here:
/var/lib/cloud/instance/scripts/runcmd
Config is in:
/var/lib/cloud/instance/cloud-config.txt
Check (powershell):
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 |