Skip to content

Instantly share code, notes, and snippets.

@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 / 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
@tuket
tuket / tips.odin
Created April 14, 2022 07:24
Odin Tips
for v in soa_zip(_names, _surnames) {
fmt.println(v._0, " ", v._1)
}
@tuket
tuket / repro_bug_glCopyImageSubData.cpp
Created November 28, 2021 19:42
A minamal example to reproduce a bug with glCopyImageSubData
#include <stdio.h>
#include <assert.h>
#include <stdint.h>
#include <SDL.h>
#include <glad/glad.h>
typedef uint32_t u32;
static const char* geGlErrStr(GLenum const err)
{
@tuket
tuket / calc.comp.glsl
Created May 27, 2021 18:04
Vulkan validation error when I try to reset a commandPool after vkQueueWaitIddle
#version 450
#extension GL_EXT_shader_explicit_arithmetic_types_int64 : enable
layout (local_size_x = 128) in;
layout(set = 0, binding = 0) uniform Unifs {
uniform int64_t start;
uniform int64_t n;
uniform int64_t N;
} unifs;
@tuket
tuket / wgl_minimal_enum_display_devices.c
Last active February 23, 2021 11:57
WGL minamal example that enumates display devices
#include <windows.h> /* must include this before GL/gl.h */
#include <GL/gl.h> /* OpenGL header file */
#include <GL/glu.h> /* OpenGL utilities header file */
#include <stdio.h>
#pragma comment (lib, "opengl32.lib")
void display()
{
/* rotate a triangle around */
@tuket
tuket / gen_raw_elf_hello_world.c
Created February 10, 2021 22:00
Generate a raw ELF executable using C
#include <stdio.h>
#include <string.h>
#include <stdint.h>
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef struct Elf64Header {
@tuket
tuket / pf.asm
Created January 22, 2021 20:06
Nasm Linux - Print the contents of a file
SECTION .text
global _start ; "global" means that the symbol can be accessed in other modules. In order to refer to a global symbol from another module, you must use the "extern" keyword
_start:
mov rax, 2 ; syscall: open
mov rdi, str_testFile
mov rsi, 0 ; flags
syscall
mov rdi, rax ; the file descriptor
@tuket
tuket / sdl_ttf_hello.c
Last active September 15, 2020 23:06
SDL_TTF hello world
#include <SDL2/SDL.h>
#include <SDL2/SDL_ttf.h>
const SDL_Color WHITE = { 0xFF, 0xFF, 0xFF, 0 };
int main()
{
SDL_Window* window;
SDL_Renderer* renderer;
SDL_CreateWindowAndRenderer(200, 200, 0, &window, &renderer);