Skip to content

Instantly share code, notes, and snippets.

View SortySort.java
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";
}
View SplitByCurrencySymbol.md

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;
View RemapCollectionKeys.java
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);
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 {
@JvmStatic
@akarnokd
akarnokd / main.py
Created Jan 28, 2022
Python script to convert Imperium Galactica's SMP files into WAV files
View main.py
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),
View Mapper.java
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;
View RepeatWhenExample.java
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 {
View BehaviorSubjectSignals.java
import org.junit.Test;
import io.reactivex.disposables.*;
import io.reactivex.subjects.BehaviorSubject;
public class BehaviorSubjectSignals {
@Test
public void test() throws Exception {
View p22_resistances.txt
alien
{ level: 1, dr: 50, er: 100, rr: 250, fr: 100, cr: 1000, pr: 100 },
{ level: 32, dr: 50, er: 100, rr: 250, fr: 100, cr: 1000, pr: 100 },
{ level: 42, dr: 50, er: 100, rr: 250, fr: 100, cr: 1000, pr: 100 },
{ level: 52, dr: 50, er: 100, rr: 250, fr: 100, cr: 1000, pr: 100 },
{ level: 100, dr: 50, er: 100, rr: 250, fr: 100, cr: 1000, pr: 100 },
angler
{ level: 15, dr: 150, er: 125, rr: 350, fr: 125, cr: 125, pr: 125 },
{ level: 25, dr: 150, er: 125, rr: 350, fr: 125, cr: 125, pr: 125 },
{ level: 37, dr: 150, er: 125, rr: 350, fr: 125, cr: 125, pr: 125 },
View xp.csv
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
Enemy Level Base INT Team Rested Relish Inspire Double XP Ingame
Super Mutant 48 102.8 11 2 5 10 15 100 372
Super Mutant 48 102.8 11 2 5 10 10 100 356
Super Mutant 48 102.8 11 2 5 10 5 100 344
Super Mutant 48 102.8 11 2 5 10 0 100 328
Super Mutant 48 102.8 11 4 0 0 15 100 340
Super Mutant 48 102.8 11 4 0 6 15 100 356
Super Mutant 48 102.8 11 3 0 6 15 100 352
Super Mutant 48 102.8 11 3 0 6 10 100 336
Super Mutant 48 102.8 11 3 0 6 5 100 320