Skip to content

Instantly share code, notes, and snippets.

View AngryCarrot789's full-sized avatar
💣
Baboom

REghZy AngryCarrot789

💣
Baboom
View GitHub Profile
@AngryCarrot789
AngryCarrot789 / InputDrivenTaskExecutor.cs
Last active August 13, 2023 16:49
Executes user code no less than a certain minimum interval, every time an input function is called
using System;
using System.Threading.Tasks;
namespace FramePFX.Utils {
/// <summary>
/// A class used for executing a tasks when an input signal is received, and ensuring the task is not
/// executed too quickly (time since last execution will exceed <see cref="MinimumInterval"/>)
/// </summary>
public class InputDrivenTaskExecutor {
private volatile bool condition;
@AngryCarrot789
AngryCarrot789 / Memory.java
Created January 22, 2022 07:05
Move array element to the end of an array
public static <T> void moveElementToEnd(T[] array, int index) {
T element = array[index];
System.arraycopy(array, index + 1, array, index, array.length - index - 1);
array[array.length - 1] = element;
}
@AngryCarrot789
AngryCarrot789 / NMSAPI.java
Last active December 15, 2021 09:26
NMSAPI - conversion between minecraft source and bukkit
package reghzy.api.utils;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.server.v1_6_R3.MinecraftServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityChest;
import net.minecraft.world.ChunkPosition;
@AngryCarrot789
AngryCarrot789 / TickUnit.java
Last active February 29, 2024 02:09
A utility class for converting between time units and ticks (e.g days in ticks, ticks to hours, etc)
package reghzy.api.utils;
import java.util.concurrent.TimeUnit;
public class TickUnit {
private static final double C1d = 50000000.0d;
private static final double C2d = 50000.0d;
private static final double C3d = 50.0d;
private static final double C4d = 20.0d;
private static final double C5d = 1200.0d;
@AngryCarrot789
AngryCarrot789 / KVObjectCache.java
Last active December 15, 2021 09:26
Used for caching a hashmap's last accessed value, by caching the last accessed key and checking for equality, then returning that last accessed value if it matches
package reghzy.api.utils;
public abstract class KVObjectCache<K, V> {
private K lastAccessedKey;
private V lastAccessedValue;
public V get(K key) {
if (key == null) {
this.lastAccessedKey = null;
this.lastAccessedValue = getValue(null);
@AngryCarrot789
AngryCarrot789 / SliderDefaultValues.cs
Created October 23, 2021 08:07
Slider set value to a default value using middle mouse button click
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media.Animation;
namespace ControlsLib.AttachedProperties {
public static class SliderDefaultValues {
public static readonly DependencyProperty IsEnabledProperty =
DependencyProperty.RegisterAttached(