Skip to content

Instantly share code, notes, and snippets.

View jboner's full-sized avatar

Jonas Bonér jboner

View GitHub Profile
@benjchristensen
benjchristensen / CallbackB.java
Last active January 16, 2024 15:09
CallbackB.java Example of using Callbacks for nested calls showing the incidental complexity that results and how eventually the asynchronous paths need to be synchronized together.
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
public class CallbackB {
/**
@viktorklang
viktorklang / SerializedExecutionContext.scala
Created January 17, 2013 00:32
Wraps an ExecutionContext into a new ExecutionContext which will execute its tasks in sequence, always.
import java.util.concurrent.ConcurrentLinkedQueue
import java.util.concurrent.atomic.AtomicInteger
import scala.concurrent.ExecutionContext
import scala.util.control.NonFatal
import scala.annotation.tailrec
object SerializedExecutionContext {
def apply(batchSize: Int)(implicit context: ExecutionContext): ExecutionContext = {
require(batchSize > 0, s"SerializedExecutionContext.batchSize must be greater than 0 but was $batchSize")
new ConcurrentLinkedQueue[Runnable] with Runnable with ExecutionContext {
private final val on = new AtomicInteger(0)
@viktorklang
viktorklang / ScalaEnum.scala
Created June 30, 2011 23:12
DIY Scala Enums (with optional exhaustiveness checking)
trait Enum { //DIY enum type
import java.util.concurrent.atomic.AtomicReference //Concurrency paranoia
type EnumVal <: Value //This is a type that needs to be found in the implementing class
private val _values = new AtomicReference(Vector[EnumVal]()) //Stores our enum values
//Adds an EnumVal to our storage, uses CCAS to make sure it's thread safe, returns the ordinal
private final def addEnumVal(newVal: EnumVal): Int = { import _values.{get, compareAndSet => CAS}
val oldVec = get
@wsargent
wsargent / docker_cheat.md
Last active August 31, 2023 12:10
Docker cheat sheet
@viktorklang
viktorklang / in-fino-veritas.zsh-theme
Last active July 31, 2023 01:47
In Fino Veritas ZSH theme
#!/usr/bin/env zsh
# in fino veritas
# Borrowing shamelessly from these oh-my-zsh themes:
# fino-time
# pure
# https://gist.github.com/smileart/3750104
# Set required options
@jpoehls
jpoehls / node-cluster-messaging.js
Created March 29, 2012 01:48
Simple message passing between cluster master and workers in Node.js
var cluster = require('cluster');
if (cluster.isWorker) {
console.log('Worker ' + process.pid + ' has started.');
// Send message to master process.
process.send({msgFromWorker: 'This is from worker ' + process.pid + '.'})
// Receive messages from the master process.
@heisters
heisters / Solarized High Contrast Dark.itermcolors
Created June 8, 2011 21:49
Solarized High Contrast Dark theme for iTerm2
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Ansi 0 Color</key>
<dict>
<key>Blue Component</key>
<real>0.19370138645172119</real>
<key>Green Component</key>
<real>0.15575926005840302</real>
@viktorklang
viktorklang / Actor.java
Last active February 13, 2023 12:13
Minimalist Java Actors
/*
Copyright 2012-2021 Viktor Klang
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
@patriknw
patriknw / LoggingMailbox.scala
Last active January 5, 2023 08:12
Logs the mailbox size when exceeding the configured limit. Implemented in Scala and Java. Copy one of them to your project and define the configuration. This code is licensed under the Apache 2 license.
/**
* Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com>
*/
package akka.contrib.mailbox
import scala.concurrent.duration._
import java.util.concurrent.atomic.AtomicInteger
import java.util.concurrent.atomic.AtomicLong
import com.typesafe.config.Config
import akka.actor.{ ActorContext, ActorRef, ActorSystem, ExtendedActorSystem }