Skip to content

Instantly share code, notes, and snippets.

View WesJD's full-sized avatar

Wesley Smith WesJD

View GitHub Profile
@WesJD
WesJD / Logging.java
Created March 12, 2016 02:29
Easy logging.
public class Logging {
private static final String PREFIX = "MyPrefix";
public static void logStatistic(String message) {
logWithExtra("Statistic", message);
}
public static void logDebug(String message) {
logWithExtra("Debug", message);
@WesJD
WesJD / Announcer.java
Created March 29, 2016 01:53
Easy announcements.
public class Announcer {
private final String[] announcements;
private final int secondsBetween;
private BukkitTask announcementTask;
public Announcer(int secondsBetween, String... announcements) {
this.secondsBetween = secondsBetween;
this.announcements = announcements;
@WesJD
WesJD / MainThreadExecutor.java
Created December 30, 2015 23:25
Execute things on the main thread easily.
public abstract class MainThreadExecutor {
public MainThreadExecutor() {
MinecraftServer.getServer().processQueue.add(new Runnable() {
@Override
public void run() {
call();
}
});
}
@WesJD
WesJD / delete_screen.sh
Created May 7, 2016 15:25
Delete screen sessions with ease.
echo "----------- [ DELETE SCREEN SESSION ] -----------"
screen -ls
read -p "Please supply the screen id you would like to delete: " id
read -p "Are you sure you want to delete screen $id? [y/N]: " des
if [[ $des =~ [yY](es)* ]]
then
echo "Deleting...."
screen -S $id -p 0 -X quit
echo "Done!"
fi
@WesJD
WesJD / InstanceManager.java
Last active August 8, 2016 00:49
Dynamic instance manager with Reflections
public class InstanceManager<T> {
private final List<T> instances = new ArrayList<>();
public InstanceManager(Class<T> superclass, String packageSearch) {
new Reflections(packageSearch).getSubTypesOf(superclass).forEach(clazz -> {
try {
instances.add(clazz.newInstance());
} catch (InstantiationException | IllegalAccessException e) {
e.printStackTrace();
@WesJD
WesJD / InstanceHolder.java
Created August 13, 2016 23:41
Literally holds instances of a type
public class InstanceHolder<T> {
private final List<T> instances = new ArrayList<>();
public void add(T instance) {
instances.add(instance);
}
public T get(Class<? extends T> clazz) {
return instances.stream().filter(instance -> instance.getClass().equals(clazz)).findFirst().orElse(null);
@WesJD
WesJD / questioner.rs
Last active August 21, 2016 22:13
Simple questioner written in Rust (first little project)
use std::io;
struct Question {
ask: String,
answers: Vec<String>,
}
impl Question {
fn new(ask: String, answers: Vec<String>) -> Question {
Question {
@WesJD
WesJD / mac-modmap.txt
Created October 1, 2016 00:10
Basically get mac keybinds on linux
clear control
clear mod1
clear mod4
keycode 64 = Control_L NoSymbol Control_L
keycode 133 = Alt_L NoSymbol Alt_L
keycode 37 = Super_L NoSymbol Super_L
keycode 108 = Control_L NoSymbol Control_L
keycode 134 = Alt_L NoSymbol Alt_L

Keybase proof

I hereby claim:

  • I am WesJD on github.
  • I am wesjd (https://keybase.io/wesjd) on keybase.
  • I have a public key whose fingerprint is 5DF0 E345 74BD D70A 03B7 1C4E 45CB 4DED 972A F8C4

To claim this, I am signing this object:

@WesJD
WesJD / AbstractInventory4j8.java
Last active November 8, 2016 16:03
AbstractInventory that uses Java 8 BiConsumers rather than it's own Button class
public abstract class AbstractInventory {
private static final String SERVER_VERSION = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
private static Method handleInventoryCloseEvent;
private static Method getHandle;
private static Field defaultContainer;
private static Field activeContainer;
static {