Skip to content

Instantly share code, notes, and snippets.

View jnguyen1098's full-sized avatar

Jason Nguyen jnguyen1098

View GitHub Profile
@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 / guelph_housing.md
Last active August 12, 2023 20:38
Guide for apartment hunting in Guelph

Guelph Housing Guide

The intended audience of this guide lies somewhere between a UofGuelph student looking for a temporary sublet, an established couple looking for medium-term housing to build a family, and someone who spends 9 hours tweaking their .vimrc: it is aimed toward new grads who are excited and/or nervous to begin the transition into the real world but also want to spend egregious amounts of research before pulling the trigger on something that could very well make or break your first few years out.

Every struggle I (facetiously) enumerate is something I went through or am still going through, and if anything this post is my diary on surviving in the real world. As such, some (or all) of this post will not pertain to you. You don't have to take as drastic of a measure as some of the things I mention below (and if anything, I left them in to lighten the mood for what is likely one of the worst COL crises we've ever faced in Canada). I love everything this city has to offer and although housing

@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 February 14, 2024 14:35
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) \