Skip to content

Instantly share code, notes, and snippets.

@ezr
ezr / cheat.py
Created Dec 3, 2021
Print out a cheat sheet, falls back to tldr pages
View cheat.py
#!/usr/bin/env python3
# depends on:
# https://github.com/sharkdp/bat
# https://github.com/tldr-pages/tldr
from glob import glob
from os import listdir, environ
import subprocess
from sys import argv
@ezr
ezr / zip-args.py
Created Nov 18, 2021
takes lists and merges them into columns
View zip-args.py
#!/usr/bin/env python3
import argparse
from sys import argv, stderr
parser = argparse.ArgumentParser(description='zip together lists')
parser.add_argument("-s", "--separator", default=" ", help='character to separate items', required=False)
parser.add_argument("lists", nargs="+")
args = parser.parse_args()
@ezr
ezr / portchecker.go
Created Oct 12, 2021
Google cloud function to scan a given IP/TCP port.
View portchecker.go
package portchecker
/* A Google cloud function that takes an address and a TCP port.
It scans the port and tells you whether its open or not.
If "addr" is not supplied, then it scan the requestor.
Example usage:
$ curl --header "Api-Key: $API_KEY" --data "port=443&addr=142.250.65.174" https://us-region-projectname.cloudfunctions.net/portchecker
*/
@ezr
ezr / printf-loop.sh
Created Sep 22, 2021
Print the supplied format once for each line of stdin
View printf-loop.sh
#!/usr/bin/env bash
USAGE=$(cat <<-END
Error: no argument supplied.
This program prints the template once for each line of stdin. It only substitutes one variable in the printf format string.
Usage:
$0 <printf_format> < data
@ezr
ezr / textsub.py
Created Sep 21, 2021
Print the supplied template once for each line of stdin
View textsub.py
#!/usr/bin/env python
import sys
if len(sys.argv) == 1:
text = "{text}"
message = '''\
Error: no argument supplied.
This program prints the template once for each line of stdin. {text} in the template is replaced with the line from stdin.
View append-at.py
#!/usr/bin/env python3
# argv[1] is the path to a configuration file
# the config file is a CSV file of the form date,path,message. EG:
# 03-03-2022,/home/user/py/remind/f,remember to do a backup
# 10-22-2021,/home/user/.motd,get tickets for Dune
from datetime import datetime
import os
import re
@ezr
ezr / duplicates.go
Last active Aug 22, 2021
find duplicate files in the current directory
View duplicates.go
package main
import (
"crypto/md5"
"encoding/hex"
"fmt"
"io"
"io/ioutil"
"log"
"os"
@ezr
ezr / tcping.go
Created Aug 10, 2021
Test connecting to a given tcp port. Can specify source address
View tcping.go
package main
import (
"fmt"
"log"
"net"
"os"
"strconv"
"strings"
"time"
@ezr
ezr / sshlurp.go
Created Jul 5, 2021
A fake ssh server that logs usernames/passwords that get submitted
View sshlurp.go
// A fake SSH server that logs passwords
// tweaked from https://gist.github.com/jpillora/b480fde82bff51a06238
//
// # generate server keypair with
// ssh-keygen -t rsa
// the server expects to find id_rsa in the PWD
package main
import (
@ezr
ezr / changedns.py
Created Jun 7, 2021
A script to change DNS servers when using systemd-resolved
View changedns.py
#!/usr/bin/env python3
from os import listdir
from pydbus import SystemBus
import socket
nics = listdir("/sys/class/net/")
nics.remove("lo")
for idx, nic in enumerate(nics):