Skip to content

Instantly share code, notes, and snippets.

View Scarsz's full-sized avatar
🐒
Programming Primate

Austin Shapiro Scarsz

🐒
Programming Primate
View GitHub Profile
@Scarsz
Scarsz / backup-mysql.sh
Created April 4, 2018 18:19
Script to backup all MySQL databases to a compressed .tar.gz and upload to AWS S3
#!/bin/bash
bucket="milkyway-backups"
server="MILKYWAY"
subject="MYSQL"
databases=$(mysql -e "show databases;" | grep -Ev "(Database|information_schema|performance_schema|phpmyadmin)")
masterfile="$server-$subject-$(date +"%Y-%m-%d").tar.gz"
tmpdir="/tmp/backup-$(echo $RANDOM % 999999 + 1 | bc)"
masterfile="/tmp/$masterfile"
@Scarsz
Scarsz / sharex-upload.php
Last active April 21, 2018 21:20
Simple custom ShareX destination script
<?php
//
// instructions:
// 1. upload script as "upload.php" (changable, just change the other one too)
// 2. change secret key to something random & unguessable
// 3. ensure the files dir exists and is writable to by the web server
// 4. create a new custom destination on ShareX
// - request url: https://example.com/upload.php
// - file form name: d
// - arguments:
@Scarsz
Scarsz / BukkitSerialization.java
Created August 5, 2017 00:28 — forked from graywolf336/BukkitSerialization.java
Serialize and deserialize the player's inventory, including armor and content.
/**
* Converts the player inventory to a String array of Base64 strings. First string is the content and second string is the armor.
*
* @param playerInventory to turn into an array of strings.
* @return Array of strings: [ main content, armor content ]
* @throws IllegalStateException
*/
public static String[] playerInventoryToBase64(PlayerInventory playerInventory) throws IllegalStateException {
//get the main content part, this doesn't return the armor
String content = toBase64(playerInventory);
@Scarsz
Scarsz / Emoji.java
Last active June 17, 2019 21:33
Emojis for bots to use
@SuppressWarnings("unused")
public class Emoji {
public static final String A = "\uD83C\uDD70";
public static final String AB = "\uD83C\uDD8E";
public static final String ABC = "\uD83D\uDD24";
public static final String ABCD = "\uD83D\uDD21";
public static final String ACCEPT = "\uD83C\uDE51";
public static final String AERIAL_TRAMWAY = "\uD83D\uDEA1";
public static final String AIRPLANE = "\u2708";
@Scarsz
Scarsz / Bukkit-setBlockSuperFast.java
Last active June 28, 2017 22:31
Change lots of blocks lots of quick for lots of MC versions
private static Class<?> blockPositionClass = null;
private static Class<?> blockDataClass = null;
private static Class<?> craftWorldClass = null;
/**
* Change a given block extremely quickly using NMS & Reflection
* @param block Block to change
* @param material Material to set the block to
* @param data Any associated data for the block's material
*/
@Scarsz
Scarsz / AnvilGUI.java
Created June 18, 2017 21:02
Anvil Menu
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.player.PlayerQuitEvent;
@Scarsz
Scarsz / ListenToAllEvents.java
Last active November 19, 2023 02:31
Listen to all Bukkit events being fired, ignoring a few
RegisteredListener registeredListener = new RegisteredListener(new Listener() {}, (listener, event) -> {
List<Class> ignoredEvents = Arrays.asList(new Class[] {
BlockFadeEvent.class,
EntityAirChangeEvent.class,
PlayerMoveEvent.class,
PlayerAnimationEvent.class,
BlockPhysicsEvent.class,
VehicleUpdateEvent.class
});
if (ignoredEvents.contains(event.getClass())) return;
@Scarsz
Scarsz / RandomObjectFromProbabilities.java
Last active August 23, 2024 11:20
Get a random object from a given map containing objects and their probabilities
package com.scarsz.playground;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;
/**
* Made by Scarsz
@Scarsz
Scarsz / PokemonGenerationThreeWithTypes.java
Created February 12, 2017 00:10
Pokemon generation 3 pokes with types
public enum PokemonGenerationThreeWithTypes {
Bulbasaur(Type.Grass, Type.Poison),
Ivysaur(Type.Grass, Type.Poison),
Venusaur(Type.Grass, Type.Poison),
Charmander(Type.Fire),
Charmeleon(Type.Fire),
Charizard(Type.Fire, Type.Flying),
Squirtle(Type.Water),
Wartortle(Type.Water),
@Scarsz
Scarsz / BukkitGetOnlinePlayerCount.java
Created February 2, 2017 08:55
Backwards-compatible Server::getOnlinePlayers::size
private int getOnlinePlayers() {
try {
Method onlinePlayerMethod = Server.class.getMethod("getOnlinePlayers");
if (onlinePlayerMethod.getReturnType().equals(Collection.class)) {
return ((Collection<?>) onlinePlayerMethod.invoke(Bukkit.getServer())).size();
} else {
return ((Player[]) onlinePlayerMethod.invoke(Bukkit.getServer())).length;
}
} catch (Exception e) {
e.printStackTrace();