Skip to content

Instantly share code, notes, and snippets.

View ashafer01's full-sized avatar
🤓
1.3.6.1.4.1.53450

Alex Shafer ashafer01

🤓
1.3.6.1.4.1.53450
  • San Francisco, CA
View GitHub Profile
@ashafer01
ashafer01 / yaml-json.txt
Last active October 1, 2023 15:36
python single-expression shell aliases to convert between yaml and json. accepts optional filename argument, defaults to stdin
macbook:~ % which yaml-to-json
yaml-to-json: aliased to python3 -c 'print(__import__("json").dumps(__import__("yaml").safe_load(open([*__import__("sys").argv[1:],"/dev/stdin"][0]).read()),indent=" "))'
macbook:~ % which json-to-yaml
json-to-yaml: aliased to python3 -c 'print(__import__("yaml").dump(__import__("json").load(open([*__import__("sys").argv[1:],"/dev/stdin"][0]))),end="")'
@ashafer01
ashafer01 / adb-backup-extract-one-line.sh
Last active June 4, 2022 22:03
Stream adb backup output all the way to tar in one line
#!/bin/bash
# Requires linux or macos
#
# On macos, I used a random open source zlib-uncompress tool that reads stdin and writes stdout only:
# brew install go
# go install github.com/odeke-em/zlib-cli/cmd/zlib-uncompress@latest
# And add $HOME/go/bin to my PATH (or add to the command)
#
# This will take adb backup output and stream it all the way to tar with verbose output
@ashafer01
ashafer01 / get-remote-cert.py
Last active September 10, 2020 20:43
Runs `openssl s_client -showcerts` to obtain the certificate chain being presented by a remote server
#!/usr/bin/env python3
"""
Usage: get-remote-cert.py <host:port> [cert index]
Runs `openssl s_client -showcerts` to obtain the certificate chain being
presented by a remote server.
The default behavior (with cert index omitted) is to print all of the certificates
found in the s_client output to stdout. Any stderr output from s_client will be
printed seperately to stderr.
@ashafer01
ashafer01 / async_rsync_progress.py
Created August 22, 2020 16:18
Run an rsync as an asyncio subprocess and stream the progress output
"""Demo for streaming rsync progress from a subprocess with asyncio
Before running:
dd if=/dev/zero of=./1000mb.bin bs=$((1024 ** 2)) count=1000
mkdir tmp
"""
import asyncio
from subprocess import PIPE
@ashafer01
ashafer01 / ghe_mirror.sh
Last active August 12, 2019 19:30
Mirror all of your accessible repos locally from github enterprise
#!/bin/bash
## Create or update a local mirror of all of your accessible repos on a GitHub Enterprise server
## Operates within the working directory
## Sets up a host/org/repo directory structure similar to Go
## Requires command line utilities: curl, jq, git
## Token available at https://github.YOUR-ENTERPRISE.com/settings/tokens
## Appears to need: repo (Full control of private repositories) permission, and read:org (Read org and team membership) permission
@ashafer01
ashafer01 / digitalocean_dynamic_dns.py
Last active July 2, 2019 07:42
Use the Digital Ocean DNS API to implement dynamic DNS
#!/usr/bin/env python3
## Setup:
## 0. See if you have a better way than the default below to find your WAN IP
## 1. Create the record using the control panel manually, set ttl to 30 or 60, set to dummy IP
## 2. Create an API token specific to this application
## 3. pip/pip3 install requests
## 4. Update the variables below and add cron job
# config
base = 'https://api.digitalocean.com/v2'
@ashafer01
ashafer01 / mail_relay.py
Last active February 2, 2024 04:16
Drop-in replacement for sendmail -t which relays to gmail smtp, should be easy to adapt to any smtp
#!/usr/bin/env python3
import email
import smtplib
import sys
smtp_address = "smtp.gmail.com"
smtp_port = 587
smtp_user_name = "YOUR_EMAIL@gmail.com"
smtp_password = "YOUR_APP_PASSWORD"
@ashafer01
ashafer01 / ad_sudo_schema.ldif
Created February 9, 2019 00:09
Active Directory Schema for sudo ldap - tested working with AWS Directory Service - replace DC=EXAMPLE,DC=COM with your domain
dn: CN=SudoUser,CN=Schema,CN=Configuration,DC=EXAMPLE,DC=COM
changetype: add
objectCategory: CN=Attribute-Schema,CN=Schema,CN=Configuration,DC=EXAMPLE,DC=COM
objectClass: attributeSchema
objectClass: top
cn: SudoUser
attributeID: 1.3.6.1.4.1.15953.9.1.1
attributeSyntax: 2.5.5.12
isSingleValued: FALSE
lDAPDisplayName: sudoUser
@ashafer01
ashafer01 / formatter.py
Created January 17, 2019 17:22
Python custom string.Formatter example
import string
class MyForm(string.Formatter):
def parse(self, format_string):
for tpl in string.Formatter.parse(self, format_string):
print(tpl)
literal_text, field_name, format_spec, conversion = tpl
if field_name:
literal_text += f'"{field_name}"'
yield literal_text, None, None, None
@ashafer01
ashafer01 / userContent.css
Created November 25, 2018 18:23
Vertically and horizontally center the content on firefox about:home after customizing the content in preferences
/* @-moz-document (about:home) DOES NOT WORK :(
use this heuristic selector applied to all pages instead */
html > body.activity-stream > div#root > div[data-reactroot] > div.outer-wrapper > main {
/* force-center the content based on computed values for
MacBook Retina 12" Early 2016 2304x1400 */
position: absolute;
left: calc((100% - 1042px)/2);
top: calc((100% - 566px)/2);
}