Skip to content

Instantly share code, notes, and snippets.

View nickelpro's full-sized avatar
suzmarin

Vito Gamberini nickelpro

suzmarin
View GitHub Profile
@nickelpro
nickelpro / Python Enum
Created November 13, 2012 19:18
Do-It-Yourself Enumeration in Python
class enum(object):
def __init__(self, *names):
for number, name in enumerate(names):
setattr(self, name, number)
Example:
Month = enum(
"January",
"Febuary",
@nickelpro
nickelpro / to_hex.cpp
Last active December 15, 2015 01:29
Creates a std::string of hex from data, data being basically any primitive data type. I have no idea under what conditions this will explode, probably many
#include <iomanip>
#include <sstream>
std::string to_hex(const void *data, const unsigned int size) {
std::stringstream stream;
stream << std::uppercase << std::hex;
const unsigned char *bytes = static_cast<const unsigned char *>(data);
for (unsigned int i = 0; i<size; ++i) {
stream << std::setfill('0') << std::setw(2) << static_cast<const int>(bytes[i]) << " ";
}
@nickelpro
nickelpro / randpng.py
Created April 23, 2013 07:24
Generates a reasonably random PNG image, relies on pypng
import png
import random
random.seed()
pixels = [[random.randint(0, 255) for i in xrange(0, 3*64)] for i in xrange(0, 32)]
png.from_array(pixels, 'RGB').save('foo.png')
@nickelpro
nickelpro / yggdrasil.py
Created October 16, 2013 21:51
Yggdrasil Authentication implementation for Minecraft, implements all known Yggdrasil methods and is a lot simpler than some of the other implementations floating around
import urllib.request as request
from urllib.error import HTTPError
import json
class YggAuth:
def __init__(self,
client_token=None,
access_token=None,
username=None,
password=None
@nickelpro
nickelpro / mcvarint.py
Created November 5, 2013 02:20
Two python functions that implement the new Minecraft varint type (32-bit signed integers packed into Google protobuf varints). Packs varints into a byte string, unpacks varints from a buffer that has a read(bytes) method. Supports negative numbers even though they aren't used in the current protocol.
import struct
def pack_varint(val):
total = b''
if val < 0:
val = (1<<32)+val
while val>=0x80:
bits = val&0x7F
val >>= 7
total += struct.pack('B', (0x80|bits))
@nickelpro
nickelpro / nickfollow.py
Last active December 13, 2015 10:34
Example of movement with new pathfinding
from spockbot.plugins.tools.event import EVENT_UNREGISTER
from spockbot.plugins.base import PluginBase
from spockbot.vector import Vector3
class NickelproFollow(PluginBase):
requires = (
'Chat', 'ClientInfo', 'Entities', 'Event', 'Movement', 'Interact'
)
events = {
char *enc_varint(char *dest, uint32_t source) {
for(; source >= 0x80; dest++, source >>= 7) {
*dest = 0x80 | (source & 0x7F);
}
*dest = source & 0x7F;
return ++dest;
}
char *dec_varint(int32_t *dest, char *source) {
for(; *(unsigned char *) source & 0x80; source++, *(uint32_t *) dest <<= 7) {
#Midway upon the journey of our life
#I found myself within a forest dark,
#For the straight-forward pathway had been lost.
#This code is really bad
import cfile as c
import minecraft_data
import re
#This is not a real compiler, there is no IR or anything. Just walks the
#define GLFW_INCLUDE_VULKAN
#include <GLFW/glfw3.h>
#include <stdio.h>
#include <string.h>
#include <graphene-1.0/graphene.h>
#include "vgfx.h"
#include "logc/log.h"
#include "par/par_shapes.h"
#include "sds/sds.h"
@nickelpro
nickelpro / build_and_copy_buf.c
Last active May 28, 2019 04:25
I hate Vulkan
//Basically this:
//https://github.com/KhronosGroup/Vulkan-Docs/wiki/Synchronization-Examples
//Holy shit this function got out of control
int build_and_copy_buf(
vk_buffer_t *local_buf,
void *data,
VkDeviceSize size,
VkBufferUsageFlags usage,
VkAccessFlags dst_access,
VmaAllocator allocator,