Skip to content

Instantly share code, notes, and snippets.

@JCThePants
JCThePants / transaction.js
Created December 27, 2017 04:01
Modified for use with znodes
var util = require('./util.js');
exports.CreateGeneration = function (args) {
var rpcData = args.rpcData;
var publicKey = args.publicKey;
var extraNoncePlaceholder = args.extraNoncePlaceholder;
var rewardType = args.rewardType;
var txMessages = args.txMessages;
@JCThePants
JCThePants / PlayerLives.cs
Created July 27, 2016 04:21
PlayerLives struct
public struct PlayerLives {
public static readonly PlayerLives Infinite = new PlayerLives(-1);
private readonly int _lives;
public readonly bool IsInfinite;
public PlayerLives(int lives) {
_lives = lives;
@JCThePants
JCThePants / ArrayDeque.cs
Last active March 1, 2021 02:17
C# array based double ended queue that implements IList
/*
* This file is licensed under the MIT License (MIT).
*
* Copyright (c) JCThePants (github.com/JCThePants)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
@JCThePants
JCThePants / ArrayQueue.java
Last active June 18, 2016 22:46
ArrayQueue for java
/*
* This file is licensed under the MIT License (MIT).
*
* Copyright (c) JCThePants (www.jcwhatever.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
@JCThePants
JCThePants / test.js
Created January 11, 2016 19:46
Test for checking value falls in clamped range for Citizens 2
var hasMoved = true,
hasNotMoved = false;
// check ideal values
assert(0, 45, hasNotMoved);
assert(0, 91, hasMoved);
assert(0, -91, hasMoved);
assert(90, clamp(181), hasMoved);
assert(90, 180, hasNotMoved);
@JCThePants
JCThePants / image-fit-resize-math.js
Last active December 5, 2015 03:46
Fit an image inside a container (centered) while maintaining its aspect ratio
var slotWidth = 100; // The width of the container
var slotHeight = 100;// The height of the container
var imgWidth = 200; // The width of the image to draw inside the container
var imgHeight = 200; // The height of the image to draw inside the container
var offsetTop = 0; // The offset of the image from the top of the container
var offsetLeft = 0; // The offset of the image from the left of the container
var width = imgWidth; // the new image draw width
var height = imgHeight; // the new image draw height
@JCThePants
JCThePants / select-text.js
Created December 5, 2015 03:18
Select all text in an HTML element
function selectAllText(elem) {;
var range = document.createRange();
range.setStart(elem, 0);
var i = 0;
while (i < 999999) { // could have used 'true', but I don't like the infinite loop
try {
range.setEnd(elem, i++);
} catch (err) {
break;
}
@JCThePants
JCThePants / mine.lua
Created February 13, 2015 07:42
Simple ComputerCraft turtle mining script
args = { ... }
-- hasModem hasEnderChest size depth [startDepth]
-- Used to denote the current direction relative to the direction the
-- turtle was facing when the program starts. The start direction is FORWARD.
direction = {}
direction.FORWARD = 0
direction.RIGHT = 1
direction.BACKWARD = 2
direction.LEFT = 3
@JCThePants
JCThePants / Msg.java
Created December 29, 2014 08:46
Nucleus plugin messenger helper
import com.jcwhatever.nucleus.messaging.ChatPaginator;
import com.jcwhatever.nucleus.messaging.IMessenger;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.Collection;
import java.util.List;
import java.util.UUID;
@JCThePants
JCThePants / Minecraft 1.8.1Chunk Packet Data FormatNotes
Last active April 18, 2018 16:05
Minecraft 1.8.1 chunk packet data format notes from looking at Minecraft 1.8 source. (net.minecraft.server.PacketPlayOutMapChunk)
16 chunk sections in a chunk. A chunk is 16x256x16 (x y z) blocks. A chunk section is 16x16x16 blocks.
--------------------------------------------------
Chunk:
Section:
Block Data: 2 bytes per block. 8192 bytes. format: blockId << 4 | meta
Emitted Light: 4 bits per block (1/2 byte). 2048 bytes
Skylight: 4 bits per block (1/2 byte). 2048 bytes (only included in overworld)
Biome: 1 byte per block column. 256 bytes. (only included if all sections are in chunk)
--------------------------------------------------