Skip to content

Instantly share code, notes, and snippets.

@tors42
tors42 / zen-give-time.jsh
Created April 30, 2024 22:34
Java tool to give time to opponent
if (! Files.exists(Path.of("chariot.jar"))) {
Files.write(Path.of("chariot.jar"), URI.create(
"https://repo1.maven.org/maven2/io/github/tors42/chariot/0.0.87/chariot-0.0.87.jar"
).toURL().openStream().readAllBytes());
}
/env --class-path chariot.jar
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;
import java.util.prefs.Preferences;
@tors42
tors42 / puzzles.jsh
Created April 28, 2024 16:39
Download 9 months of solved puzzles into file puzzles.txt
if (! Files.exists(Path.of("chariot.jar"))) {
Files.write(Path.of("chariot.jar"), URI.create(
"https://repo1.maven.org/maven2/io/github/tors42/chariot/0.0.87/chariot-0.0.87.jar"
).toURL().openStream().readAllBytes());
}
/env --class-path chariot.jar
var auth = chariot.Client.auth(
uri -> System.out.println("\nVisit the following URL to grant permission:\n\n" + uri),
pkce -> pkce.scope(chariot.Client.Scope.puzzle_read));
@tors42
tors42 / worst.jsh
Created April 20, 2024 12:00
Java (jshell) program to find "Top 10" worst accuracies (of analysed Lichess games)
String userId = "tors42"; // User to check "Top" 10 worst accuracies for
// Optional token (download a bit faster) https://lichess.org/account/oauth/token/create
String token = "";
if (! Files.exists(Path.of("chariot.jar"))) {
Files.write(Path.of("chariot.jar"), URI.create(
"https://repo1.maven.org/maven2/io/github/tors42/chariot/0.0.86/chariot-0.0.86.jar"
).toURL().openStream().readAllBytes());
@tors42
tors42 / missed-challenges.jsh
Created March 3, 2024 15:50
A script which uses the Lichess API to listen for events, in order to detect any missed challenges
if (! Files.exists(Path.of("chariot.jar"))) {
Files.write(Path.of("chariot.jar"), URI.create(
"https://repo1.maven.org/maven2/io/github/tors42/chariot/0.0.84/chariot-0.0.84.jar"
).toURL().openStream().readAllBytes());
}
/env --class-path chariot.jar
import java.time.LocalTime;
import java.util.prefs.Preferences;
@tors42
tors42 / tournaments.jsh
Created February 18, 2024 14:21
Download Team Arena and Swiss PGNs
if (! Files.exists(Path.of("chariot.jar"))) {
Files.write(Path.of("chariot.jar"), URI.create(
"https://repo1.maven.org/maven2/io/github/tors42/chariot/0.0.83/chariot-0.0.83.jar"
).toURL().openStream().readAllBytes());
}
/env --class-path chariot.jar
import chariot.Client;
import chariot.model.*
@tors42
tors42 / backup-studies.jsh
Created January 29, 2024 22:30
jshell script to backup studies into a single file
if (! Files.exists(Path.of("chariot.jar"))) {
Files.write(Path.of("chariot.jar"), URI.create(
"https://repo1.maven.org/maven2/io/github/tors42/chariot/0.0.82/chariot-0.0.82.jar"
).toURL().openStream().readAllBytes());
}
/env --class-path chariot.jar
import chariot.*;
import chariot.Client.*;
import chariot.model.*;
@tors42
tors42 / annotate.jsh
Created January 28, 2024 14:21
Annotate PGNs from input.pgn, with FEN of each move as PGN Tags and PGN Move comments - using JShell (Java)
Path inputFile = Path.of("input.pgn");
if (! Files.exists(inputFile)) {
System.out.println("Couldn't find input file " + inputFile);
return -1;
}
if (! Files.exists(Path.of("chariot.jar"))) {
Files.write(Path.of("chariot.jar"), URI.create(
"https://repo1.maven.org/maven2/io/github/tors42/chariot/0.0.82/chariot-0.0.82.jar"
@tors42
tors42 / puzzle-fen.jsh
Last active May 1, 2024 09:51
JShell script to get the FEN of a puzzle
if (! Files.exists(Path.of("chariot.jar"))) {
Files.write(Path.of("chariot.jar"), URI.create(
"https://repo1.maven.org/maven2/io/github/tors42/chariot/0.0.83/chariot-0.0.83.jar"
).toURL().openStream().readAllBytes());
}
/env --class-path chariot.jar
import chariot.Client;
import chariot.util.Board;
@tors42
tors42 / opponent-gone.jsh
Created December 20, 2023 20:10
Example chariot jshell script to trigger "opponent gone", runnable with lichess-org/lila-docker
if (Path.of("chariot-0.0.77.jar") instanceof Path chariot
&& ! Files.exists(chariot)) {
Files.write(chariot, URI.create(
"https://repo1.maven.org/maven2/io/github/tors42/chariot/0.0.77/chariot-0.0.77.jar"
).toURL().openStream().readAllBytes());
}
/env --module-path chariot-0.0.77.jar --add-module chariot
import chariot.*;
@tors42
tors42 / Games.java
Created January 29, 2023 13:54
Shows a list of Lichess Correspondence games, sorted by "urgency" to play a move
import java.time.*;
import java.util.function.Function;
import java.util.Comparator;
import chariot.model.Enums.Color;
import chariot.model.Enums.PerfType;
import chariot.model.Game;
import chariot.Client;
class Games {