Skip to content

Instantly share code, notes, and snippets.

View loganmzz's full-sized avatar
🐒
Doing some stuff with K8S, CF and Rust

Logan Mzz loganmzz

🐒
Doing some stuff with K8S, CF and Rust
View GitHub Profile
@loganmzz
loganmzz / StampedLockExample.java
Last active September 23, 2015 21:00
Strange behaviour about StampedLock.unlock for read stamp
public class StampedLockExample {
static StampedLock lock = new StampedLock();
static void println(String message, Object... args) {
System.out.printf(message, args);
System.out.println();
}
static void printReadLockCount() {
println("Lock count=%d", lock.getReadLockCount());
@loganmzz
loganmzz / StackMemoryExhaustation.java
Created September 30, 2015 13:37
Generates Stack memory exhaustation
//Sets -Xss128k
public class StackMemoryExhaustation {
public static void stackConsumer(long stackSize) {
long a000 = 1;
long a001 = a000 + 1;
long a002 = a001 + 1;
long a003 = a002 + 1;
long a004 = a003 + 1;
long a005 = a004 + 1;
@loganmzz
loganmzz / BasicMonitor.java
Created October 8, 2015 22:09
Simple monitoring API (Java 8 based)
public class BasicMonitor implements Monitor {
private Map<String, Stat> stats;
private Function<String, Stat> statBuilder;
public BasicMonitor(Collection<String> keys) {
Thread currentThread = Thread.currentThread();
long threadId = currentThread.getId();
String threadName = currentThread.getName();
statBuilder = name -> new Stat(threadId, threadName, name);
@loganmzz
loganmzz / Executor.java
Created October 8, 2015 22:41
Multithread run helper
/**
* <p>Multi-threaded run helper.</p>
* <p>Based on few parameters, launch a fixed number of task and wait a given amount of time before
* interrupting them and give back execution results</p>
*/
public class Executor {
/** Makes tasks starting at the same time **/
public boolean syncStartup = true;
/** Number of task to run in parallel **/
@loganmzz
loganmzz / bootsync.sh
Last active April 6, 2016 11:16
Docker boot to append certificates
#!/bin/sh
#To drop in /var/lib/boot2docker/bootsync.sh
echo "Appending custom ca-certificates"
for file in /var/lib/boot2docker/certs/*.pem; do
echo " - Append $file"
cat "$file" >> /etc/ssl/certs/ca-certificates.crt
done
echo "Appending custom ca-certificates (complete)"
@loganmzz
loganmzz / ReactiveTaskDispatch.java
Created March 2, 2017 15:07
Reactor - Task dispatching example
package com.github.loganmzz.labo.reactor.samples;
import reactor.core.publisher.Flux;
import reactor.core.publisher.ParallelFlux;
import reactor.core.scheduler.Scheduler;
import reactor.core.scheduler.Schedulers;
import java.util.Date;
import java.util.concurrent.ThreadLocalRandom;
@loganmzz
loganmzz / code.swift
Created May 16, 2017 19:25
MKTD Banana Island
let myName = "Capucin"
var isOver = false
public init() {
// Nothing
}
public func play(_ game:Game, _ teamId:Int) -> Direction {
print("Team ID: \(teamId)")
@loganmzz
loganmzz / ceylon-compile.sh
Created August 11, 2017 20:14
Compile many Ceylon source directories
#!/bin/sh
echo "Merging src-* directories into source"
rm -rf "source"
mkdir -p "source"
for source in src-*; do
echo " -- Merging ${source}"
cp -r "${source}"/* "source"
done
@loganmzz
loganmzz / RandomReader.java
Created January 24, 2018 16:31
Java Random Reader
package org.apache.jmeter.services;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.charset.Charset;
import java.util.concurrent.ThreadLocalRandom;
def chars = [
'a'..'z', '0'..'9',
// 'àâäéèêëìîïòôöùûüÿçñ',
'@#&!=+$£€*?,;.:-_(){}[]'
]
def printChars(list) {
println(list.join().replaceAll(/[\[\]-]/, /\\$0/))
}