Skip to content

Instantly share code, notes, and snippets.

View mshafae's full-sized avatar

Michael Shafae mshafae

View GitHub Profile
@mshafae
mshafae / cpsc120_simple_image.cc
Created April 28, 2025 07:07
CPSC 120 Create a simple PNG image
// Gist https://gist.github.com/mshafae/f3405bece8f6293036cbd94f2ae555c1
// Filename cpsc120_simple_image.cc
// CompileCommand clang++ -std=c++20 -I /usr/include/GraphicsMagick -lGraphicsMagick++ cpsc120_simple_image.cc
// Create a simple PNG image.
#include <Magick++.h>
#include <iostream>
int main(int argc, char* argv[]) {
const int kImageWidthAndHeight{512};
@mshafae
mshafae / cpsc120_is_even.cc
Last active February 25, 2025 04:42
CPSC 120 Check to see if a number is even or not
// Gist https://gist.github.com/mshafae/978da2ef9ca32695d1ac0396c1427feb
// Filename cpsc120_is_even.cc
// CompileCommand clang++ -std=c++20 cpsc120_is_even.cc
// Check to see if a number is even or not
#include <iostream>
// Poor style
// bool IsEven(int number) {
// if ((number % 2) == 0) {
@mshafae
mshafae / cpsc120_common_if_mistakes.cc
Created October 8, 2024 19:17
Common mistakes with if, else-if, and else
// Gist https://gist.github.com/mshafae/0a21e4c9277838ed0c57e3e9b9ecd5a3
// Filename cpsc120_common_if_mistakes.cc
// CompileCommand clang++ -std=c++17 cpsc120_common_if_mistakes.cc
// Common mistakes with if, else-if, and else
// -- Start -- Turns off warnings - do not do this at home
#pragma clang diagnostic ignored "-Wtautological-constant-out-of-range-compare"
#pragma clang diagnostic ignored "-Wempty-body"
#pragma clang diagnostic ignored "-Wparentheses"
// -- End -- Turns off warnings - do not do this at home
@mshafae
mshafae / ubuntu-24-lab_config.py
Created August 25, 2024 18:17
Example of a CSUF CPSC 120 lab configuration file targeting Ubuntu 24.04 LTS with the TUSK packages.
#!/usr/bin/env python3
# Tested on Ubuntu 24.04 LTS with tusk packages, https://github.com/mshafae/tusk
"""A lab configuration file. To turn off TODO linter check, set LABSOLUTION in your environment, ex. `LABSOLUTION=YES make lint`"""
from datetime import date
from os import environ
#
# -- START -- For each lab update this section -- START --
@mshafae
mshafae / high_score_demo.py
Created June 26, 2024 18:24
CPSC 386 High score demo in class 2024-06-25
#!/usr/bin/env python3
import pickle
from highscore import HighScore
def main():
# 13 23 33 100 345
print('hello world')
score_list = [HighScore(13), HighScore(23), HighScore(33), HighScore(100), HighScore(345)]
print(score_list)
@mshafae
mshafae / list_with_cpp_ptr.cc
Created April 26, 2024 20:38
Doubly linked list using C++ style shared and unique pointers.
// Gist https://gist.github.com/mshafae/2a5eaf94a0f7f81f725dc8e29872c107
// Filename list_with_cpp_ptr.cc
// CompileCommand clang++ -std=c++17 list_with_cpp_ptr.cc
// Doubly linked list using C++ style shared and unique pointers.
#include <iostream>
#include <memory>
class Printable {
public:
@mshafae
mshafae / list_with_c_ptr.cc
Last active April 26, 2024 20:37
Doubly linked list using C style pointers.
// Gist https://gist.github.com/mshafae/102aefa38e3b28b83ad4357201e93d3a
// Filename list_with_c_ptr.cc
// CompileCommand clang++ -std=c++17 list_with_c_ptr.cc
// Doubly linked list using C style pointers.
#include <iostream>
class Printable {
public:
virtual void Print(std::ostream& out) = 0;
@mshafae
mshafae / cpsc120_words_to_vector.cc
Created April 16, 2024 21:16
Read a file word by word and place contents into a std::vector
// Gist https://gist.github.com/mshafae/d6704ddbb9f360d6ccd53dc979cc4776
// Filename cpsc120_words_to_vector.cc
// CompileCommand clang++ -std=c++17 cpsc120_words_to_vector.cc
// Read a file word by word and place contents into a std::vector
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
@mshafae
mshafae / cpsc120_function_pointer.cc
Last active February 29, 2024 06:24
CPSC 120 C++ pointers to functions and member functions
// Gist https://gist.github.com/mshafae/396db34b08fb9d3b553358778d176f56
// Filename cpsc120_function_pointer.cc
// CompileCommand clang++ -std=c++17 cpsc120_function_pointer.cc
// Demonstrates how to work with functions and member functions as pointers.
// Generally speaking, don't do this unless you need to. You will probably
// find that function objects and lambda expressions will get you more mileage
// in C++ however this knowledge is useful.
#include <iostream>
#include <string>
@mshafae
mshafae / cpsc120_virtual.cc
Created February 28, 2024 18:36
CPSC 120 C++ virtual usage
// Gist https://gist.github.com/mshafae/00875dc88635dfb640278b2259b19fb3
// Filename cpsc120_virtual.cc
// CompileCommand clang++ -std=c++17 cpsc120_virtual.cc
// Demonstrates how virtual works in C++
#include <iostream>
#include <string>
class Fizz {
public: