Skip to main content

LeetCode #192: Word Frequency

Oct 15, 2022CodeCatch
Loading...

More Shell Posts

unexpandDirectory.sh

May 13, 2023LeifMessinger

0 likes • 1 view

#!/bin/bash
# Turns 4 spaces into tabs.
# Mostly stolen from AI
# Define the directory to process
DIRECTORY=$1
TabCount=${2:-'4'} #Defaults to 4
# Check if directory is specified
if [ -z "$DIRECTORY" ]; then
echo "Error: Directory not specified."
exit 1
fi
# Check if directory exists
if [ ! -d "$DIRECTORY" ]; then
echo "Error: Directory does not exist."
exit 1
fi
# Find all files in directory and subdirectories
FILES=$(find "$DIRECTORY" -type f)
# Loop through each file and unexpand it
for FILE in $FILES; do
unexpand -t "$TabCount" "$FILE" > "$FILE.tmp"
mv "$FILE.tmp" "$FILE"
done
echo "Done!"

cpcmd.sh

Sep 29, 2021LeifMessinger

0 likes • 20 views

#!/bin/bash
#cpcmd.sh [file1 [file2...]]
#Prints out the commands needed to copy the file to your local machine
#This will work on any server that also has the same hostname as in your hosts file.
#I should update this to detect if a file is a directory, and enable recursion for those commands. If you do it now, it will probably just warn you.
if [ -n "$1" ]; then
while [ -n "$1" ]; do
printf "scp \"$(whoami)@$(hostname):"
printf `readlink -f $1`
printf "\" .\n"
shift
done
else
echo "scp \"$(whoami)@$(hostname):$PWD/*\" ."
fi
#-----------EDIT:
#On the UNT cell machines, you have to do this script instead
#if [ -n "$1" ]; then
# while [ -n "$1" ]; do
# printf "scp $(whoami)@$(hostname).eng.unt.edu:"
# printf `readlink -f $1`
# printf " .\n"
# shift
# done
#else
# echo "scp $(whoami)@$(hostname).eng.unt.edu:$PWD/* ."
#fi

Find data-testids

Jul 8, 2024CHS

0 likes • 13 views

#!/bin/bash
# Set the directory to search
DIRECTORY="src"
# Set the output file
OUTPUT_FILE="testids.txt"
# Clear the output file
> "$OUTPUT_FILE"
# Find all .tsx files in the specified directory and its subdirectories
find "$DIRECTORY" -type f -name "*.tsx" | while read -r FILE
do
# Search for instances of 'data-testid="testid"' and append them to the output file
grep -o 'data-testid="[^"]*"' "$FILE" >> "$OUTPUT_FILE"
# Search for instances of "'data-testid': 'testid'" and append them to the output file
grep -o "'data-testid': '[^']*'" "$FILE" >> "$OUTPUT_FILE"
done
echo "Search complete. Test IDs written to $OUTPUT_FILE."

Useful NVM Commands

Mar 20, 2023CHS

0 likes • 0 views

// check version
node -v || node --version
// list installed versions of node (via nvm)
nvm ls
// install specific version of node
nvm install 6.9.2
// set default version of node
nvm alias default 6.9.2
// switch version of node
nvm use 6.9.1

upload_key.sh

Jan 12, 2023LeifMessinger

0 likes • 0 views

#!/bin/bash
#Originally made by Isaac Cook https://gist.github.com/icook/5400173
#Modified by Leif Messinger
#upload_key.sh [server_ip [server2_ip [...]]]
#To be run locally on a linux computer
if [ -e ~/.ssh/id_rsa.pub ];
then
echo "SSH Key already exists on local machine"
else
echo "Generating SSH key on local machine"
ssh-keygen -t rsa #generates id_rsa and id_rsa.pub
chmod -R 700 ~/.ssh #Sets permissions of ssh folder
ssh-add #Adds keys (and passwords?) to ssh_agent. (hopefully doesn't require password)
fi
echo "Loading client public key into memory"
pubKey=$(<~/.ssh/id_rsa.pub)
for server
do
echo "Adding client public key to $server remote server authorized keys"
#Idiot Isaac Cook didn't know about ssh-copy-id
#ssh-copy-id even checks if your key already exists
#In fairness, I didn't either until researching ssh-add
ssh-copy-id -i ~/.ssh/id_rsa.pub $server #In theory, this should prompt for a username
#ssh $server "mkdir -p ~/.ssh; #Make the folder if not already made
# echo \"$pubKey\" >> ~/.ssh/authorized_keys; #Append your public key to the server's authorized_keys
# chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys" #Set the correct permissions of those files
#echo "Adding server public key to local authorized keys"
#ssh $server "ssh-copy-id -i ~/.ssh/id_rsa.pub \$SSH_CLIENT" #this might need some awk, as $SSH_CLIENT spits out clientip portnumber
echo "Displaying server public key"
ssh $server "cat ~/.ssh/id_rsa.pub"
#Though, he did give me a good idea
echo "Displaying keys authorized on $server (you can paste them in your authorized_keys file)"
ssh $server "cat ~/.ssh/authorized_keys"
#echo "Appending keys authorized on $server to your local authorized_keys"
#ssh $server "cat ~/.ssh/authorized_keys" >> ~/.ssh/authorized_keys
done
echo "SSH keys schronized successfully!"

credit.sh

Oct 26, 2021LeifMessinger

0 likes • 0 views

#!/bin/bash
#Leif Messinger lsm0147
#credit.sh FILES
cred="Leif Messinger lsm0147"
for bruh; do
if [[ $bruh =~ \.cpp|\.c|\.java|\.js ]]; then
comment="//$cred"
else
#Basically everything else gets a pound sign comment
#Pound signs are standard across linux. bash, sed, gawk, python etc
#Speaking of which, I need to escape it because of that.
comment="\#$cred"
fi
if [ -s $bruh ]; then
#If the file has a shebang
if egrep -q '^#!/' $bruh; then
sed -i "/^\#!\//a$comment" $bruh
else
sed -i "1i$comment" $bruh
fi
else
echo "$comment" > $bruh
fi
done