Skip to content

Instantly share code, notes, and snippets.

View cnlohr's full-sized avatar

cnlohr cnlohr

View GitHub Profile
@cnlohr
cnlohr / example_generate_texture.c
Last active April 12, 2023 10:09
How to write 2D and 3D Unity Texture files from C
// Execute this with `tcc testgen.c -run`
#include <stdio.h>
#include "unityassettexture.h"
#include <math.h>
int main()
{
float asset3d[50][50][50][4] = {0};
int x, y, z;
@cnlohr
cnlohr / authenticate.sh
Created July 5, 2021 01:42
2021 How to authenticate with the VRChat API
$ echo -n "username:password" | base64
$ echo -e "api.vrchat.cloud\tFALSE\t/\tFALSE\t0\tapiKey\tJlE5Jldo5Jibnk5O5hTx6XVqsJu4WJ26" > cookiejar.txt
$ curl -b cookiejar.txt -c cookiejar.txt -A "WorldMon" -H "Authorization: Basic ########################" https://api.vrchat.cloud/api/1/auth/user
{"requiresTwoFactorAuth":["totp","otp"]}
$ curl -X 'POST' \
'https://api.vrchat.cloud/api/1/auth/twofactorauth/totp/verify' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-b cookiejar.txt -c cookiejar.txt \
-d '{
@cnlohr
cnlohr / teapot.h
Created September 29, 2021 12:09
Teapot.h single-file c header
/* Copyright (c) 2012-2017, ARM Limited and Contributors
*
* SPDX-License-Identifier: MIT
*
* 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 furnished to do so, subject to the following conditions:
*
@cnlohr
cnlohr / noeuclid2.cginc
Created October 28, 2021 04:26
Ray Casting Logic For No Euclid Avatar in VRChat
// This was the version from Dec 12, 2020
/*
NO EUCLID 2: This time written from the ground up for MODERN (2020)
GPUs! No more janky math stuff to support the NVIDIA 460M or some
awful ancient ATI card.
The three textures we have are:
Read only when a collision may be possible.
GeoTex:
@cnlohr
cnlohr / esppgmmode.c
Last active February 4, 2022 00:36
Setting RTS/DTR on serial port from C in Linux for ESP8266 and ESP32 manual booting
#include <stdio.h>
#include <sys/ioctl.h> //ioctl() call defenitions
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <fcntl.h>
/* ESP8266 / ESP32 Dual-Transistor Boot Bridge:
DTR RTS RST GP0
@cnlohr
cnlohr / libnl_example_basic_wifi.c
Created May 27, 2022 22:27
Really basic libnl test for getting wifi properties.
// Based on (but modified from)
/*************************************************************
* Description: We get some wifi info using nl80211 *
* Licence : Public Domain. *
* Author : Antonios Tsolis (2016) *
*************************************************************/
//
// Modifications by C. Lohr (still under public domain)
#include <stdio.h>
@cnlohr
cnlohr / graph.c
Created July 14, 2022 04:40
Example command-line graphing tool for rawdraw.
#define CNFG_IMPLEMENTATION
#include "rawdraw_sf.h"
void HandleKey( int keycode, int bDown ) { }
void HandleButton( int x, int y, int button, int bDown ) { }
void HandleMotion( int x, int y, int mask ) { }
void HandleDestroy() { }
#include <pthread.h>
@cnlohr
cnlohr / sandbox_esp32_s2_frequency_and_pro_alone_gpio.c
Created July 17, 2022 11:14
ESP32-S2 Experiments with pro alone GPIO + Overclocking.
#include <stdio.h>
#include "esp_system.h"
#include "swadgeMode.h"
#include "hdw-led/led_util.h"
#include "hal/gpio_types.h"
#include "soc/system_reg.h"
#include "soc/dport_access.h"
#include "soc/dedic_gpio_reg.h"
#include "soc/rtc_cntl_reg.h"
#include "esp_log.h"
@cnlohr
cnlohr / SDL_add_logging.c
Created August 11, 2022 00:28
Make SDL Apps Emit Verbose Logging for Debugging Purposes
void SDL_LogVerbose()
{
// You can C&P theis code into yours before main.
SDL_LogSetPriority(SDL_LOG_CATEGORY_ERROR, SDL_LOG_PRIORITY_DEBUG);
}