NOTE: This is a question I found on StackOverflow which I’ve archived here, because the answer is so effing phenomenal.
If you are not into long explanations, see [Paolo Bergantino’s answer][2].
package org.tempura.console.util; | |
import java.util.ArrayList; | |
import java.util.Collections; | |
import java.util.List; | |
/** | |
* Usage: | |
* <li>String msg = Ansi.Red.and(Ansi.BgYellow).format("Hello %s", name)</li> | |
* <li>String msg = Ansi.Blink.colorize("BOOM!")</li> |
class Pouring(capacity: Vector[Int]) { | |
// States | |
type State = Vector[Int] | |
val initialState = capacity map (x => 0) | |
// Moves | |
trait Move { | |
// A method that defines state changes | |
def change(state: State): State |
/** | |
* A tiny class that extends a list with four combinatorial operations: | |
* ''combinations'', ''subsets'', ''permutations'', ''variations''. | |
* | |
* You can find all the ideas behind this code at blog-post: | |
* | |
* http://vkostyukov.ru/posts/combinatorial-algorithms-in-scala/ | |
* | |
* How to use this class. | |
* |
package sandbox; | |
import java.lang.reflect.Field; | |
import java.lang.reflect.Modifier; | |
public class MainSandBox { | |
public static void main(String[] args) throws Exception { | |
Example ex = new Example(); | |
// Change private modifier to public | |
Field f = ex.getClass().getDeclaredField("id"); |
NOTE: This is a question I found on StackOverflow which I’ve archived here, because the answer is so effing phenomenal.
If you are not into long explanations, see [Paolo Bergantino’s answer][2].
// Base64 encode | |
val text = "This is plaintext." | |
val bytesEncoded = java.util.Base64.getEncoder.encode(text.getBytes()) | |
// Base64 decode | |
val textDecoded = new String(java.util.Base64.getDecoder.decode(bytesEncoded)) | |
println(textDecoded) |
# SGR color constants | |
# rene-d 2018 | |
class Colors: | |
""" ANSI color codes """ | |
BLACK = "\033[0;30m" | |
RED = "\033[0;31m" | |
GREEN = "\033[0;32m" | |
BROWN = "\033[0;33m" | |
BLUE = "\033[0;34m" |