Skip to content

Commit

Permalink
2024-07-09 17:12:50.821088 new snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardocerqueira committed Jul 9, 2024
1 parent 3399cb5 commit 6ce6848
Show file tree
Hide file tree
Showing 15 changed files with 882 additions and 0 deletions.
25 changes: 25 additions & 0 deletions seeker/report.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
--------------------------------------------------------------------------------
2024-07-09 17:12:50.821088
--------------------------------------------------------------------------------
On branch main
Your branch is up to date with 'origin/main'.

Untracked files:
(use "git add <file>..." to include in what will be committed)
snippet/LAB0001.java
snippet/RedisTemplate.java
snippet/aws-nuke.sh
snippet/change_user.sh
snippet/create-cache.java
snippet/filename.java
snippet/get-cache.java
snippet/get-latest-terraform.sh
snippet/install_csi_tool.sh
snippet/migrate.sh
snippet/qt5-build-for-qgis-macos.sh
snippet/solution.go
snippet/transformer.py
snippet/uuid7.py

nothing added to commit but untracked files present (use "git add" to track)

--------------------------------------------------------------------------------
2024-07-08 17:11:24.479467
--------------------------------------------------------------------------------
Expand Down
13 changes: 13 additions & 0 deletions seeker/snippet/LAB0001.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//date: 2024-07-09T17:08:26Z
//url: https://api.github.com/gists/bdfc2d74930bca6cc495831620eeabdd
//owner: https://api.github.com/users/Kat-Rambo

package EX_070724;

public class LAB0001 {
public static void main(String[] args) {
System.out.println("Hello World!");


}
}
15 changes: 15 additions & 0 deletions seeker/snippet/RedisTemplate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//date: 2024-07-09T17:09:38Z
//url: https://api.github.com/gists/7b28c84aaa859f0d7118fbf2bf070ab8
//owner: https://api.github.com/users/enrinal

public RedisTemplate<String, byte[]> redisTemplateByte(
LettuceConnectionFactory defaultLettuceConnectionFactory) {
RedisTemplate<String, byte[]> template = new RedisTemplate<>();
template.setKeySerializer(RedisSerializer.string());
template.setHashKeySerializer(RedisSerializer.string());
template.setValueSerializer(RedisSerializer.byteArray());
template.setHashValueSerializer(RedisSerializer.byteArray());
template.setConnectionFactory(defaultLettuceConnectionFactory);
template.afterPropertiesSet();
return template;
}
33 changes: 33 additions & 0 deletions seeker/snippet/aws-nuke.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#date: 2024-07-09T16:59:18Z
#url: https://api.github.com/gists/5b08d61c03d2396eaa8ec0650d36415f
#owner: https://api.github.com/users/bruteforks

#!/usr/bin/env bash

# Set the target directory
TARGET_DIR="$HOME/.local/bin"

