Skip to content

Instantly share code, notes, and snippets.

View rainbowdashlabs's full-sized avatar
🦊
foxy

Lilly Tempest rainbowdashlabs

🦊
foxy
View GitHub Profile
@rainbowdashlabs
rainbowdashlabs / CustomRadixNotation.java
Last active November 29, 2022 15:01
A custom radix notation class. Allows to encode and decode numbers created with a custom radix notation.
/*
* SPDX-License-Identifier: MIT
*
* Copyright (C) 2022 RainbowDashLabs
*/
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
@rainbowdashlabs
rainbowdashlabs / check.sql
Created October 25, 2022 12:33
List size of tables, materialized views and views in your PostgreSQL database.
WITH
tables AS (
SELECT
oid::REGCLASS::TEXT AS table_name,
CASE relkind
WHEN 'm' THEN 'materialized_view'
WHEN 'r' THEN 'table'
WHEN 'v' THEN 'view'
END AS type
FROM
@rainbowdashlabs
rainbowdashlabs / setup.sh
Last active May 20, 2022 11:35
Reputation bot setup
echo "Create a directory for our bot"
mkdir repbot
# Enter it
cd repbot
# Get the reputation bot repository
git clone https://github.com/RainbowDashLabs/reputation-bot.git repo
echo "Copy logging config into config directory"
mkdir config
cp repo/src/main/resources/log4j2.xml config/log4j2.xml
echo "Getting scripts for running and upgrading"
@rainbowdashlabs
rainbowdashlabs / InventoryContainer.java
Last active December 22, 2022 12:24
Classes which allows to serialize and deserialize bukkit classes which implements the ConfigurationSerializable interface using GSON or others via adapters
import org.bukkit.Material;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import java.util.Arrays;
import java.util.List;
public class InventoryContainer {
private final List<SerializeContainer> contents;
@rainbowdashlabs
rainbowdashlabs / snowflake_to_unix.sql
Last active March 28, 2022 12:04
Convert a discord snowflake to unix timestamp using PostgreSQL
CREATE FUNCTION snowflake_to_unix_timestamp(snowflake BIGINT) RETURNS TIMESTAMP
LANGUAGE plpgsql
PARALLEL SAFE
IMMUTABLE
AS
$BODY$
BEGIN
-- message_id::BIT(64) AS bits
-- bits::BIT(42) AS timestamp_bits
-- timestamp_bits::BIGINT AS discord_epoch
@rainbowdashlabs
rainbowdashlabs / loop.sh
Created September 11, 2021 14:02
Recover, restart and upgrade your process via exit codes with bash
#!/bin/bash
# switch to config directory
while true; do
# Of course you can use any other executable file here. We use java.
java \
-Xms256m \
-Xmx2048m \
@rainbowdashlabs
rainbowdashlabs / AdventureComponentAdapter.java
Last active August 27, 2021 17:14
ProtocolLib cant read the components in chat packets when using adventure. This workaround allows reading of the content on servers using adventure and those who are not
// Workaround for https://github.com/aadnk/ProtocolLib/issues/191/
package de.eldoria.util;
import com.comphenix.protocol.events.PacketContainer;
import net.kyori.adventure.text.TextComponent;
import java.util.function.Function;
import java.util.logging.Level;
public class AdventureComponentAdapter {
@rainbowdashlabs
rainbowdashlabs / sh
Last active June 15, 2021 16:44
disney plus pin finder in bash
#!/bin/bash
# This script can help you when you forgot the pin for your disney plus profile.
# Dont use it to get access to other members of your account. This is only for your own profile :3
# Arguments: <start> <end> <profile_id> <token>
# start and end are the first and last pin to be checked. zeros will be added by the script.
# the profile id can be found in the url url when you have to enter your pin
# the token can be found in any request which requires authentification. try a pin to get it for example.
# the token has to be entered without the "Bearer" in front of it.
FIRST=$1
LAST=$2
@rainbowdashlabs
rainbowdashlabs / PluginDataHolder.java
Created April 14, 2021 15:03
A basic PluginDataHolder to use as parent class for Dataclasses which should query data from a database via a data source.
import org.bukkit.plugin.Plugin;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.logging.Level;
public abstract class PluginDataHolder {
private final DataSource source;
private final Plugin plugin;
@rainbowdashlabs
rainbowdashlabs / BukkitAsyncAction.java
Last active April 13, 2021 19:09
BukkitAsyncAction
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitScheduler;
import javax.annotation.CheckReturnValue;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.logging.Level;
public final class BukkitAsyncAction<T> {