Skip to content

Instantly share code, notes, and snippets.

View mnebuerquo's full-sized avatar
😎
Being awesome!

Sherman Adelson mnebuerquo

😎
Being awesome!
View GitHub Profile
@mnebuerquo
mnebuerquo / curl-or-wget.sh
Created August 18, 2022 13:04
curl-or-wget.sh
#!/bin/sh
# this one saves to a file
download_file(){
curl -f -o "${1}" "${2}" || wget -O "${1}" "${2}"
}
download_file /path/destination https://sourceurl
@mnebuerquo
mnebuerquo / clear-iptables.sh
Last active April 26, 2018 16:48
Clear all rules from iptables without locking me out of the server
#!/bin/sh
# Clear out all iptables rules and make the changes persistent.
# first, find out if we're sudo
if [ $(id -u) -ne 0 ]; then
echo "Nope. Simon didn't say so.";
exit 1;
fi
@mnebuerquo
mnebuerquo / findcrons.sh
Last active April 12, 2018 13:56
list all cron jobs of all users on system
#!/bin/sh
# first, find out if we're sudo
if [ $(id -u) -ne 0 ]; then
echo "Nope. Simon didn't say so.";
exit 1;
fi
for user in $(cut -f1 -d: /etc/passwd); do
crons=$(crontab -u $user -l 2>/dev/null | grep -v '^#')
@mnebuerquo
mnebuerquo / rotate-mongo-log
Created April 9, 2018 17:02
logrotate rule to rotate mongodb logs
# rotate mongodb
# https://stackoverflow.com/a/8396266/5114
/var/log/mongo/*.log {
daily
rotate 30
compress
dateext
missingok
notifempty
sharedscripts
#!/bin/sh
# find out if we're sudo
if [ $(id -u) -ne 0 ]; then
echo "Nope. Simon didn't say so.";
exit 1;
fi
target="/dev/md0"
mountpoint="/data"
#!/bin/sh
# Install docker on machine, add a user to the docker group.
# first, find out if we're sudo
if [ $(id -u) -ne 0 ]; then
echo "Nope. Simon didn't say so.";
exit 1;
fi
#!/bin/sh
if [ $(id -u) -ne 0 ]; then
echo "Nope. Simon didn't say so!"
exit 1;
fi
if [ -z "$1" ]; then
echo "What's my name? Say my name, bitch!"
exit 1
@mnebuerquo
mnebuerquo / flatten.py
Created January 19, 2018 15:50
code I ripped off from someone on stack overflow
# https://stackoverflow.com/a/19647596/5114
def flatten_dict(dd, separator='_', prefix=''):
return { prefix + separator + k if prefix else k : v
for kk, vv in dd.items()
for k, v in flatten_dict(vv, separator, kk).items()
} if isinstance(dd, dict) else { prefix : dd }
@mnebuerquo
mnebuerquo / mongo-tunnel
Last active January 4, 2018 20:27
Open an ssh tunnel to a mongo server through another host, so that the mongo ports are available on localhost.
#!/bin/sh
# mongodb is in a private network somewhere, host is a machine which can connect
# after running this script, you can connect to mongo at localhost
MONGO=$1
HOST=$2
ssh -fnN \
-L 27017:$MONGO:27017 \
@mnebuerquo
mnebuerquo / runpy
Last active March 16, 2019 18:01
Run a python script in a virtualenv more easily
#!/bin/sh
# Note: This gist is superseded by an improved script:
# https://github.com/mnebuerquo/virtuous-python
# Run a python script, and manage the virtualenv for me so I don't have to
# https://gist.github.com/mnebuerquo/4da76a007d18964dc3f7ce43e213b46f
# Run: ./run app.py [--argument --other file --whatever]
# Test: ./run --test [<--more-pytest-args-here>]