Skip to content

Instantly share code, notes, and snippets.

View WesJD's full-sized avatar

Wesley Smith WesJD

View GitHub Profile
@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
@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 / 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 / RandomTeleporter.java
Created August 3, 2016 03:27
Teleport players to random locations with efficiency from Guava
public class RandomTeleporter {
private final LoadingCache<Pair<Location, Location>, List<Pair<Integer, Integer>>> locationCache = CacheBuilder.newBuilder()
.expireAfterAccess(1, TimeUnit.MINUTES)
.maximumSize(5)
.build(new CacheLoader<Pair<Location, Location>, List<Pair<Integer, Integer>>>() {
@Override
public List<Pair<Integer, Integer>> load(Pair<Location, Location> bounds) throws Exception {
final List<Pair<Integer, Integer>> ret = new ArrayList<>();
final Location bounds1 = bounds.getLeft();
@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 / 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 {
@WesJD
WesJD / spigot-install-file.sh
Last active March 20, 2019 02:10
Useful for AnvilGUI and its dependencies.
read -p "What is the file path? " path
read -p "What is the groupId? " groupId
read -p "What is the artifactId? " artifactId
read -p "What is the version? " version
mvn install:install-file -Dfile=$path -DgroupId=$groupId -DartifactId=$artifactId -Dversion=$version -Dpackaging=jar -DgeneratePom=true
@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 / AbstractInventory.java
Last active November 8, 2016 16:05
Really easy Bukkit inventories.
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 {
@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;