Skip to content

Instantly share code, notes, and snippets.

View look4regev's full-sized avatar
😎
Saving the world

Regev Golan look4regev

😎
Saving the world
View GitHub Profile
@look4regev
look4regev / get_ec2s_ips_by_name_tag.sh
Created May 26, 2022 12:17
Get AWS EC2s IPs by name tag
INSTANCE_NAME=$1
ips=$(aws ec2 describe-instances --filters="Name=tag:Name,Values=${INSTANCE_NAME}" --query="Reservations[*].Instances[*].PrivateIpAddress" --output=text)
for i in $(cat ips | tr '\t\n' ',' | tr ',' '\n'); do echo $i; ssh $i -q -t "hostname"; done
@look4regev
look4regev / mongodb_group_connections_by_env_var.js
Created May 26, 2022 12:13
mongodb group by connections count on env var
// Assuming "application" is the connection env var to group by connections by.
db.currentOp(true).inprog.reduce(
(accumulator, connection) => {
application = connection.clientMetadata && connection.clientMetadata.application ?
connection.clientMetadata.application.name : "Internal";
accumulator[application] = (accumulator[application] || 0) + 1;
accumulator["TOTAL_CONNECTION_COUNT"]++;
return accumulator;
},
{ TOTAL_CONNECTION_COUNT: 0 }
@look4regev
look4regev / mongo_group_connections_by_source_ip.sh
Last active May 26, 2022 12:11
mongodb group by count on connections by source ip
lsof -i -u mongod | grep "ESTABLISHED" | awk {'print $9 '} | cut -d":" -f 2| sort | uniq -c | sort -n
@look4regev
look4regev / jenkins_jobs_builds_remove.sh
Last active March 21, 2022 15:27
Delete jenkins jobs directories with a lot of old builds
find ${JENKINS_HOME_PATH} -maxdepth 2 -type d -print0 -name "builds" | while read -d '' -r dir; do
files=("$dir"/*)
if [ "${#files[@]}" -gt 30 ]; then
if [[ "$dir" =~ .*"builds_"$ ]]; then
echo "removing $dir"
rm -rf $dir
else
printf "%5d files in directory %s\n" "${#files[@]}" "$dir"
rm -rf "${dir}_"
mv "${dir}" "${dir}_"
@look4regev
look4regev / Swap_Mac_plus-minus_and_tilde_keys.sh
Created October 15, 2020 13:56
Swap Mac ± and ~ keys script
# Taken from https://ppolyzos.com/2020/10/09/swap-places-between-tilde-and-section-sign-%C2%A7-key-in-your-macbook-keyboard/
hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000035,"HIDKeyboardModifierMappingDst":0x700000064},{"HIDKeyboardModifierMappingSrc":0x700000064,"HIDKeyboardModifierMappingDst":0x700000035}]}'
sudo /usr/bin/env bash -c "cat > /Library/LaunchAgents/org.custom.tilde-switch.plist" << EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
@look4regev
look4regev / myip.sh
Created July 12, 2020 14:55
Show my local and external ip quick shell command
myip() {
echo "local ip: "
ipconfig getifaddr en0
echo "external ip: "
curl ipecho.net/plain ; echo
}
@look4regev
look4regev / asdf_python372_install.sh
Created January 18, 2020 08:52
Quick install script for python3.7.2 by asdf
#!/bin/bash -e
ASDF_VERSION=v0.7.1
PYTHON3_VERSION372=3.7.2
if [ ! -d "$HOME/.asdf" ] ; then
git clone https://github.com/asdf-vm/asdf.git $HOME/.asdf --branch $ASDF_VERSION
fi
source $HOME/.asdf/asdf.sh
source $HOME/.asdf/completions/asdf.bash
@look4regev
look4regev / rsync_move.sh
Created August 31, 2019 17:04
Move files with rsync
#!/bin/bash
# Example:
# SOURCE_PATH=/var/lib/docker/
# DEST_PATH=/mnt/docker/
rsync -aPHSx --remove-source-files ${SOURCE_PATH} ${DEST_PATH}
@look4regev
look4regev / qfind.sh
Created August 22, 2019 08:35
Bash find files function which excludes ignored directories
#!/bin/bash
qfind () {
find . -not -path "*/node_modules*" -not -path "*/.git/*" -not -path "*/build/*" -not -path "*/*.egg-info*" -not -path "*/.pytest_cache*" -not -path "*/.idea*" -not -path "*/__pycache__*" -not -path "*/.vscode*/" -not -path "*/app/libs/*" -name $1
}
@look4regev
look4regev / krand.sh
Created August 22, 2019 05:17
Bash function to make a random 12 chars string including numbers, special chars and lower+upper case
#!/bin/bash
krand() {
# Outputs random 12 chars string including numbers, special chars and lower+upper case
dd if=/dev/urandom count=1 2>/dev/null | base64 | head -1 | cut -c4-15
}