Skip to content

Instantly share code, notes, and snippets.

package blog;
import java.util.List;
import rx.Observable;
public class WidgetAndArticles {
static final class Widget {
String articleName;
String articleUrl;
View on_player_setup_blueprint.lua
script.on_event(, function(event)
local player = game.get_player(event.player_index)
local bp = player.blueprint_to_setup
if not bp.valid_for_read then
bp = player.cursor_stack
local bp_ents = bp.get_blueprint_entities()
if bp_ents then
local source = event.mapping.get()
for i, entity in pairs(bp_ents) do
View transfer.lua
function transfer(sourceInventory, destinationInventory, recipe, alimit, tag)
if not destinationInventory then return end
local limits = { }
if recipe then
for _, ingredient in pairs(recipe.ingredients) do
if alimit then
limits[] = math.min(alimit, ingredient.amount + 1)
limits[] = ingredient.amount + 1
View control.lua
}, function(event)
import java.util.*;
public class SortySort {
public static String stringSorter(List<String> stringList, String sortingOrder) {
if ((stringList == null) || (stringList.isEmpty())) {
return "Given stringList or sortingOrder is empty, null or blank space";
if ((stringList.size() == 1)) {
return "The list contains an empty or blank space value";

You'll have to escape the currency symbol as it might be a reserved symbol in regex. Plus, splitting doesn't keep the symbol itself so you'll have to add it back manually:

String currency = "$"; // from your method

String escapedCurrency = Pattern.quote(currency);

String[] result = "$5".split(escapedCurrency, 2);
result[0] = currency;
Map<List<String>, String> map = new HashMap<>();
map.put(List.of("A", "B"), "X");
map.put(List.of("C"), "Y");
var result = map.entrySet()
.flatMap(kv -> kv.getKey().stream().map(k -> Map.entry(k, kv.getValue())))
.collect(Collectors.toMap(k -> k.getKey(), v -> v.getValue()));
View RepeatBench.kt
package hu.akarnokd.kotlin
import io.reactivex.rxjava3.core.Completable
import io.reactivex.rxjava3.schedulers.Schedulers
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
object RepeatBench {
akarnokd /
Created Jan 28, 2022
Python script to convert Imperium Galactica's SMP files into WAV files
import sys
import os.path
from os import listdir
from os.path import isfile, join
def int_to_bytes(uint):
return bytearray([
(uint & 0xFF),
((uint >> 8) & 0xFF),
static <T, R> Publisher<R> map(Publisher<T> upstream, Function<T, R> mapper) {
return downstream -> upstream.subscribe(new Mapper<>(downstream, mapper));
class Mapper<T, R> implements Subscriber<T> {
final Subscriber<? super R> downstream;
final Function<T, R> mapper;