Skip to content

Instantly share code, notes, and snippets.

### Keybase proof
I hereby claim:
* I am jodersky on github.
* I am jodersky (https://keybase.io/jodersky) on keybase.
* I have a public key whose fingerprint is 4E7D A7B5 A0F8 6992 D6EB 3F51 4601 8786 62E3 3372
To claim this, I am signing this object:
@jodersky
jodersky / risk
Created September 5, 2016 22:11
Simulate attack scenarios in a classic Risk game.
#!/usr/bin/env scala
import math._
import scala.util.Random
val Iterations = 100000
val MaxAttackers = 15
val MaxDefenders = 15
/** Randomly simulates a complete attack (until there are either no attackers or defenders left).
object Main extends App {
type Succ[A] <: Shape
type _0 <: Shape
type _1 = Succ[_0]
type _2 = Succ[_1]
type _3 = Succ[_2]
type Shape
@jodersky
jodersky / MacroFormats.scala
Created August 26, 2017 22:24
Spray-JSON formats for product types, automatically provided with the use of macros.
package spray.json
import scala.language.experimental.macros
import scala.reflect.macros.blackbox.Context
trait MacroFormats {
def macroReader[A]: RootJsonReader[A] = macro MacroFormatsBundle.jsonReader[A]
def macroWriter[A]: RootJsonWriter[A] = macro MacroFormatsBundle.jsonWriter[A]
#!/bin/bash
# Manage a collection of github mirrors.
#
# This script provides functionality to clone and update git
# repositories as mirrors. The update functionality is silent on
# successful updates and is designed to be called in an automated way,
# such as with cron.
#
# All mirror repositories are assumed to be contained under one base
# directory (by default ~/public_git), configurable via a flag.
@jodersky
jodersky / index.html
Last active October 6, 2018 20:43
Minimal CSS to format code as if it were displayed in a terminal
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<style type="text/css">
.term {
background-color: rgba(43,43,43,0.99);
color: rgb(169,183,198);
padding: 1em;
@jodersky
jodersky / loading.py
Created December 15, 2019 21:41
Loading animation for terminals
import time, sys, random
def loading(count):
all_progress = [0] * count
sys.stdout.write("\n" * count) # Make sure we have space to draw the bars
while any(x < 100 for x in all_progress):
time.sleep(0.01)
# Randomly increment one of our progress values
unfinished = [(i, v) for (i, v) in enumerate(all_progress) if v < 100]
index, _ = random.choice(unfinished)
all_progress[index] += 1
@jodersky
jodersky / pickler.scala
Created May 26, 2020 17:57
Simple ujson-based pickler using Dotty typeclass derivation
import scala.deriving._
import scala.compiletime.{erasedValue, summonInline}
// super primitive (but composable via typeclass derivation) JSON reader
trait Reader[A] {
def read(json: ujson.Value): A
}
object Reader {
given Reader[Int] = new Reader[Int] {
// The following code is from http://www.academicpub.org/PaperInfo.aspx?PaperID=14496 .
import java.math.BigInteger;
import java.security.*;
import java.security.spec.*;
import javax.crypto.KeyAgreement;
public class ECCKeyAgreement {
public static void main(String[] args) throws Exception {
KeyPairGenerator kpg;
kpg = KeyPairGenerator.getInstance("EC","SunEC");
@jodersky
jodersky / silenceask.scala
Last active August 30, 2020 21:42
Remove useless startup logs from jboss when starting cask
def silenceJboss(): Unit = {
// Some jboss classes don't have manners and think that it's ok to write to
// logs from their static initializers. This is a hack to silence this
// rather rude behaviour.
val tmp = System.out
System.setOut(null)
org.jboss.threads.Version.getVersionString() // this causes the static initializer to be run
System.setOut(tmp)
// Other loggers print way too much information. Set them to only print