Skip to content

Instantly share code, notes, and snippets.

View mshafae's full-sized avatar

Michael Shafae mshafae

View GitHub Profile
@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>
@mshafae
mshafae / cpsc120_filelines_to_vector.cc
Last active April 16, 2024 21:12
CPSC 120 Example of reading a file line by line, storing it in a std::vector, and then selecting random lines from the vector to print.
// Gist https://gist.github.com/mshafae/4d282935ea5deaf8c2e6aca83a9fcac8
// Filename cpsc120_filelines_to_vector.cc
// CompileCommand clang++ -std=c++17 cpsc120_filelines_to_vector
// Read a file line by line and place contents into a std::vector
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
@mshafae
mshafae / cpsc120_filelines_to_vector.cc
Last active April 16, 2024 21:13
CPSC 120 Example of reading a file line by line and storing each line into a std::vector
// Gist https://gist.github.com/mshafae/4d282935ea5deaf8c2e6aca83a9fcac8
// Filename cpsc120_filelines_to_vector.cc
// CompileCommand clang++ -std=c++17 cpsc120_filelines_to_vector.cc
// Read a file line by line and place contents into a std::vector
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
@mshafae
mshafae / cpsc120_double_comparison.cc
Last active October 8, 2024 18:58
Demonstrating how doubles are approximating Real numbers and how direct comparison must be avoided.
// Gist https://gist.github.com/mshafae/77d3cda92a90746210f3224c1cf83555
// Filename cpsc120_double_comparison.cc
// CompileCommand clang++ -std=c++17 cpsc120_double_comparison.cc
// Demonstrating how doubles are approximating Real numbers and how direct
// comparison must be avoided.
#include <iomanip>
#include <iostream>
// lhs stands for "left hand side"