Skip to content

Instantly share code, notes, and snippets.

View DrBrad's full-sized avatar
💭
Learning Rust

Brad DrBrad

💭
Learning Rust
View GitHub Profile
@DrBrad
DrBrad / PacketListener.java
Created September 30, 2024 21:56
Spigot 1.21.1 NMS (net.minecraft.server) packet listener
public class MyEventHandler implements Listener {
@EventHandler
public void onJoin(PlayerJoinEvent event) throws NoSuchFieldException, IllegalAccessException {
Player player = event.getPlayer();
//Craft Player (NMS varient of player)
EntityPlayer nmsPlayer = ((CraftPlayer) player).getHandle();
//Get connection
ServerCommonPacketListenerImpl connection = nmsPlayer.c;
@DrBrad
DrBrad / PacketListener.java
Created September 30, 2024 21:56
Spigot 1.21.1 NMS (net.minecraft.server) packet listener
public class MyEventHandler implements Listener {
@EventHandler
public void onJoin(PlayerJoinEvent event) throws NoSuchFieldException, IllegalAccessException {
Player player = event.getPlayer();
//Craft Player (NMS varient of player)
EntityPlayer nmsPlayer = ((CraftPlayer) player).getHandle();
//Get connection
ServerCommonPacketListenerImpl connection = nmsPlayer.c;
@DrBrad
DrBrad / NumberConverter.java
Created April 19, 2024 01:01
Java Number to byte array without using String
public static char[] numberToByteArray(int number) {
int numDigits = getNumDigits(number);
char[] charArray = new char[numDigits];
for (int i = numDigits - 1; i >= 0; i--) {
charArray[i] = (char)('0' + number % 10);
number /= 10;
}
return charArray;
}
@DrBrad
DrBrad / CipherInputStream.java
Created March 25, 2024 22:16
Improved CipherInputStream & CipherOutputStream
import javax.crypto.Cipher;
import javax.crypto.NullCipher;
import javax.crypto.ShortBufferException;
import java.io.EOFException;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
public class CipherInputStream extends FilterInputStream {
@DrBrad
DrBrad / hpe_sos_ubuntu.md
Created December 28, 2023 08:06 — forked from yukirii/hpe_sos_ubuntu.md
installing HPE StoreOpen Software for RHELx64 to Ubuntu 20.04.2 LTS (Reference: https://rabbit-note.com/2020/01/12/ubuntu-ltfs/)
@DrBrad
DrBrad / JWK.php
Created November 19, 2023 20:25
Simple EC JWK
<?php
class JWK {
public static $curveOID = '06082a8648ce3d030107';//'1.2.840.10045.3.1.7';
private $jwk;
function __construct(){
}
public function create($jwk = null){
@DrBrad
DrBrad / curlparse.c
Last active January 27, 2022 20:36
URL parser for C-Lang
#include <stdio.h>
#include <string.h>
typedef struct {
char *protocol;
char *host;
char *path;
int port;
} URL;
@DrBrad
DrBrad / client.java
Last active March 14, 2021 12:40
UDP Hole Punching Java
public static void main(String[] args){
try{
DatagramSocket s = new DatagramSocket();
byte[] b = new byte[10];
DatagramPacket p = new DatagramPacket(b, b.length, InetAddress.getLocalHost(), 8000);
s.send(p);
p = new DatagramPacket(new byte[65535], 65535);
s.receive(p);
@DrBrad
DrBrad / README.md
Last active July 12, 2021 19:25
Java Swing Relative Layout Manager

I tried to make the layout as similar as possible to androids relative layout, as feel that it is the superior layout.

Heres an example:

pane.add(mjlabel, new RelativeConstraints().alignParentRight().toRightOf(mjlabel1).setHeight(RelativeConstraints.MATCH_PARENT));

@DrBrad
DrBrad / SRI.java
Last active September 20, 2020 18:35
Socket Cipher Data Input / Output Stream for AES
import javax.crypto.Cipher;
import javax.crypto.NullCipher;
import java.io.EOFException;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
public class SRI extends FilterInputStream {