Skip to content

Instantly share code, notes, and snippets.

@dansimau
dansimau / bandwidth-usage.sh
Created August 3, 2011 12:31
Display realtime bandwidth usage for a given interface (Linux only)
#!/bin/bash
#
# Display the realtime bandwidth usage for the specified interface.
#
# dsimmons@squiz.co.uk
# 2011-08-03
#
# Number of seconds to average data over
avgsecs=3
@dansimau
dansimau / README.md
Created September 26, 2023 14:19
Command execution in Maestro

Quick start

  • Start the exec server
tsx exec-server.ts &
  • Run Maestro test
@dansimau
dansimau / ldif-to-csv.sh
Created November 12, 2010 15:14
Shell script that reads LDIF data from STDIN and outputs as CSV.
#!/bin/bash
#
# Converts LDIF data to CSV.
# Doesn't handle comments very well. Use -LLL with ldapsearch to remove them.
#
# 2010-03-07
# dsimmons@squiz.co.uk
#
# Show usage if we don't have the right params
@dansimau
dansimau / grepurls.py
Created November 13, 2012 09:44
Recursive grep-like search for extracting URLs from a bunch of files
import os
import re
import sys
# Crazy URL regexp from Gruber
# http://daringfireball.net/2010/07/improved_regex_for_matching_urls
r = re.compile(r'(?i)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?]))')
# grep -r
for parent, dnames, fnames in os.walk(sys.argv[1]):
@dansimau
dansimau / ping-csv.sh
Created December 23, 2011 11:01
Ping a host and output each reply in CSV format
#!/bin/bash
#
# Do a ping and output results as CSV.
#
# dsimmons@squiz.co.uk
# 2011-12-23
#
if [ $# -lt 1 ]; then
echo "Usage: $0 [--add-timestamp] <ping host>"
@dansimau
dansimau / timeout-server.py
Created March 26, 2014 08:49
HTTP server that accepts connections and then hangs. Used to simulate and test slow API connections.
#!/usr/bin/python
import sys
import time
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
class RequestHandler(BaseHTTPRequestHandler):
def do_GET(s):
while True:
time.sleep(1000)
@dansimau
dansimau / README.md
Created August 11, 2022 13:49
Getting PowerShell running on macOS (M1) - August 2022

Getting PowerShell running on macOS (M1) - August 2022

We need to run everything under x86 emulation, because Powershell needs opensslv1 and opensslv1 only builds under x86.

Create home directory and script to launch x86 shell:

mkdir -p $HOME/x86shell
cat <<EOF > $HOME/x86shell/.bash_profile
export PATH=$PATH:/usr/bin
@dansimau
dansimau / supervise.sh
Created November 14, 2016 20:29
process supervisor in bash
#!/bin/bash
#
# Spawn a process and restart it if it exits.
#
declare -i exit_code
declare -i pid
_cleanup() {
echo "[$(date)]: sending TERM to pid $pid"
kill -TERM $pid
@dansimau
dansimau / README.md
Last active July 31, 2022 01:22
Tool for logging SSH sessions.

What is sshlog.sh

sshlog.sh logs all your SSH sessions to the specified destination directory so you can search/recall them later.

How to use

@dansimau
dansimau / recursively-list-users-in-azure-ad-group.py
Last active May 18, 2022 14:03
Recursively list users in an Azure AD group
#!/usr/bin/env python3
import json
import subprocess
import sys
from typing import List
def list_users_in_groups(group_names: List[str]):
groups_stack: List[str] = group_names;
users: List[str] = [];