Skip to content

Instantly share code, notes, and snippets.

@sha1n
sha1n / ExecutorsMetrics.java
Created February 5, 2024 08:46
Micrometer executor metrics
package io.sha1n.infra.monitoring;
import io.micrometer.core.instrument.Tag;
import io.micrometer.core.instrument.Tags;
import lombok.val;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadPoolExecutor;
@sha1n
sha1n / bump-version.sh
Created October 30, 2023 06:39
Maven version update utility script
#!/usr/bin/env bash
update_type=$1
maven_args=""
invalid_argument() {
echo "Error: Invalid argument."
echo "Usage: $0 {major|minor|patch}"
exit 1
@sha1n
sha1n / googlesearch_daily_quota_alert.mql
Last active January 26, 2023 09:56
Google Custom Search API Quota Alert MQL
fetch consumer_quota
# Only fetch the quota usage metric
| metric 'serviceruntime.googleapis.com/quota/rate/net_usage'
# Only count custom search API requests
| filter
(metric.method == 'google.customsearch.v1.CustomSearchService.List'
&& metric.quota_metric == 'customsearch.googleapis.com/requests')
# Map 'yyyymmdd' formatted date field in PST timezone to column 'Date'
| map
add[
@sha1n
sha1n / ForkJoinUseAndAbuseExample.java
Created December 19, 2022 05:46
ForkJoin use and abuse examples
package com.example;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinTask;
public class ForkJoinUseAndAbuseExample {
public static void main(String[] args) throws InterruptedException, ExecutionException {
@sha1n
sha1n / ExecutorDeadLockExample.java
Last active December 19, 2022 05:47
ExecutorService deadlocked nested tasks example
package com.example;
import lombok.val;
import java.util.concurrent.*;
public class ExecutorDeadLockExample {
public static void main(String[] args) throws InterruptedException, ExecutionException {
val executorService = Executors.newFixedThreadPool(1);
@sha1n
sha1n / README.md
Last active September 28, 2021 13:44
Poor man's Bazel disk-cache age based eviction

Poor man's Bazel disk-cache age based eviction

Usage:

  1. Edit BAZEL_BIN_PATH in the script to match your setup
  2. Add build --disk_cache=~/.cache/bazel/disk_cache to your .bazelrc. Edit the path to your preferences and the variable value accordingly.
  3. Edit the value of BAZEL_DISK_CACHE_MAX_AGE to match your preferences.
  • Higher values means more cache hits over time
  • Lower values means less disk-space and less cleanup time and CPU load
  1. Finally source the scriupt from your shell profile
@sha1n
sha1n / EmulatedStdinReader.go
Created May 25, 2021 09:50
An emulated STDIN reader for user input testing in Go
package test
import (
"bytes"
"fmt"
"strings"
)
type EmulatedStdinReader struct {
buf *bytes.Buffer
@sha1n
sha1n / backup.py
Last active May 2, 2020 20:36
A simple backup script for Cubase settings (macOS) such as project templates, track presets, instruments presets and more (requires Python >= 3.6).
#!/usr/bin/env python3
import argparse
import os
import shutil
from distutils.dir_util import copy_tree
from shutil import copy2
_DEFAULT_BACKUP_DEST = "/Volumes/Audio/Cubase Settings"
_DEFAULT_CUBASE_VERSION = 10
@sha1n
sha1n / until.py
Created March 23, 2020 10:54
Handy utility function for use in Python tests to wait for a state change triggered by an external or async source
from time import time, sleep
def wait_until(condition_eval_fn: Callable[[], bool], interval_sec: float, timeout_sec: float):
start_time = time()
while not condition_eval_fn() and time() - start_time < timeout_sec:
sleep(interval_sec)
if not condition_eval_fn():
raise TimeoutError("The condition has not been fulfilled within the specified {}s timeout".format(timeout_sec))
@sha1n
sha1n / public_ip_resolver.py
Last active March 11, 2020 10:28
An 'ipify.org' based public IP resolution code in Python
import http.client as http
def resolve_my_public_ip(timeout_sec=1.0):
print("Trying to resolve public IP...")
conn = http.HTTPSConnection(
host='api.ipify.org',
port=None,
timeout=timeout_sec,
)