Skip to content

Instantly share code, notes, and snippets.

View Dgiffone's full-sized avatar

Domenico Giffone Dgiffone

View GitHub Profile
import java.lang.constant.ClassDesc;
import java.lang.constant.DirectMethodHandleDesc;
import java.lang.constant.DirectMethodHandleDesc.Kind;
import java.lang.constant.MethodHandleDesc;
import java.lang.invoke.CallSite;
import java.lang.invoke.ConstantCallSite;
import java.lang.invoke.LambdaMetafactory;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
private async _runK6(metadata: RunK6Metadata, config: K6Options) {
const { queryName, outputFile } = metadata
// If "debug" true, log all HTTP responses
if (this.config.debug) config.httpDebug = 'full'
// Write the K6 configuration JSON to a temp file, to pass as CLI flag
const tmpConfig = path.join(__dirname, 'tmp', `${queryName}_config.json`)
await fs.outputJSON(tmpConfig, config)
@bokks
bokks / RegistrationPattern1.jsp
Last active January 6, 2021 20:35
This pattern shows how to easily perform Activity registration using pzRegisterActivity
/* This shows how to convert a regular SafeURL to a Dispatcher URL */
/* The normal URL would be like pyActivity=Work-.AttachmentStatus&AttachmentHandle=XXX */
/* When you pass the SafeURL to pega.u.d.convertToRunActivityAction(oSafeURL) , the URL becomes a dispatcher */
/* pyActivity=pzRunActionWrapper&pzActivity=Work-.AttachmentStatus&AttachmentHandle=XXX&pzActivityParams=AttachmentHandle */
/* pzRegisterActivity or long form of registration works only with such Dispatcher URLs */
<script>
function CheckAttachmentStatus(LinkHandle,strAttachmentHandle)
{
var oSafeURL= new SafeURL("Work-.AttachmentStatus",getReqURI());
@lamngockhuong
lamngockhuong / ConsumeHeap.java
Created May 3, 2019 07:19 — forked from mosheeshel/ConsumeHeap.java
Function to fill JVM/Java Heap, Java options to automatically create a Heapdump on that event and a companion script to upload resulting files to S3
import java.io.IOException;
import java.util.Vector;
/**
* Created by moshee
* on: 07/06/17
* to compile in place: `javac ConsumeHeap.java`
* Execute: `java -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/app-`date +%s`-pid$$.hprof -XX:OnOutOfMemoryError=/opt/app/bin/upload_dump_s3.sh -Xmx2m ConsumeHeap`
* HeapDumpOnOutOfMemoryError specifies to automatically create a dump when OOM occures
* HeapDumpPath supplies a path to put that file
@rponte
rponte / HowToUseIt.java
Last active December 30, 2023 14:37
THEORY: Example of a simple Single Thread Pool implementation in Java
public class HowToUseIt {
/**
* Usually we'll have a single instance per client
*/
private static final SingleThreadPool THREAD_POOL = new SingleThreadPool();
public void executeAsync() {
try {
@jdillon222
jdillon222 / heapdumps.sh
Last active February 8, 2020 11:07
Java heap dump script (currently for dev instances)
#!/bin/bash
#######################################################################
#############################Heapdumps.sh #############################
#######################################################################
## ##
## Heapdumps.sh provides a means for triggering Java heap records ##
## of the main JVM process on EC2 instances. ##
## Records will be added to a temporary directory in /var/temp ##
## and then transferred to an S3 bucket named ____ ##
@miguno
miguno / gist:548cd72eaec017c475448cb9b2ced258
Last active April 7, 2023 19:24
Taking Java JVM memory snapshots with gdb and jmap (for YourKit)

Notes

  • Good: very quick snapshotting even for large heap spaces (e.g. works if your JVM process would otherwise timeout and die)
  • Bad: such a memory snapshot contains significantly less useful information than YourKit's "enhanced" memory snapshots.

Usage

# 1. Find the relevant JVM pid on the target machine
$ ps ...

Thread Pools

Thread pools on the JVM should usually be divided into the following three categories:

  1. CPU-bound
  2. Blocking IO
  3. Non-blocking IO polling

Each of these categories has a different optimal configuration and usage pattern.

@mosheeshel
mosheeshel / ConsumeHeap.java
Last active August 28, 2023 12:20
Function to fill JVM/Java Heap, Java options to automatically create a Heapdump on that event and a companion script to upload resulting files to S3
import java.io.IOException;
import java.util.Vector;
/**
* Created by moshee
* on: 07/06/17
* to compile in place: `javac ConsumeHeap.java`
* Execute: `java -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/app-`date +%s`-pid$$.hprof -XX:OnOutOfMemoryError=/opt/app/bin/upload_dump_s3.sh -Xmx2m ConsumeHeap`
* HeapDumpOnOutOfMemoryError specifies to automatically create a dump when OOM occures
* HeapDumpPath supplies a path to put that file
@0x263b
0x263b / colors.md
Last active May 16, 2024 09:59
Random color from string in javascript

Random color from string in javascript

Consider a list of strings you need to permanently assign a random color.

First you should turn the string into a hash.

var string = "string"
var hash = 0