Skip to content

Instantly share code, notes, and snippets.

@tuket
tuket / zstring_view.cpp
Last active May 15, 2024 08:19
proposal for ztring_view
#include <string>
#include <string_view>
struct zstring_view : public std::string_view {
zstring_view() {}
zstring_view(std::string_view s) = delete;
zstring_view(const char* s) : std::string_view(s) {}
zstring_view(const std::string& s) : std::string_view(s) {}
operator const char* ()const { return data(); }
@tuket
tuket / latlong_tile.py
Last active March 9, 2024 18:17
Google Maps: Get tile image from latlong coordinate
import math
def latlongToTile(latlongDegs, zoom):
n = 2 ** zoom
latRads = math.radians(latlongDegs[0])
tileX = n * ((latlongDegs[1] + 180.0) / 360.0)
tileY = n * (1.0 - (math.log(math.tan(latRads) + 1.0/math.cos(latRads)) / math.pi)) / 2.0
return (int(tileX), int(tileY))
def latlongToUrl(latlongDegs, zoom):
@tuket
tuket / build.zig
Created October 13, 2023 07:42
possible fix to zig_bare_apk issue in mac
// INSTRUCTIONS:
// 0) Install Dependencies
// - Zig (0.11)
// - JDK: https://www.oracle.com/es/java/technologies/downloads
// - Android SDK
// - Also NDK
// - Also platform tools (for ADB)
// 1) In the next section you will find a set of configuration bits you need to edit
// - The JDK and Adnroid SDK paths are specially important!
// 2) Obtain a key for signing android APKs (only once)
@tuket
tuket / paint.zig
Created August 13, 2019 09:31
paint in zig using SDL2
// compile in ubuntu:
// $ zig build-exe paint.zig --library SDL2 --library SDL2main --library c -isystem "/usr/include" --library-path "/usr/lib/x86_64-linux-gnu"
const std = @import("std");
const warn = std.debug.warn;
const fmt = std.fmt;
const c = @cImport({
@cInclude("SDL2/SDL.h");
});
@tuket
tuket / imgui.glsl
Created November 24, 2022 22:00
change imgui shader
precision highp float;
layout (location = 0) in vec2 Position;
layout (location = 1) in vec2 UV;
layout (location = 2) in vec4 Color;
uniform mat4 ProjMtx;
out vec2 Frag_UV;
out vec4 Frag_Color;
void main()
{
Frag_UV = UV;
@tuket
tuket / enet_example.cpp
Created November 17, 2022 15:36
Simple ENet example
#include <stdio.h>
#include <thread>
#include "enet.h"
const uint16_t THE_PORT = 55555;
static void sendString(ENetPeer* peer, const char* str)
{
ENetPacket* packet = enet_packet_create(str, strlen(str) + 1, ENET_PACKET_FLAG_RELIABLE);
enet_peer_send(peer, 0, packet);
@tuket
tuket / possible_bug.md
Last active November 8, 2022 10:11
Bug report for Nvidia

Hello, I'm a software developer and I'm using Vulkan. After updating my drivers, I noticed that I started getting some errors from the Khronos validation layers. After lots of time debugging, I think I found the issue. I had to compile the Validation Layers in debug mode in order to find out.

The problem is in the vkCreateInstance function. If you set VkInstanceCreateInfo.VkApplicationInfo.apiVersion = VK_API_VERSION_1_0 ...

when you get to the Validation Layer callback:

VKAPI_ATTR VkResult VKAPI_CALL CreateInstance(const VkInstanceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,

@tuket
tuket / main.cpp
Created October 25, 2022 11:45
OpenGL sRGB experiment
#include "utils.hpp"
#include <GLFW/glfw3.h>
constexpr int W = 800;
constexpr int H = 600;
GLFWwindow* window;
namespace shader_srcs
{
@tuket
tuket / example1.cpp
Created September 14, 2022 07:39
vulkan example that shouldn't be working
#include <stdio.h>
#include <assert.h>
#include <vulkan/vulkan.h>
#include <glm/glm.hpp>
#include <GLFW/glfw3.h>
#include <stb_image.h>
typedef uint8_t u8;
typedef int32_t i32;
typedef int64_t i64;
@tuket
tuket / windows_cpuid_shellcode.cpp
Last active August 20, 2022 21:50
windows cpuid shellcode
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <Windows.h>
static const char cpuidCode[] =
{
0x48, 0x89, 0xCE, // mov rsi, rcx
0x31, 0xC0, // xor eax, eax
0x0F, 0xA2, // cpuid