Skip to content

Instantly share code, notes, and snippets.

View hikari-no-yume's full-sized avatar
🌟
trying to save beautiful things

hikari_no_yume hikari-no-yume

🌟
trying to save beautiful things
View GitHub Profile
@hikari-no-yume
hikari-no-yume / secret-holder.c
Created April 15, 2024 16:30
test of /proc/xxx/mem
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void main(int argc, char **argv)
{
char *secret = strdup(argv[1]);
printf("I have a secret! It is located at %p and is %zu bytes long!\n", secret, strlen(secret));
while (1) {}
free(secret);
@hikari-no-yume
hikari-no-yume / sdl2-gl-ctx-sharing-test.rs
Created May 24, 2023 15:38
sharing between GL contexts in a single window, with SDL2
use sdl2::video::{GLContext, GLProfile, Window};
use sdl2::{EventPump, VideoSubsystem};
use std::time::Instant;
fn make_big_gl() -> (u32, u32, Vec<u8>) {
let small_gl_data = b"\
00GGGG00L0000000\
0G0000G0L0000000\
G0000000L0000000\
G0000000L0000000\
@hikari-no-yume
hikari-no-yume / textureFlipped.glsl
Created May 16, 2023 10:58
one way to automatically flip texture co-ordinates in GLSL
#version 300 es
precision mediump float;
precision mediump sampler2D;
precision mediump sampler3D;
vec4 textureFlipped(sampler2D s, vec2 coords) {
return texture(s, vec2(coords.x, 1.0 - coords.y));
}
vec4 textureFlipped(sampler3D s, vec3 coords) {
@hikari-no-yume
hikari-no-yume / sdl2-gl-ctx-test.rs
Created December 31, 2022 12:34
Test having multiple OpenGL versions in the same window with rust-sdl2 (spoiler: it works!)
use sdl2::video::{GLContext, GLProfile, Window};
use sdl2::{EventPump, VideoSubsystem};
use std::time::Instant;
fn test_opengl(
video_ctx: &VideoSubsystem,
window: &Window,
gl_ctx: &GLContext,
color: (f32, f32, f32, f32),
) {
@hikari-no-yume
hikari-no-yume / !steps.md
Created May 14, 2021 16:06
Rust no_std “hello world” compiled to C!

Requires rustc and llvm-cbe.

  • rustc hello-world-no_std.rs -O --emit=llvm-ir -C panic=abort -o hello-world-no_std-O.ll
  • llvm-cbe ../testfiles/hello-world-no_std-O.ll
@hikari-no-yume
hikari-no-yume / try.py
Last active August 18, 2021 00:46
bruteforce mojibake decoder
# as of python 3.9
all_encodings = ['ascii', 'big5', 'big5hkscs', 'cp037', 'cp273', 'cp424', 'cp437', 'cp500', 'cp720', 'cp737', 'cp775', 'cp850', 'cp852', 'cp855', 'cp856', 'cp857', 'cp858', 'cp860', 'cp861', 'cp862', 'cp863', 'cp864', 'cp865', 'cp866', 'cp869', 'cp874', 'cp875', 'cp932', 'cp949', 'cp950', 'cp1006', 'cp1026', 'cp1125', 'cp1140', 'cp1250', 'cp1251', 'cp1252', 'cp1253', 'cp1254', 'cp1255', 'cp1256', 'cp1257', 'cp1258', 'euc_jp', 'euc_jis_2004', 'euc_jisx0213', 'euc_kr', 'gb2312', 'gbk', 'gb18030', 'hz', 'iso2022_jp', 'iso2022_jp_1', 'iso2022_jp_2', 'iso2022_jp_2004', 'iso2022_jp_3', 'iso2022_jp_ext', 'iso2022_kr', 'latin_1', 'iso8859_2', 'iso8859_3', 'iso8859_4', 'iso8859_5', 'iso8859_6', 'iso8859_7', 'iso8859_8', 'iso8859_9', 'iso8859_10', 'iso8859_11', 'iso8859_13', 'iso8859_14', 'iso8859_15', 'iso8859_16', 'johab', 'koi8_r', 'koi8_t', 'koi8_u', 'kz1048', 'mac_cyrillic', 'mac_greek', 'mac_iceland', 'mac_latin2', 'mac_roman', 'mac_turkish', 'ptcp154', 'shift_jis', 'shift_jis_2004', 'shift_jis
#include "who-needs-glsl-anyway.h"
#include <stdio.h>
int main(void)
{
vec4 v = { {1.5, 2.5, 3.5, 4.5} };
printf("%f, %f, %f, %f\n", v.rg.x, v.xy.t, v.stp.z, v.w);
for (int i = 3; i >= 0; i--) {
printf("%f\n", v._[i]);
}
}
@hikari-no-yume
hikari-no-yume / 0_hello-world.cbe.c
Created February 23, 2021 21:32
What would C look like if it had already been compiled to LLVM IR and back again, but then you compiled it to LLVM IR and back again… again? (sequel to https://gist.github.com/hikari-no-yume/3cde016149d0309a80770c5eccd013ad, using https://github.com/JuliaComputing/llvm-cbe)
/* Provide Declarations */
#include <stdarg.h>
#include <setjmp.h>
#include <limits.h>
#include <stdint.h>
#include <math.h>
#ifndef __cplusplus
typedef unsigned char bool;
#endif
@hikari-no-yume
hikari-no-yume / 0_hello-world.c
Last active February 24, 2021 08:26
What would C look like if you compiled it to LLVM IR and back again? (https://github.com/JuliaComputing/llvm-cbe)
#include <stdio.h>
int main(void)
{
printf("hello, world\n");
}
@hikari-no-yume
hikari-no-yume / dril-units.lib
Created November 15, 2020 14:14
units -f dril-units
/ https://twitter.com/dril/status/701465049030926343
treat !a!
snack 20 treats
meal 3 snacks
BoysDailyIntake 3 meals
Treat treat
Goody 1 Treat