Skip to content

Instantly share code, notes, and snippets.

View adriansr's full-sized avatar

Adrian Serrano adriansr

View GitHub Profile
/* stress test a JUnit test
given your test body:
feature(a) {
}
...
feature(c) {
}
wrap it:
class LoggingScheduledThreadPoolExecutor(nthreads: Int)
extends ScheduledThreadPoolExecutor(nthreads) {
private val log = Logger(LoggerFactory.getLogger(classOf[LoggingScheduledThreadPoolExecutor]))
override def submit[T](task: Runnable, result: T): java.util.concurrent.Future[T] = {
val queueTime = System.nanoTime()
log debug s"Submit task $task"
super.submit(new Runnable {
class LoggingScheduledThreadPoolExecutor(nthreads: Int)
extends ScheduledThreadPoolExecutor(nthreads) {
private val log = Logger(LoggerFactory.getLogger(classOf[LoggingScheduledThreadPoolExecutor]))
class CustomTask[T](runnable: AnyRef, task: RunnableScheduledFuture[T])
extends RunnableScheduledFuture[T] {
val creationTime = System.nanoTime()
@adriansr
adriansr / RaceMain.scala
Last active February 2, 2017 16:55
Akka actor creation/deletion race-condition
package adriansr.test
import scala.util.control.NonFatal
import akka.actor.{Actor, ActorRef, ActorSystem, InvalidActorNameException, Props}
case class Test(name: String, retries: Int, delay: Long)
case class Create(iter: Long, cfg: Test)
case class Remove(iter: Long, actor: ActorRef, cfg: Test)
@adriansr
adriansr / codegen.py
Last active August 1, 2017 09:51
REST resource code gen
import sys
# Writes the body of a REST resource
# input is a list of <type> <name> variables, one per line:
# i.e:
# String nwDstAddress
# int nwDstLength
# UUID[] inPorts
# [...]
# helloWorld => HELLO_WORLD
@adriansr
adriansr / wherefroms.go
Created December 21, 2017 00:35
Read kMDItemWhereFroms in Go
package main
/*
#include <stdlib.h>
#include <sys/xattr.h>
*/
import "C"
import (
"fmt"
@adriansr
adriansr / main.go
Created January 11, 2018 14:56
GetExtendedTcpTable golang
// +build windows
package main
import (
"encoding/binary"
"encoding/hex"
"fmt"
"syscall"
"time"
@adriansr
adriansr / pkgcleanup.sh
Created February 6, 2018 22:10
Uninstall macOS pkg removing all files
#!/bin/bash
die() {
echo "error: $@" >&2
exit 1
}
test "$#" -gt 0 || die "Usage: $0 <package identifier>"
test "$(uname -s)" = "Darwin" || die "Must be run under macOS"
test $(id -u) -eq 0 || die "Must be root"
@adriansr
adriansr / svg2icns.sh
Created February 19, 2018 15:21
Convert SVG file to macOS icon (icns) format
#!/bin/sh -x
set -e
SIZES="
16,16x16
32,16x16@2x
32,32x32
64,32x32@2x
128,128x128
@adriansr
adriansr / syscall_stress.go
Last active January 4, 2022 15:19
Call a syscall in a loop, optionally limiting the number of calls per second
package main
import (
"sync/atomic"
"fmt"
"os"
"strconv"
"syscall"
"time"
)