Skip to content

Instantly share code, notes, and snippets.

@riicchhaarrd
riicchhaarrd / token.h
Created May 24, 2021 23:43
token.h for lex example
#ifndef TOKEN_H
#define TOKEN_H
enum TOKEN_TYPE
{
//ASCII characters reserved
TK_IDENT = 256,
TK_INTEGER,
TK_STRING,
TK_NUMBER,
@riicchhaarrd
riicchhaarrd / main.c
Created May 24, 2021 23:42
main.c for lex.c example
#include <stdio.h>
#include <stdlib.h>
#include "token.h"
#define HEAP_STRING_IMPL
#include "rhd/heap_string.h"
#define LINKED_LIST_IMPL
#include "rhd/linked_list.h"
@riicchhaarrd
riicchhaarrd / lex.c
Created May 24, 2021 23:41
lex example test
#include <stdio.h>
#include <stdlib.h>
#include "token.h"
#include "rhd/heap_string.h"
#include "rhd/linked_list.h"
struct lexer
{
char *buf;
@riicchhaarrd
riicchhaarrd / elf.c
Created May 24, 2021 00:27
Writing ELF File Format / Linux executable in C
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <assert.h>
#include <linux/elf.h>
#define HEAP_STRING_IMPL
#include "heap_string.h"
//https://en.wikipedia.org/wiki/Executable_and_Linkable_Format
//http://www.muppetlabs.com/~breadbox/software/tiny/teensy.html
@riicchhaarrd
riicchhaarrd / hex.c
Last active February 23, 2021 02:57
hexadecimal to decimal
#include <stdio.h>
#include <string.h>
int dec(int c)
{
if(c >= '0' && c <= '9')
return c - '0';
if(c >= 'a' && c <= 'f')
return c - 'a' + 10;
return 0;
@riicchhaarrd
riicchhaarrd / glow.cpp
Created February 10, 2021 10:40
glow sphere
#include <stdio.h>
#include <math.h>
#include <vector>
#include <stdint.h>
#include <time.h>
typedef uint8_t u8;
struct vec3
{
@riicchhaarrd
riicchhaarrd / watermark.sh
Last active October 30, 2025 20:18
imagemagick watermark repeating text
#!/bin/bash
# usage: ./watermark.sh "your text" input_image_path.png
convert -background none -fill "rgba(128,128,128,0.25)" -font Arial -rotate -30 -pointsize 14 label:"$1" /tmp/wm.png
convert $2 -alpha on \( +clone -tile /tmp/wm.png -draw "color 0,0 reset" \) -composite result.png
#rm /tmp/wm.png
@riicchhaarrd
riicchhaarrd / main.cpp
Created May 24, 2020 15:18
steam appid
#include <stdio.h>
#include <Windows.h>
int main(int argc, char** argv)
{
if (argc < 2)
return 0;
HMODULE lib = LoadLibraryA("steam_api.dll");
bool (*__cdecl SteamAPI_Init)() = (bool(__cdecl*)())GetProcAddress(lib, "SteamAPI_Init");
@riicchhaarrd
riicchhaarrd / circles.html
Created September 16, 2019 15:16
fun with circles
<canvas>
</canvas>
<script>
(function()
{
var canvas = document.getElementsByTagName("canvas")[0];
var ctx = canvas.getContext("2d");
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
@riicchhaarrd
riicchhaarrd / sphere.c
Last active September 14, 2019 19:13
drawing a shaded sphere (using https://cidscropt.org/)
dot(a,b)
{
return (a.x*b.x+a.y*b.y+a.z*b.z);
}
_sqrt(a)
{
prev = 0;
for(i=0.0;i<10000;i = i + 0.1)
{