Skip to content

Instantly share code, notes, and snippets.

View loverdos's full-sized avatar

Christos KK Loverdos loverdos

View GitHub Profile
@loverdos
loverdos / Logger.scala
Last active July 7, 2022 11:14
Logger with nested contexts
// Author: github.com/loverdos
// SPDX-License-Identifier: Apache-2.0
import java.io.PrintStream
final class Logger(out: PrintStream = System.out) {
private var ctx = List[String]()
private val indent_chunk = " "
private def ctx_size = ctx.length

Keybase proof

I hereby claim:

  • I am loverdos on github.
  • I am loverdos (https://keybase.io/loverdos) on keybase.
  • I have a public key ASAi41-Ewm_fgf0UGtN1aQEgDix-sDJp3LSsEyuXv4kgRgo

To claim this, I am signing this object:

@loverdos
loverdos / pbquote
Created March 1, 2016 15:54
Re-copy text as email-quoted
#!/bin/sh
# Re-copy text as email-quoted
pbpaste | sed 's/^/>/' | pbcopy
#!/usr/bin/env python
from os.path import expanduser
from ConfigParser import ConfigParser
from sys import argv
kamakirc = "%s/.kamakirc" % expanduser("~")
cfg=ConfigParser()
cfg.read(kamakirc)
@loverdos
loverdos / mvn-project-version.sh
Created May 20, 2015 10:07
Get maven project version from the shell
mvn help:evaluate -Dexpression=project.version | grep -e '^[^\[]'
trait TypeContainer {
type A
type B
type ABPlus
type C
}
trait TypeProjector[TC <: TypeContainer] {
type A = TC#A
type B = TC#B
@loverdos
loverdos / jvm-crasher.scala
Created December 30, 2014 09:10
JVM crasher
{ val u = classOf[sun.misc.Unsafe].getDeclaredField("theUnsafe")
u.setAccessible(true)
u.get(null).asInstanceOf[sun.misc.Unsafe]
} freeMemory 1024
@loverdos
loverdos / enhanced-match.scala
Created October 14, 2014 10:50
Enhanced Scala match with exception handling
// Inspired by latest OCaml
eval() match {
case v1 =>
case v2 =>
case _ =>
case catch e: Exception =>
case catch _ =>
case finally =>
implicit class GoodLord(val Good: Int) extends AnyVal {
def Lord = Good
}
// and then in a Scala prompt:
// scala> 1.Good.Lord
// res0: Int = 1
// Also:
// scala> 1.Good.Lord.Good.Lord.Good.Lord
@loverdos
loverdos / gist:e8bc5d264dc1524f011a
Created April 30, 2014 14:38
Enable mosh ports on a server
iptables -I INPUT 1 -p udp --dport 60000:61000 -j ACCEPT
service iptables save