Skip to content

Instantly share code, notes, and snippets.

@akarnokd
akarnokd / FusionReactorFix.java
Created April 22, 2024 12:21
The Planet Crafter Fusion Reactor Fixer
package hu.akarnokd.theplanetcrafter;
import java.nio.charset.StandardCharsets;
import java.nio.file.*;
import java.util.*;
import java.util.regex.Pattern;
public class FusionReactorFix {
public static void main(String[] args) throws Throwable {
script.on_event(defines.events.on_player_setup_blueprint, 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
end
local bp_ents = bp.get_blueprint_entities()
if bp_ents then
local source = event.mapping.get()
for i, entity in pairs(bp_ents) do
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[ingredient.name] = math.min(alimit, ingredient.amount + 1)
else
limits[ingredient.name] = ingredient.amount + 1
script.on_event({
defines.events.on_built_entity,
defines.events.on_robot_built_entity,
defines.events.script_raised_built,
defines.events.script_raised_revive,
}, function(event)
handleEntityPlaced(event.created_entity)
end)
script.on_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()
.stream()
.flatMap(kv -> kv.getKey().stream().map(k -> Map.entry(k, kv.getValue())))
.collect(Collectors.toMap(k -> k.getKey(), v -> v.getValue()));
result.entrySet().forEach(System.out::println);
@akarnokd
akarnokd / main.py
Created January 28, 2022 23:13
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;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.Test;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.observers.TestObserver;
import io.reactivex.rxjava3.schedulers.TestScheduler;
public class RepeatWhenSO {