Skip to content

Instantly share code, notes, and snippets.

View mshafae's full-sized avatar

Michael Shafae mshafae

View GitHub Profile
@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:
@mshafae
mshafae / cpsc120_animated_image.cc
Last active December 13, 2023 23:19
CPSC 120 Example of creating an animated gif using Graphics Magick.
// Gist https://gist.github.com/mshafae/80d95db3aeb0de7d181440ce47f32a36
// Filename cpsc120_animated_image.cc
// CompileCommand clang++ -std=c++17 -I /usr/include/GraphicsMagick cpsc120_animated_image.cc -lGraphicsMagick++ -lGraphicsMagick
// Create a simple, small image from a given filename. GraphicsMagick
// will figure out how to output to the given file format.
// Supported formats: http://www.graphicsmagick.org/formats.html
// Example:
// clang++ -std=c++17 -I /usr/include/GraphicsMagick cpsc120_animated_image.cc -lGraphicsMagick++ -lGraphicsMagick
// ./a.out my_image.jpg
@mshafae
mshafae / cpsc120_fancy_image.cc
Last active December 13, 2023 23:18
CPSC 120 Example of creating an image using GraphicsMagick and using some math to make it look fancy.
// Gist https://gist.github.com/mshafae/9218c947894149cabdebadb1a1083000
// Filename cpsc120_fancy_image.cc
// CompileCommand clang++ -std=c++17 -I /usr/include/GraphicsMagick -lGraphicsMagick++ cpsc120_fancy_image.cc
// Create a simple, small image from a given filename. GraphicsMagick
// will figure out how to output to the given file format.
// Supported formats: http://www.graphicsmagick.org/formats.html
// Example:
// clang++ -std=c++17 -I /usr/include/GraphicsMagick -lGraphicsMagick++ cpsc120_fancy_image.cc
// ./a.out my_image.jpg
@mshafae
mshafae / cpsc120_image_with_text.cc
Last active December 13, 2023 23:18
CPSC 120 Example of creating an image using GraphicsMagick and rasterizing some text into the image. Uses X11 color names instead of RGB color values.
// Gist https://gist.github.com/mshafae/c60dcd64a98e664c6d75115e7f57fe41
// Filename cpsc120_image_with_text.cc
// CompileCommand clang++ -std=c++17 -I /usr/include/GraphicsMagick -lGraphicsMagick++ cpsc120_image_with_text
// Create a simple, small image from a given
// filename. GraphicsMagick will figure out how to output to the given file
// format.
// Supported formats: http://www.graphicsmagick.org/formats.html
// Example:
// clang++ -std=c++17 -I /usr/include/GraphicsMagick -lGraphicsMagick++ cpsc120_image_with_text
@mshafae
mshafae / cpsc120_food_class.cc
Created November 15, 2023 08:43
Create a vector of objects. The object has multiple data members.
// Gist https://gist.github.com/mshafae/7dfcb98e197573a97b0766d48af7a6d2
// Filename cpsc120_food_class.cc
// CompileCommand clang++ -std=c++17 cpsc120_food_class.cc
// Create a vector of objects. The object has multiple data members.
#include <iostream>
#include <string>
#include <vector>
@mshafae
mshafae / cpsc120_2D_vector_pt2.cpp
Created November 14, 2023 05:59
Create a vector of vectors, the inner vectors contain strings
// Gist https://gist.github.com/mshafae/759d0d17b0bb03873516dcc9e16f5dca
// Filename cpsc120_2D_vector_pt2.cpp
// CompileCommand clang++ -std=c++17 cpsc120_2D_vector_pt2.cpp
// Create a vector of vectors, the inner vectors contain strings
// Note that C++ is row major order.
#include <iostream>
#include <string>
#include <vector>
@mshafae
mshafae / cpsc120_vector.cc
Created November 13, 2023 21:25
Working with C++ vectors.
// Gist https://gist.github.com/mshafae/ff7818bd3514ad0539e90b5d2f8933b3
// Filename cpsc120_vector.cc
// CompileCommand clang++ -std=c++17 cpsc120_vector.cc
// Working with C++ vectors.
#include <iostream>
#include <vector>
int main(int argc, char const* argv[]) {
@mshafae
mshafae / cpsc120_2D_vector.cpp
Last active December 13, 2023 23:18
Create a vector of vectors, the inner vectors contain strings
// Gist https://gist.github.com/mshafae/eb239941e0171dcf564d91a3f75c64a7
// Filename cpsc120_2D_vector.cpp
// CompileCommand clang++ -std=c++17 cpsc120_2D_vector.cpp
// Create a vector of vectors, the inner vectors contain strings
// Note that C++ is row major order.
#include <iostream>
#include <string>
#include <vector>