-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2024-07-09 17:12:50.821088 new snippets
- Loading branch information
1 parent
3399cb5
commit 6ce6848
Showing
15 changed files
with
882 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!"); | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ( | ||
|
||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.