Skip to content

Instantly share code, notes, and snippets.

View serkan-ozal's full-sized avatar

Serkan ÖZAL serkan-ozal

View GitHub Profile
@serkan-ozal
serkan-ozal / gist:b6a9701801279736e5ec
Created February 8, 2015 11:54
A Hacky Way to Clean All Thread Local Variables of Current Thread
void cleanThreadLocalsOfCurrentThread() {
try {
// Get a reference to the thread locals table of the current thread
Thread thread = Thread.currentThread();
Field threadLocalsField = Thread.class.getDeclaredField("threadLocals");
threadLocalsField.setAccessible(true);
Object threadLocalTable = threadLocalsField.get(thread);
// Get a reference to the array holding the thread local variables inside the
// ThreadLocalMap of the current thread
Runtime JDK 21, Java HotSpot(TM) 64-Bit Server VM, 21+35-LTS-2513
Benchmark tool JMH (version 1.37)
Benchmark mode Throughput, ops/time
Warmup iteration 3
Warmup time 5 seconds (for each warmup iteration)
Measurement iteration 10
Measurement time 30 seconds (for each measurement iteration)
Vector length 1000
Algorithm / OS Ubuntu Window MacOS
Dot Product 750,622.625 ops/s 760,163.774 ops/s 961,366.490 ops/s
Cosine Similarity 586,113.920 ops/s 705,148.739 ops/s 892,124.358 ops/s
Manhattan Distance 793,538.457 ops/s 717,150.911 ops/s 1,156,442.603 ops/s
Euclidean Distance 760,819.826 ops/s 748,286.320 ops/s 1,012,210.232 ops/s
Runner OS Processor (CPU) Memory (RAM)
ubuntu-latest Ubuntu - 22.04 Model: Intel Xeon E5-2673 v4 @ 2.30GHz # of cores: 2 7 GB
windows-latest Windows - 2022 Model: Xeon® Platinum 8272CL # of cores: 2 7 GB
macos-latest MacOS - 12 Model: Intel Xeon E5-1650 v2 @ 3.50GHz # of cores: 3 14 GB
Runner OS Processor (CPU) Memory (RAM)
ubuntu-latest Ubuntu - 22.04 - Model: Intel Xeon E5-2673 v4 @ 2.30GHz
- # of cores: 2
7 GB
windows-latest Windows - 2022 - Model: Xeon® Platinum 8272CL
- # of cores: 2
7 GB
macos-latest MacOS - 12 - Model: Intel Xeon E5-1650 v2 @ 3.50GHz
- # of cores: 3
14 GB
const AWS = require('aws-sdk');
const dynamodb = new AWS.DynamoDB();
exports.hello = async (event, context) => {
const promises = [];
for (let i = 0; i < 1000; i++) {
const params = {
TableName: 'books',
Item: {
'id': {S: i.toString()},
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonStreamContext;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.ser.BeanSerializerModifier;
import com.fasterxml.jackson.databind.ser.PropertyWriter;
import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter;
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;
import com.fasterxml.jackson.databind.type.*;

How to setup AWS lambda function to talk to the internet and VPC

I'm going to walk you through the steps for setting up a AWS Lambda to talk to the internet and a VPC. Let's dive in.

So it might be really unintuitive at first but lambda functions have three states.

  1. No VPC, where it can talk openly to the web, but can't talk to any of your AWS services.
  2. VPC, the default setting where the lambda function can talk to your AWS services but can't talk to the web.
  3. VPC with NAT, The best of both worlds, AWS services and web.
@serkan-ozal
serkan-ozal / gist:4ec4cbb128645a80ea25
Created November 8, 2014 09:19
Sample working JNI code to get address of given object, to get object at given address and pin/unpin given object to memory for not to be collected by GC
/**
* @author SERKAN OZAL
*
* E-Mail: <a href="mailto:serkanozal86@hotmail.com">serkanozal86@hotmail.com</a>
* GitHub: <a>https://github.com/serkan-ozal</a>
*/
#include <jni.h>
#include "tr_com_serkanozal_jvm_playground_MemoryUtil.h"
@serkan-ozal
serkan-ozal / TransformableClassLoaderWhisperer.java
Created July 12, 2017 04:43
TransformableClassLoaderWhisperer - Add `ClassFileTransformer`s on the fly without Java agent
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.IllegalClassFormatException;
import java.lang.reflect.Field;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Enumeration;
import java.util.List;