Skip to content

Instantly share code, notes, and snippets.

View jtsiomb's full-sized avatar

John Tsiombikas jtsiomb

View GitHub Profile
@jtsiomb
jtsiomb / 1 - unistate.h
Last active November 19, 2017 00:43
OpenGL global uniform state tracking
#ifndef UNISTATE_H_
#define UNISTATE_H_
#include "vmath/vmath.h"
class ShaderProg;
enum StType {
ST_UNKNOWN,
ST_INT, ST_INT2, ST_INT3, ST_INT4,
@jtsiomb
jtsiomb / rinplace.c
Created March 24, 2018 15:41
In-place search & replace efficiently even in huge files (UNIX)
/*! cc -o rinplace -pedantic -Wall -g rinplace.c */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
struct snode {
@jtsiomb
jtsiomb / capsctrl.asm
Last active September 8, 2018 00:48
DOS TSR for remapping caps lock to control (see comment at the end for pre-built binaries)
; DOS caps lock -> ctrl remapper
; Author: John Tsiombikas <nuclear@member.fsf.org>
; This program is public domain. Do whatever you like with it
; build with: nasm -o capsctrl.com -f bin capsctrl.asm
org 100h
bits 16
mov ax, 0900h
mov dx, msg
int 21h
@jtsiomb
jtsiomb / mbox_attachments.c
Last active February 10, 2019 00:03
Scans a mailbox (mbox format) and extracts all attachments with the help of munpack
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include <alloca.h>
#include <unistd.h>
#include <fcntl.h>
#include <dirent.h>
#include <sys/wait.h>
@jtsiomb
jtsiomb / md5.c
Created October 17, 2019 14:34
MD5 sum implementation
/* MD5 message digest
* Author: John Tsiombikas <nuclear@member.fsf.org>
*
* This software is public domain. Feel free to use it any way you like.
*
* If public domain is not applicable in your part of the world, you may use
* this under the terms of the Creative Commons CC-0 license:
* http://creativecommons.org/publicdomain/zero/1.0/
*/
#include <stdio.h>
@jtsiomb
jtsiomb / dropcr.c
Created January 2, 2021 15:08
text file cleanup: unix->dos line endings, missing newline at EOF, and trailing whitespace
#include <stdio.h>
#include <stdlib.h>
char *find_nonws(char *ptr, char *end);
int trailing_ws, fixed_trailing;
int main(int argc, char **argv) {
int i, j, count = 0;
@jtsiomb
jtsiomb / glclip_example.c
Created August 18, 2018 16:35
OpenGL user clip planes example fixed function & shaders (discard)
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <math.h>
#include <assert.h>
#include <alloca.h>
#include <GL/glew.h>
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
@jtsiomb
jtsiomb / fixname.sh
Last active November 15, 2022 13:15
Shell script to fix filenames to abide by my arbitrary "clean filename" rules
#!/bin/sh
# ___________________________________________________
# / \_
# | fixname - cleans up filenames | \
# | | |
# | author: John Tsiombikas <nuclear@member.fsf.org> | |
# | license: public domain | |
# \___________________________________________________/ |
# \___________________________________________________/
#
@jtsiomb
jtsiomb / xsection.c
Last active December 12, 2022 23:12
Example of rendering cross-sections of closed geometry with OpenGL
/* Example of rendering cross-sections of closed non-self-intersecting geometry
* with the stencil buffer. See draw_cross_section for details.
*
* Controls:
* - rotate object by dragging with the left mouse button
* - move cross-section plane back and forth by dragging up/down with the right
* mouse button
*
* Compile with: cc -o xsection xsection.c -lGL -lGLU -lglut
*
@jtsiomb
jtsiomb / Makefile
Last active October 21, 2023 08:46
Bootable 16bit C program with gcc-ia16
bin = boot.img
CC = ia16-elf-gcc
LD = ia16-elf-ld
$(bin): boot.o
$(LD) -Tboot.ld -o $@ $^
.PHONY: clean
clean: