Skip to content

Instantly share code, notes, and snippets.

View JohnnyJayJay's full-sized avatar
🏔️
Now on Codeberg

Johnny JohnnyJayJay

🏔️
Now on Codeberg
View GitHub Profile
@JohnnyJayJay
JohnnyJayJay / TableBuilder.java
Last active August 12, 2024 20:04
A util class to build table-like Strings in Java. Free to use (see UNLICENSE)
import java.util.Arrays;
import java.util.Objects;
/**
* A utility class that can be used to easily create String tables in Java without any extra frameworks.
* This can be useful to display table-like structures in Discord codeblocks, for example.
*
* <p>If framing is activated, the tables usually look like this (but with box drawing characters):
* <code>
* ------------------------------------
@JohnnyJayJay
JohnnyJayJay / EventExpecter.java
Last active September 12, 2022 03:40
Event Waiter für Spigot und faule Menschen, die Inventar Menüs wollen
package com.github.johnnyjayjay.testplugin;
import org.bukkit.Bukkit;
import org.bukkit.event.Event;
import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import java.util.function.Consumer;
@JohnnyJayJay
JohnnyJayJay / CatBot.kt
Created March 7, 2019 21:44
Bot that sends a random cat pic if you ping it. Needs kotlin and khttp and jda as dependencies.
import net.dv8tion.jda.core.JDABuilder
import net.dv8tion.jda.core.events.GuildMessageReceivedEvent
import khttp.get
import org.json.JSONObject
fun main(args: Array<String>) {
JDABuilder("bot token").addEventListener(event -> {
if (event is GuildMessageReceivedEvent && event.guild.selfMember in event.message.mentionedMembers) {
val response = get("https://api.thecatapi.com/v1/images/search", headers = mapOf("x-api-key" to "key"))
val cat = (response.jsonArray[0] as JSONObject).getString("url")
@JohnnyJayJay
JohnnyJayJay / KotlinMessageUtils.kt
Created April 1, 2019 15:12
Utilities for JDA discord bots created with the kotlin programming language
package com.github.johnnyjayjay.titanbot.utils
import net.dv8tion.jda.core.EmbedBuilder
import net.dv8tion.jda.core.MessageBuilder
import net.dv8tion.jda.core.entities.Message
import net.dv8tion.jda.core.entities.MessageEmbed
import net.dv8tion.jda.core.entities.MessageEmbed.*
import java.awt.Color
import java.time.Instant
import java.time.temporal.TemporalAccessor
import java.util.concurrent.TimeUnit;
import java.util.Map;
import java.util.HashMap;
import java.util.function.Function;
public class RateLimiter<T> {
private final long rateLimit;
private final Function<T, ?> keyMapper;
private final Map<?, Long> timestamps;
@JohnnyJayJay
JohnnyJayJay / EventExpecter.java
Last active July 9, 2019 17:47
modified event waiter from jda-utilities for jda 4 alpha
import net.dv8tion.jda.api.events.GenericEvent;
import net.dv8tion.jda.api.hooks.EventListener;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.*;
import org.bukkit.command.*;
public final class DelegatingCommand implements CommandExecutor {
private final Map<String, ? extends CommandExecutor> children;
private final CommandExecutor defaultCase;
public DelegatingCommand(Map<String, ? extends CommandExecutor> children) {
this((s, c, l, a) -> false, children);
@JohnnyJayJay
JohnnyJayJay / main.py
Created September 2, 2019 17:15
vigenere cipher hacking script
import math
def duplicates(vigenere):
strings = []
duplicates = set()
for index in range(len(vigenere)):
string = ""
for i in range(3):
if index + i < len(vigenere):
string += vigenere[index + i]
def extended_euclidian(a, b):
if b == 0:
return a, 1, 0
gcd, s, t = extended_euclidian(b, a % b)
s, t = t, s - int(a / b) * t
return gcd, s, t
print("Alphabet length:")
length = int(input())
print("Key:")
@JohnnyJayJay
JohnnyJayJay / rsa.py
Last active September 23, 2019 20:22
RSA key generation and en-/decryption implementation
import random
import string
def crypt(key, str):
x, n = key
return string.join([chr(c) for c in map(lambda element: (element ** x) % n, [ord(c) for c in str])])
def get_primes(r):
primes = []
for possible_prime in r: