Skip to content

Instantly share code, notes, and snippets.

View TuxCoding's full-sized avatar

Alex (TuxCoding) TuxCoding

  • [::1]
View GitHub Profile
@TuxCoding
TuxCoding / fibonacci.rkt
Created December 14, 2016 09:04
Calculates the fibonacci numbers recursive and iterative
;; fib-rec: nat -> nat
;;
;; Calculates the fibonacci numbers recursive.
;;
;; Example: (fib-rec 4) = 3
(define (fib-rec n)
(cond
[(= n 0) 0]
[(= n 1) 1]
[else (+ (fib-rec (- n 1)) (fib-rec (- n 2)))]))
@TuxCoding
TuxCoding / Config.java
Created December 9, 2016 15:12
Template for Sponge (Minecraft) ORM configuration with configurate
import ninja.leaping.configurate.objectmapping.Setting;
public class Config {
@Setting(comment = "")
private boolean scoreboardDisplay = true;
public boolean isScoreboardDisplay() {
return scoreboardDisplay;
}
@TuxCoding
TuxCoding / SharedConfig.java
Created December 9, 2016 15:10
Simple config map
package com.github.games647.fastlogin.core;
import java.util.Map;
public class SharedConfig {
private final Map<String, Object> configValues;
public SharedConfig(Map<String, Object> configValues) {
this.configValues = configValues;
@TuxCoding
TuxCoding / CompatibleCacheBuilder.java
Created December 9, 2016 15:09
Represents a Guava CacheBuilder that is compatible with both Guava 10 (Minecraft 1.7.X) and 13
import java.lang.reflect.Method;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit;
import com.google.common.base.Ticker;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.RemovalListener;
/**
@TuxCoding
TuxCoding / BalancedSSLFactory.java
Created December 9, 2016 15:09
When set with connection.setSSLSocketFactory(sslFactory); it will use rotating IP for every connection (Works only with HTTPS)
package com.github.games647.fastlogin.core;
import com.google.common.collect.ImmutableList;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
@TuxCoding
TuxCoding / EncryptionUtil.java
Created December 9, 2016 15:07
Encryption util class based on Craftbukkit's implementation
import com.google.common.base.Charsets;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;
@TuxCoding
TuxCoding / RefreshTask.java
Created December 9, 2016 15:05
Load balance a big operation. Instead of performing a big operation after X ticks, this script will perform every tick a small portion of it.
import com.google.common.collect.Maps;
import java.util.Map;
import org.apache.commons.lang.mutable.MutableInt;
import org.bukkit.entity.Player;
/**
* Handling all updates for a player in a performance optimized variant. This
* class split the updates over the ticks much smoother.
@TuxCoding
TuxCoding / Version.java
Created December 9, 2016 15:00
Compares two version with each other if they are formatted like semVer - http://semver.org/
package com.github.games647.scoreboardstats;
import com.google.common.base.Objects;
import com.google.common.collect.ComparisonChain;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.bukkit.Bukkit;
@TuxCoding
TuxCoding / ClassCache.java
Created December 9, 2016 14:59
Disable jar resources cache
/**
* Disable or enable the use of class caching. Workaround for linking to an
* old jar version while the plugin jar was changed during a reload.
*
* @param status should the cache be activated
* @return if the process succeed.
*/
public static boolean setClassCache(boolean status) {
try {
Field cacheField = URLConnection.class.getDeclaredField("defaultUseCaches");
@TuxCoding
TuxCoding / PathReader.java
Created December 9, 2016 14:57
EBean custom path reader to fix "file not found" if the path contains non-latin characters
package com.github.games647.scoreboardstats.pvpstats;
import com.avaje.ebeaninternal.server.util.ClassPathReader;
import org.apache.commons.lang.ArrayUtils;
/**
* This is workaround to a bug in Java 6. eBean 2.7.3 has a bug catching up
* the wrong exception while scanning through the ebean.properties. Spigot
* fixed this with updating eBean to 2.8.1 and newer versions of eBean has