# Fetch the latest release version
latest_version=$(curl -s https://api.github.com/repos/rebuy-de/aws-nuke/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")')

# Remove the 'v' prefix from the version number
version=${latest_version#v}

# Construct the download URL
download_url="https://github.com/rebuy-de/aws-nuke/releases/download/${latest_version}/aws-nuke-${latest_version}-linux-amd64.tar.gz"

# Download the tar.gz file
curl -L -o "aws-nuke-${version}.tar.gz" "$download_url"
echo "Downloaded aws-nuke-${version}.tar.gz"

echo "Extracting it to $TARGET_DIR"
tar -xz -C "$TARGET_DIR" -f "aws-nuke-${version}.tar.gz"

mv "$TARGET_DIR/aws-nuke-${latest_version}-linux-amd64" "$TARGET_DIR/aws-nuke"
echo "Renaming binary"

echo "Removing tar file"
rm -f "aws-nuke-${version}.tar.gz"

echo "aws-nuke has been installed in $TARGET_DIR"
echo "awsnuke-config in ~/.dotfiles"
24 changes: 24 additions & 0 deletions seeker/snippet/change_user.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#date: 2024-07-09T17:10:55Z
#url: https://api.github.com/gists/81cdae4248a6a66d62716f40e03ba7f9
#owner: https://api.github.com/users/mabsboza

if [ "$#" -ne 1 ]; then
echo "Usage: $0 [personal|work1|work2]"
exit 1
fi

if [ "$1" == "personal" ]; then
git config --global user.name "Tu Nombre"
git config --global user.email "[email protected]"
elif [ "$1" == "chile" ]; then
git config --global user.name "Tu Nombre Trabajo 1"
git config --global user.email "[email protected]"
elif [ "$1" == "usa" ]; then
git config --global user.name "Tu Nombre Trabajo 2"
git config --global user.email "[email protected]"
else
echo "Invalid option. Use one of [personal|work1|work2]"
exit 1
fi

echo "Git user configuration updated to $1"
19 changes: 19 additions & 0 deletions seeker/snippet/create-cache.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//date: 2024-07-09T17:08:59Z
//url: https://api.github.com/gists/12ab04d2ca4e2de5ba5433274f9885e6
//owner: https://api.github.com/users/enrinal

@Override
public <T> Mono<Boolean> createCache(HeaderCommonRequest headerCommonRequest, T value, String key,
Duration timeout) {
long startTime = System.nanoTime();
return Mono.defer(() ->
Mono.fromCallable(() -> Snappy.compress(JSONHelper.convertObjectToJsonInString(value)))
.flatMap(compressedData -> {
redisTemplateByte.opsForValue().set(key, compressedData, timeout);
return Mono.just(true);
})
.then(Mono.just(true))
)
.elapsed()
.hasElement();
}
7 changes: 7 additions & 0 deletions seeker/snippet/filename.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//date: 2024-07-09T17:12:44Z
//url: https://api.github.com/gists/0f8f49db67e43818accc20177436de16
//owner: https://api.github.com/users/fav579

class sample (

)
40 changes: 40 additions & 0 deletions seeker/snippet/get-cache.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//date: 2024-07-09T17:03:26Z
//url: https://api.github.com/gists/81141dba7ab189d65ab1acd1d4f8a749
//owner: https://api.github.com/users/enrinal

public <T> Mono<T> getCache(HeaderCommonRequest headerCommonRequest, String key, Class<T> clazz) {
return Mono.defer(() -> {
long startTime = System.nanoTime();
return Mono.defer(() ->
Optional.ofNullable(redisTemplateByte.opsForValue().get(key))
.map(Mono::just)
.orElseGet(Mono::empty))
.elapsed()
.flatMap(tupleData ->
Mono.fromCallable(() -> Snappy.uncompressString(tupleData.getT2()))
.flatMap(uncompressedData ->
Mono.defer(() -> {
log.debug("[{}] process time get cache key = {}, process time={} ms",
headerCommonRequest.getMandatoryRequest().getRequestId(), key,
tupleData.getT1());
return Mono.just(
Objects.requireNonNull(
JSONHelper.convertJsonInStringToObject(uncompressedData, clazz)));
})
)
.onErrorResume(throwable ->
Mono.defer(() -> {
cacheMonitoringUtil.logMetric(isSendMetric, "getCache", startTime, FAILED);
log.error("[{}] getCache() - failed get this key={}. with this error={}",
headerCommonRequest.getMandatoryRequest().getRequestId(), key,
throwable);
return Mono.error(
new BusinessLogicException(
CommonResponseCode.PARSE_DATA_ERROR.getCode(),
CommonResponseCode.PARSE_DATA_ERROR.getMessage()));
}))
)
.doOnSuccess(res ->
cacheMonitoringUtil.logMetric(isSendMetric, "getCache", startTime, SUCCEED));
});
}
18 changes: 18 additions & 0 deletions seeker/snippet/get-latest-terraform.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#date: 2024-07-09T17:00:07Z
#url: https://api.github.com/gists/b71c0ec0139df9375ea3f4156979ad2c
#owner: https://api.github.com/users/Malond11

#!/bin/bash

LATEST_RELEASE=$(curl -s https://checkpoint-api.hashicorp.com/v1/check/terraform | jq -r .current_version)
CURRENT_RELEASE=$(terraform version -json | jq -r .terraform_version)
if [[ ${LATEST_RELEASE} != $CURRENT_RELEASE ]]; then
echo "Installing Terraform ${LATEST_RELEASE}..."

FILENAME=terraform_${LATEST_RELEASE}_linux_amd64.zip
wget https://releases.hashicorp.com/terraform/${LATEST_RELEASE}/$FILENAME
unzip $FILENAME && rm $FILENAME
sudo mv terraform /usr/local/bin
else
echo "Latest version of Terraform (${LATEST_RELEASE}) already installed."
fi
29 changes: 29 additions & 0 deletions seeker/snippet/install_csi_tool.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#date: 2024-07-09T16:57:03Z
#url: https://api.github.com/gists/482f0ab3291143bc8ded9188bc9c2e73
#owner: https://api.github.com/users/Stop423

#!/bin/bash

# Install development tools
sudo apt update
sudo apt install gcc make linux-headers-$(uname -r) git-core
# Build and install the modified wireless driver
CSITOOL_KERNEL_TAG=csitool-$(uname -r | cut -d . -f 1-2)
git clone https://github.com/posoo/linux-80211n-csitool.git --branch ${CSITOOL_KERNEL_TAG} --depth 1
cd linux-80211n-csitool
make -C /lib/modules/$(uname -r)/build M=$(pwd)/drivers/net/wireless/iwlwifi modules
sudo make -C /lib/modules/$(uname -r)/build M=$(pwd)/drivers/net/wireless/iwlwifi INSTALL_MOD_DIR=updates \
modules_install
sudo depmod
cd ..
# Install the modified firmware
git clone https://github.com/posoo/linux-80211n-csitool-supplementary.git
for file in /lib/firmware/iwlwifi-5000-*.ucode
do
sudo mv $file $file.orig
done
sudo cp linux-80211n-csitool-supplementary/firmware/iwlwifi-5000-2.ucode.sigcomm2010 /lib/firmware/
sudo ln -s iwlwifi-5000-2.ucode.sigcomm2010 /lib/firmware/iwlwifi-5000-2.ucode
# Build the userspace logging tools
make -C linux-80211n-csitool-supplementary/netlink
echo "All Done!"
156 changes: 156 additions & 0 deletions seeker/snippet/migrate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
#date: 2024-07-09T16:54:05Z
#url: https://api.github.com/gists/bfe99ee6d9061d46609ba171d2705fa2
#owner: https://api.github.com/users/ArktikAgency

#!/bin/bash

# This script will backup your Coolify instance and move everything to a new server. Docker volumes, Coolify database, and ssh keys

# 1. Script must run on the source server
# 2. Have all the containers running that you want to migrate

# Configuration - Modify as needed
sshKeyPath="$HOME/.ssh/your_private_key" # Key to destination server
destinationHost="server.example.com"

# -- Shouldn't need to modify anything below --
backupSourceDir="/data/coolify/"
backupFileName="coolify_backup.tar.gz"

# Check if the source directory exists
if [ ! -d "$backupSourceDir" ]; then
echo "❌ Source directory $backupSourceDir does not exist"
exit 1
fi
echo "βœ… Source directory exists"

# Check if the SSH key file exists
if [ ! -f "$sshKeyPath" ]; then
echo "❌ SSH key file $sshKeyPath does not exist"
exit 1
fi
echo "βœ… SSH key file exists"

# Check if we can SSH to the destination server, ignore "The authenticity of host can't be established." errors
if ! ssh -i "$sshKeyPath" -o "StrictHostKeyChecking no" -o "ConnectTimeout=5" root@$destinationHost "exit"; then
echo "❌ SSH connection to $destinationHost failed"
exit 1
fi
echo "βœ… SSH connection successful"

# Get the names of all running Docker containers
containerNames=$(docker ps --format '{{.Names}}')

# Initialize an empty string to hold the volume paths
volumePaths=""

# Loop over the container names
for containerName in $containerNames; do
# Get the volumes for the current container
volumeNames=$(docker inspect --format '{{range .Mounts}}{{.Name}}{{end}}' "$containerName")

# Loop over the volume names
for volumeName in $volumeNames; do
# Check if the volume name is not empty
if [ -n "$volumeName" ]; then
# Add the volume path to the volume paths string
volumePaths+=" /var/lib/docker/volumes/$volumeName"
fi
done
done

# Calculate the total size of the volumes
# shellcheck disable=SC2086
totalSize=$(du -csh $volumePaths 2>/dev/null | grep total | awk '{print $1}')

# Print the total size of the volumes
echo "βœ… Total size of volumes to migrate: $totalSize"

# Print size of backupSourceDir
backupSourceDirSize=$(du -csh $backupSourceDir 2>/dev/null | grep total | awk '{print $1}')
echo "βœ… Size of the source directory: $backupSourceDirSize"

# Check if the backup file already exists
if [ ! -f "$backupFileName" ]; then
echo "🚸 Backup file does not exist, creating"

# Recommend stopping docker before creating the backup
echo "🚸 It's recommended to stop all Docker containers before creating the backup
Do you want to stop Docker? (y/n)"
read -r answer
if [ "$answer" != "${answer#[Yy]}" ]; then
if ! systemctl stop docker; then
echo "❌ Docker stop failed"
exit 1
fi
echo "βœ… Docker stopped"
else
echo "🚸 Docker not stopped, continuing with the backup"
fi

# shellcheck disable=SC2086
if ! tar --exclude='*.sock' -Pczf $backupFileName -C / $backupSourceDir $HOME/.ssh/authorized_keys $volumePaths; then
echo "❌ Backup file creation failed"
exit 1
fi
echo "βœ… Backup file created"
else
echo "🚸 Backup file already exists, skipping creation"
fi

# Define the remote commands to be executed
remoteCommands="
# Check if Docker is a service
if systemctl is-active --quiet docker; then
# Stop Docker if it's a service
if ! systemctl stop docker; then
echo '❌ Docker stop failed';
exit 1;
fi
echo 'βœ… Docker stopped';
else
echo 'ℹ️ Docker is not a service, skipping stop command';
fi
echo '🚸 Saving existing authorized keys...';
cp ~/.ssh/authorized_keys ~/.ssh/authorized_keys_backup;
echo '🚸 Extracting backup file...';
if ! tar -Pxzf - -C /; then
echo '❌ Backup file extraction failed';
exit 1;
fi
echo 'βœ… Backup file extracted';
echo '🚸 Merging authorized keys...';
cat ~/.ssh/authorized_keys_backup ~/.ssh/authorized_keys | sort | uniq > ~/.ssh/authorized_keys_temp;
mv ~/.ssh/authorized_keys_temp ~/.ssh/authorized_keys;
chmod 600 ~/.ssh/authorized_keys;
echo 'βœ… Authorized keys merged';
if ! curl -fsSL https://cdn.coollabs.io/coolify/install.sh | bash; then
echo '❌ Coolify installation failed';
exit 1;
fi
echo 'βœ… Coolify installed';
"

# SSH to the destination server, execute the remote commands
if ! ssh -i "$sshKeyPath" -o "StrictHostKeyChecking no" root@$destinationHost "$remoteCommands" <$backupFileName; then
echo "❌ Remote commands execution or Docker restart failed"
exit 1
fi
echo "βœ… Remote commands executed successfully"

# Clean up - Ask the user for confirmation before removing the local backup file
echo "Do you want to remove the local backup file? (y/n)"
read -r answer
if [ "$answer" != "${answer#[Yy]}" ]; then
if ! rm -f $backupFileName; then
echo "❌ Failed to remove local backup file"
exit 1
fi
echo "βœ… Local backup file removed"
else
echo "🚸 Local backup file not removed"
fi
Loading

0 comments on commit 6ce6848

Please sign in to comment.