Skip to content

Instantly share code, notes, and snippets.

@jnguyen1098
jnguyen1098 / free_sux.md
Created June 18, 2022 12:28
Freeing Memory Before Panic in CIS*2750 Considered Harmful?

Freeing Memory Before Panic Considered Harmful?

Originally published April 7, 2021 here

(I will admit I dislike 'x Considered Harmful' essays, so take the title as a tongue-in-cheek.)

There's this common adage going around at UofG's C courses (ahem, CIS*2750) that when your program encounters an error and quits (i.e. "panics"), it should free all of its buffers before exiting. I think this is a colossal waste of time. The University of Guelph's C courses worry too much about being pedantic and "correct" that, in my opinion, it wastes a lot of curriculum time.

Most sane operating systems (at least the ones used at the University of Guelph SoCS infrastructure) will free all of buffers in a given program before exiting. Typically such memory is reported by valgrind as

@jnguyen1098
jnguyen1098 / rfd.py
Created April 4, 2022 02:29
RFD text extractor
from selenium import webdriver
with webdriver.Chrome() as driver:
driver.get("https://forums.redflagdeals.com/hot-deals-f9/")
for elem in driver.find_elements_by_xpath("//h3[contains(@class, 'topictitle')]"):
print(elem.text)
@jnguyen1098
jnguyen1098 / cis3190.md
Last active December 25, 2025 23:34
CIS*3190 Is One of the Most Useful Courses in BComp

CIS*3190 Is One of the Most Useful Courses in BComp

Ask anyone at the University of Guelph what butt end courses exist, and you will usually find folks laughing at CIS*2910, the "useless theory" course, or CIS*4650, the course where you "learn to make compilers, a skill you'll never work on in the real world" (completely untrue, btw). But no course has received the short end of the stick more than CIS*3190 "Software for Legacy Systems". Yuck, a course where you program in Fortran, Ada, and COBOL, some of the most dinosaur-esque languages out there still in use? Blech. Or so you may think. On the contrary, I would argue that the introspection and creative format of the course make it one of the most useful, rewarding, and overall underrated courses at U of Guelph.

CIS*3190 is a Distance Education or "DE" course at Guelph, meaning it is offered entirely online (a format that is different from "SYNC" courses introduced during the COVID era of schooling). This convenience means there aren't any lectu

@jnguyen1098
jnguyen1098 / int_pun.c
Last active February 7, 2022 02:29
Re-interpret `int` as four bytes without casts
#include <stdio.h>
#include <limits.h>
/**
* A `union` is defined like a `struct`, but rather than have every member
* exist simultaneously (in the case of the latter), each member exists
* exclusively. That is, every top-level member of a `union` defines a
* separate way to "interpret" its bytes.
*
* In this particular example, there are two top-level members:
@jnguyen1098
jnguyen1098 / fac.c
Created April 7, 2021 13:35
C / ASM versions of fac, gcd, and sort (CIS*4650)
#include <stdio.h>
/* A program to compute the factorial value of an input */
int main(void) {
int x; int fac;
scanf("%d", &x);
fac = 1;
while (x > 1) {
@jnguyen1098
jnguyen1098 / valgrind_destroyer.h
Created March 30, 2021 09:05
goodbye valgrind leaks xd
#include <stdlib.h>
char *ram;
size_t brk;
void __attribute__((constructor)) lmao(void) {
!ram ? atexit(lmao), ram = calloc(1, 100000) : free(ram);
}
#define calloc(x,y)(malloc(x*y))
#define malloc(x)(void *)(&ram[brk] + x >= &ram[100000 - 1] ? NULL : (brk += x, &ram[brk - x]))
#define free(x)
@jnguyen1098
jnguyen1098 / bogograms.c
Created March 30, 2021 04:12
Find out if two words are anagrams, bogo style
#define _GNU_SOURCE
#include <stdio.h>
#include <string.h>
int main(void)
{
char first_word[BUFSIZ] = "";
char second_word[BUFSIZ] = "";
@jnguyen1098
jnguyen1098 / double_free_guard.c
Created August 10, 2020 02:16
Macro to temporarily prevent double free problems
#include <stdio.h>
#include <stdlib.h>
/**
* NULLs pointer after freeing.
* Prints the pointer alerting a double free
* in the case where that may have occurred.
**/
#define FREE(p) \