Skip to content

Instantly share code, notes, and snippets.

@valtoni
valtoni / aws_orphan_snapshots.py
Created July 4, 2022 22:17
AWS List of snapshots without AMI (Boto3)
import boto3
from boto3 import ec2
import datetime
import re
from datetime import date
def is_attached(image, snapshot):
for mapping in image['BlockDeviceMappings']:
# Is it a machine ephemeral device?
@valtoni
valtoni / find_executable.PS1
Created November 23, 2021 12:59
Powershell find file in path
:: simple version
$env:path.Split(';') | gci -Filter application.exe
:: expanded version
$env:path.Split(';') | select -Unique | ? {$_ -and (test-path $_)} | gci -Filter application.exe
@valtoni
valtoni / move_structure.ps1
Created October 10, 2021 13:15
Move founded files with structure (PowerShell)
$OldBase="C:\src\main\java"
$NewBase="C:\src\main\resources"
$HibernateFiles=Get-ChildItem $OldBase -Include *.xml -Recurse
foreach ($file in $HibernateFiles) {
Write-Host $file.FullName
$Directory=$file.Directory.ToString()
$Directory=$Directory.replace($OldBase, $NewBase)
$OldFile=$file.FullName
$NewFile=$OldFile.replace($OldBase, $NewBase)
New-Item $Directory -ItemType Directory -ea 0
#!/bin/bash
stats=””
echo "% user"
echo "============"
# collect the data
for user in `ps aux | grep -v COMMAND | awk '{print $1}' | sort -u`
do
stats="$stats\n`ps aux | egrep ^$user | awk 'BEGIN{total=0}; \
@valtoni
valtoni / linux_redirect_syslog.sh
Created March 22, 2021 10:57
Output log to syslog in linux (init.d scripts)
# Original: https://serverfault.com/questions/341919/how-to-find-error-messages-from-linux-init-d-rc-d-scripts
# Reference: http://urbanautomaton.com/blog/2014/09/09/redirecting-bash-script-output-to-syslog/
exec 1> >(logger -s -t $(basename $0)) 2>&1
cat >/tmp/demo-space-separated.sh <<'EOF'
#!/bin/bash
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-e|--extension)
@valtoni
valtoni / mount_ec2_ephemeral.sh
Last active February 25, 2021 20:50
This script automatically mount ephemeral disks in EC2 nitro instances.
#!/usr/bin/env bash
# Mandatory: apt install nvme-cli
# Mount point (directory)
TARGET_MOUNT=/data/tmp
# Raid info
TARGET_RAID_DEVICE=/dev/md0
TARGET_RAID_LABEL=RAID0
@valtoni
valtoni / xcode_uninstall.sh
Last active November 3, 2020 23:10
Remove Xcode
#!/bin/bash
killall Xcode
xcrun -k
xcodebuild -alltargets clean
dirs = ("$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang/ModuleCache"
"$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang.$(whoami)/ModuleCache"
/Applications/Xcode.app
~/Library/Caches/com.apple.dt.Xcode
@valtoni
valtoni / slack.sh
Created September 12, 2020 20:39 — forked from andkirby/slack.sh
Shell/Bash script for sending slack messages.
#!/usr/bin/env bash
####################################################################################
# Slack Bash console script for sending messages.
####################################################################################
# Installation
# $ curl -s https://gist.githubusercontent.com/andkirby/67a774513215d7ba06384186dd441d9e/raw --output /usr/bin/slack
# $ chmod +x /usr/bin/slack
####################################################################################
# USAGE
# Send message to slack channel/user
@valtoni
valtoni / path_environment.ps
Created June 19, 2020 12:55
Set path environment on windows powershell
# Add path permanently to environment machine
[Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\bin", "Machine")
# Add path permanently to environment user
[Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\bin", "User")