Skip to content

Instantly share code, notes, and snippets.

View DavidDudson's full-sized avatar

David Dudson DavidDudson

View GitHub Profile
@DavidDudson
DavidDudson / gist:8051016
Created December 20, 2013 06:07
loadNBTData method for Enchant Insanity players.
@Override
public void loadNBTData(NBTTagCompound compound) {
if (compound.hasKey("EISkillData")) {
this.EISkillData = compound.getCompoundTag("EISkillData");
} else {
this.EISkillData = generateSkillData();
}
if (compound.hasKey("EIEnchantmentData")) {
@DavidDudson
DavidDudson / gist:8230352
Created January 3, 2014 00:45
Chat messages in 1.7.2
package nz.co.bigdavenz.ei.core.handler;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.*;
import nz.co.bigdavenz.ei.lib.Reference;
public class ChatMessageHandler {
@DavidDudson
DavidDudson / gist:8249440
Created January 4, 2014 00:17
if player name is BigDaveNz and damage source is fall damage. Cancel the event
@SubscribeEvent
public void onLivingHurt(LivingHurtEvent event) {
if (UsefulFunctions.getPlayerFromEntity(event.entity).getDisplayName().equalsIgnoreCase("BigDaveNz") && event.source == DamageSource.fall) {
event.setCanceled(true);
}
var colors = {
"black" : "#000",
"white" : "#fff",
}
function color_hex(color) {
return {color : colors[color]}
}
"scripts": {
"test": "karma start",
"clean": "rm -r dist/*",
"populate": "node ./src/database.js",
"mkPub": "mkdir -p dist/public",
"copy:index": "cp src/client/index.html dist/public/index.html",
"copy": "npm run copy:index && npm run copy:iframe",
"quicktest": "open ./dist/public/test.html",
"webpack": "webpack --config=\"src/webpack.conf.js\" --progress",
@WhatAmI
object Test {
@WhatAmI
def main(args: Array[String]) = {}
@WhatAmI
val hi = ""
@WhatAmI
var hello = ""

Keybase proof

I hereby claim:

To claim this, I am signing this object:

@DavidDudson
DavidDudson / Interning.scala
Last active October 5, 2017 22:00
Trait based interning of case classes
import scala.collection.mutable
sealed trait InterningProvider[K, V] {
private[this] val cache =
mutable.WeakHashMap[K, V]()
protected def intern(args: (K))(builder: => V): V =
cache.getOrElseUpdate(args, builder)
}
@DavidDudson
DavidDudson / Opt.scala
Created November 7, 2017 22:04
Allocationless Option type that converts to/from scala.Option and java.Optional
/**
* An Option class, without a few Ion's
*
* Never allocates, uses null instead.
*
* No primitives allowed.
*
* Flatmap is allowed, but nesting is not (no flatten)
*/
object Opt {