Skip to content

Instantly share code, notes, and snippets.

View serkan-ozal's full-sized avatar

Serkan ÖZAL serkan-ozal

View GitHub Profile
@howardjohn
howardjohn / otel-trace.sh
Created July 11, 2023 14:44
Example of three different ways to use otel tracing in bash. See https://blog.howardjohn.info/posts/shell-tracing/
#!/bin/bash
# Usage: tracing::init [endpoint; default localhost:4317]
function tracing::init() {
export OTEL_EXPORTER_OTLP_ENDPOINT="${1:-${OTEL_EXPORTER_OTLP_ENDPOINT:-localhost:4317}}"
}
# Usage: tracing::auto::init [endpoint; default localhost:4317]
function tracing::auto::init() {
tracing::init
import sun.misc.Unsafe;
import java.io.IOException;
import java.lang.reflect.Field;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.channels.FileChannel;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
@trustin
trustin / git-trigger-build.sh
Last active January 22, 2024 05:14
git-trigger-build: Triggers a CI build by pushing an empty commit
#!/bin/bash -e
# Stash the staged files if any.
NEEDS_UNSTASH=0
if ! git diff --staged --exit-code >/dev/null; then
echo -ne '\033[1;32m'
echo -n 'Stashing the staged files'
echo -e '\033[0m'
git stash
NEEDS_UNSTASH=1
@apangin
apangin / VMFlags.java
Created January 27, 2021 23:23
Read and modify non-manageable JVM flags in runtime: macOS version
import sun.misc.Unsafe;
import javax.management.ObjectName;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.lang.reflect.Field;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.channels.FileChannel;
import java.nio.charset.StandardCharsets;
@apangin
apangin / vmoption.c
Created January 15, 2021 11:23
Change non-manageable JVM option in runtime
#include <jvmti.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
JNIEXPORT jint JNICALL
Agent_OnAttach(JavaVM* vm, char* options, void* reserved) {
if (options != NULL) {
int* addr = (int*)strtol(options, NULL, 0);
printf("vmoption [%p] = %d\n", addr, *addr); fflush(stdout);
@apangin
apangin / unmalloc.c
Created January 11, 2021 17:45
Avoid long TTSP pauses caused by Unsafe.allocateMemory/freeMemory
// Replaces implementation of Unsafe.allocateMemory/freeMemory
// to avoid long time-to-safepoint pauses.
//
// Compile: gcc -O3 -fno-omit-frame-pointer -fPIC -shared -olibunmalloc.so unmalloc.c
//
// Usage: java -agentpath:/path/to/libunmalloc.so ...
#include <jvmti.h>
#include <stdint.h>
#include <stdio.h>
@apangin
apangin / ChangeVMFlag.java
Created December 11, 2020 01:26
Change MaxJavaStackTraceDepth JVM flag in runtime
import sun.jvm.hotspot.debugger.Address;
import sun.jvm.hotspot.runtime.VM;
import sun.jvm.hotspot.tools.Tool;
import java.io.IOException;
import java.io.RandomAccessFile;
/**
* Changes -XX:MaxJavaStackTraceDepth flag to 1000000 in runtime
* without restarting the JVM.
# Source: https://stackoverflow.com/questions/50003378/automatically-set-listenerrule-priority-in-cloudformation-template
import random
import uuid
import traceback
import boto3
# Member must have value less than or equal to 50000
ALB_RULE_PRIORITY_RANGE = 1, 50000
@demdxx
demdxx / mysql_cosine_similarity.sql
Created July 18, 2020 19:33
Cosine Similarity implementation in MySQL
-- for calculation of norm vector --
DELIMITER $$
CREATE FUNCTION vector_norm( vector JSON )
RETURNS DOUBLE
READS SQL DATA
DETERMINISTIC
BEGIN
DECLARE array_length INTEGER(11);
DECLARE retval DOUBLE(19,2);
@djangofan
djangofan / Tracert.java
Last active December 17, 2023 15:31
Traceroute in Java
import java.io.IOException;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.UnknownHostException;
import java.util.Arrays;
import jpcap.JpcapCaptor;
import jpcap.JpcapSender;