Skip to content

Instantly share code, notes, and snippets.

View ephf's full-sized avatar
🍹

Grant Wittmann ephf

🍹
View GitHub Profile
@ephf
ephf / xxd.c
Created May 7, 2026 03:08
xxd Clone
#include <stdio.h>
int main(int argc, char** argv) {
if(argc != 2) return fprintf(stderr, "usage: %s <file>\n", *argv), 1;
FILE* file = fopen(argv[1], "r");
if(!file) return perror("xxd"), 1;
for(size_t o = 0; !feof(file); o += 16) {
char s[16], i = 0;
@ephf
ephf / web-server.c
Last active June 18, 2024 18:24
Simple Web Server in C
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdio.h>
#include <unistd.h>
int main() {
int sfd = socket(PF_INET, SOCK_STREAM, 0);
setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR,
&(int) { 1 }, sizeof(int));
@ephf
ephf / population-problem.md
Created May 7, 2024 23:00
Population Problem

The population grows as a result of two conditions:

  1. The anual population growth is 1% of those already in the country.
  2. 20,000 people immigrate each year.

If the population now is 50,000 people, what will the population be in 20 years?

The answer can be found using the recursive function:

$$f_0=50,000$$

@ephf
ephf / vec.c
Created April 15, 2024 01:00
Short Vector Implementation in c
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#define vec_t(t) t*
#define vec() NULL
void vresv(size_t** v, size_t s) {
if(!*v) return assert((*v = (size_t*) calloc(1, sizeof(size_t[2]) + s) + 2) - 2 && ((*v)[-2] = s));
if((s += (*v)[-1]) <= (*v)[-2]) return;