Skip to content

Instantly share code, notes, and snippets.

View muaddib1971's full-sized avatar

Paul Miller muaddib1971

  • RMIT University
View GitHub Profile
@muaddib1971
muaddib1971 / menu.cpp
Last active March 25, 2023 12:02
a menu using the command pattern
#include <iostream>
#include <string>
class menu_action {
public:
virtual bool operator() ()const = 0;
};
class play_game : public menu_action {
public:
@muaddib1971
muaddib1971 / summit.py
Created January 17, 2023 08:29
python code to implenet sum
#!/usr/bin/env python3
result = 0
for n in range(1,101):
result +=5*n*n
print (result)
@muaddib1971
muaddib1971 / linkedlist.py
Created September 15, 2022 03:23
linked list example
class Node:
def __init__(self, num: int) -> None:
self.num = num
self.next = None
class LinkedList:
def __init__(self):
self.len = 0
self.head = None
@muaddib1971
muaddib1971 / alloc.c
Last active September 15, 2022 01:26
beginning of malloc impementation
#include <stdio.h>
#include <unistd.h>
struct alloc {
void* data;
long size;
};
struct alloc thememory[BUFSIZ];
struct alloc frees[BUFSIZ] = {0};
long num_allocs = 0;
#!/bin/bash
valgrind --track-origins=yes --leak-check=full --show-leak-kinds=all $@
@muaddib1971
muaddib1971 / recur.c
Created September 1, 2022 04:56
recursion for brearne
#include <stdio.h>
void recur() {
printf("me: what's the topic, brearne: recursion");
recur();
}
int main() { recur(); }
#include <stdio.h>
#include <stdlib.h>
struct pair {
int first, second;
};
void printpair(const struct pair* apair) {
printf("first: %d, second: %d\n", apair->first, apair->second);
}
@muaddib1971
muaddib1971 / example.c
Created August 15, 2022 07:24
pointer example
#include <stdio.h>
#include <stdlib.h>
#define ADDRESSOF(X) &(X)
#define CONTENTSOF(X) *(X)
void swap(int* a, int* b) {
int temp = *a;
*a = *b;
*b = temp;
#include <stdio.h>
#include <stdlib.h>
/* global variable - you should avoid these especially
* with parallel programming as they are hard to debug
*/
int i = 42;
void printptr(void *ptr) {
/* prints the size of a pointer followed by its address. You
@muaddib1971
muaddib1971 / Makefile.advanced
Last active July 28, 2022 07:56
examples of fgets and the issues it has as well as example Makefiles
#target: prereqs
# command
CFLAGS=-Wall -Werror -std=gnu99
LDFLAGS=-lm
CC=gcc
SOURCES=fooimp.c something.c
HEADERS=fooimp.h
OBJS=fooimp.o something.o