Skip to content

Instantly share code, notes, and snippets.

View rsperl's full-sized avatar

Richard rsperl

  • North Carolina, United States
View GitHub Profile
@rsperl
rsperl / Makefile #snippet
Last active April 17, 2024 23:02
self-documenting makefile with colors
SHELL=/bin/bash
# to see all colors, run
# bash -c 'for c in {0..255}; do tput setaf $c; tput setaf $c | cat -v; echo =$c; done'
# the first 15 entries are the 8-bit colors
# define standard colors
ifneq (,$(findstring xterm,${TERM}))
BLACK := $(shell tput -Txterm setaf 0)
RED := $(shell tput -Txterm setaf 1)
@rsperl
rsperl / nmap_examples.md
Last active February 16, 2024 02:13
nmap examples #snippet
@rsperl
rsperl / set_default_browser.py
Last active May 5, 2023 10:43
set default browser on macos from command line #snippet
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# with help from https://gist.github.com/miketaylr/5969656
import sys
try:
from LaunchServices import (
LSSetDefaultHandlerForURLScheme,
@rsperl
rsperl / bash_template.sh
Last active February 2, 2023 02:46
bash script templates #shell #template #snippet
#!/bin/bash
# see also
# - Google's Shell Style Guide: https://google.github.io/styleguide/shell.xml
# - ShellCheck: https://github.com/koalaman/shellcheck
# src:
# - http://hackaday.com/2017/07/21/linux-fu-better-bash-scripting
# - https://dev.to/thiht/shell-scripts-matter
@rsperl
rsperl / read_excel_with_panda.py
Last active January 31, 2023 15:10
Reading excel files with python and panda #snippet
#!/usr/bin/env python
# src: http://pandas.pydata.org/pandas-docs/stable/io.html#io-excel-reader
import pandas as pd
# get a dataframe from xlsx object
xlsx = pd.ExcelFile('path_to_file.xls')
df = pd.read_excel(xlsx, 'Sheet1')
@rsperl
rsperl / run_ansible_playbook.py
Last active July 28, 2022 00:00
run an ansible playbook programatically from python #snippet
#!/usr/bin/env python
"""
How to programatically run a playbook
(adapted from http://docs.ansible.com/ansible/dev_guide/developing_api.html#python-api-2-0)
Note that example from URL above only supports a single play per run, while actual playbooks
contain a list of plays. A playbook cannot be read in and run, but read in, and each play
run one at at time, and evaulate the result of each play separately (see below)
Also note that this is not a general purpose playbook runner, but one specifically suited to
@rsperl
rsperl / colored_text.sh
Last active July 25, 2022 16:17
create functions that output colored text #shell #snippet
# usage: source colored_text.sh
# c_red("hello")
export C_BLACK="\\033[0;30m"
export C_DK_GRAY="\\033[1;30m"
export C_RED="\\033[0;31m"
export C_LT_RED="\\033[1;31m"
export C_GREEN="\\033[0;32m"
@rsperl
rsperl / netcat_check_udp.sh
Last active July 25, 2022 16:16
use netcat to see if a remote UDP port is open #networking #shell #snippet
#!/bin/sh
# check if a upd port is open with netcat
nc -v -u -z -w 3 localhost 5000
# send a test packet
# -n - Tells the echo command to not output the trailing newline.
# -4u Use IPV4 addresses only. Use UDP instead of TCP.
# -w1 Silently close the session after 1 second of idle time. That way, we’re not stuck waiting for more data.
echo -n “foo” | nc -4u -w1 <host> <udp port>
@rsperl
rsperl / do_not_echo_stdin.sh
Last active July 25, 2022 16:16
do not echo stdin to stdout #shell #snippet
#!/bin/bash
# show prompt without a newline
echo -n "Password:"
# Turn off echo
stty -echo
# Read what the user typed
read passwd
@rsperl
rsperl / python_template.py
Last active July 25, 2022 16:15
python script template #python #template #snippet
#!/usr/bin/env python3
"""
Documentation about this script or module
"""
import os
import sys
from datetime import datetime
import argparse