Skip to content

Instantly share code, notes, and snippets.

@EvgeniGordeev
EvgeniGordeev / ec2-ls-price.sh
Created July 17, 2025 17:59
List EC2 instances by a filter and list prices
function ec2-ls-price() {
local name_filter=${1:?}
local year=${2:-1yr}
local offering=${3:-All Upfront}
local region=${AWS_REGION:-$(aws configure get region)}
local pricing_region="$region"
local pricing_location
pricing_location=$(get_aws_pricing_location "$region")
if [[ -z "$pricing_location" ]]; then
@EvgeniGordeev
EvgeniGordeev / datagrip-copy-pwd.py
Created February 7, 2025 16:55
Reveal DataGrip passwords saved in Keychain
import re
import subprocess
if __name__ == '__main__':
# located in project folder .idea/dataSources.xml
with open('dataSources.xml', 'r') as f:
data = f.read()
data_sources = sorted(re.findall(r".*data-source.*name=\"(.*?)\".*uuid=\"(.*?)\".*", data))
for name, uuid in data_sources:
command = f'security find-generic-password -l "IntelliJ Platform DB — {uuid}" -w'
import decimal
import textwrap
# demo division 1/998001
decimal.setcontext(decimal.Context(prec=9999))
one = decimal.Decimal(1)
denom = decimal.Decimal(998001)
res = str(one/denom)
print(textwrap.fill(res, 100))
nums = textwrap.wrap(res[4:], 3)
@EvgeniGordeev
EvgeniGordeev / runtime-badge-2015-01.json
Last active January 8, 2025 04:08
adventofcode-runtime-badge
{"schemaVersion": 1, "label": "Runtime", "message": "13.3 ms ±", "color": "blue"}
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.time.Duration;
import java.time.LocalDate;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
@EvgeniGordeev
EvgeniGordeev / MigratePendingMessages.java
Last active January 13, 2021 01:11
ActiveMQ - copy pending messages from one server to another
import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.ActiveMQMessageProducer;
import org.apache.activemq.ActiveMQSession;
import org.apache.activemq.command.ActiveMQMessage;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.util.IdGenerator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@EvgeniGordeev
EvgeniGordeev / retry.sh
Created June 22, 2020 13:00 — forked from sj26/LICENSE.md
Bash retry function
# Retry a command up to a specific numer of times until it exits successfully,
# with exponential back off.
#
# $ retry 5 echo Hello
# Hello
#
# $ retry 5 false
# Retry 1/5 exited 1, retrying in 1 seconds...
# Retry 2/5 exited 1, retrying in 2 seconds...
# Retry 3/5 exited 1, retrying in 4 seconds...
#!/usr/bin/env bash
aws_region=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone | sed 's/[a-z]$//')
aws configure set default.region $aws_region
aws configure set default.output json
describe_instances(){
local filter=$1
local region=${2:-$aws_region}
aws ec2 describe-instances --filters "Name=tag:Name,Values=$filter" "Name=instance-state-name,Values=running" \
#!/usr/bin/env bash
# usage: $(assume_role <role_arn>)
assume_role(){
local role=$1
local session_name=${2:-"$(date +'%Y%m%d%h%H%M%S')"}
aws sts assume-role --role-arn "$role" --role-session-name "$session_name" \
--query 'Credentials.{AWS_ACCESS_KEY_ID:AccessKeyId, AWS_SECRET_ACCESS_KEY:SecretAccessKey, AWS_SESSION_TOKEN:SessionToken}' \
| jq -r 'to_entries[]|("export "+.key+"="+.value)'
}