Skip to content

Instantly share code, notes, and snippets.

View mshafae's full-sized avatar

Michael Shafae mshafae

View GitHub Profile
@mshafae
mshafae / vscode_extensions_and_style.sh
Last active October 26, 2022 05:35
VS Code extension and C++ style configuration script.
#!/bin/bash
# Gist https://gist.github.com/5618d1816364893ce9236d5d50272aa2
backup_file ()
{
DATE=`date +"%Y%m%d-%S"`
NAME=${1}
NEWNAME=${NAME}-${DATE}.og
echo "Copying ${NAME} to ${NEWNAME}"
@mshafae
mshafae / cpsc120_rename_jpeg.cc
Last active October 22, 2022 17:00
CPSC 120 Demonstrate how to use the filesystem library and functions to find files and rename them.
// Gist https://gist.github.com/f6a5ebf19ad736a3bdcf28be34b84cc4
// To try out this program, you don't need to have a folder full of JPEG images.
// Do the following from from the command line to create some sample data to
// demonstrate how this program works.
// $ mkdir sample_data
// $ cd sample_data
// $ touch blue.jpeg red.jpeg yellow.jpeg orange.jpeg green.jpeg purple.jpeg
// $ cd ..
@mshafae
mshafae / cpsc120_write_message.cc
Last active October 30, 2024 06:25
CPSC 120 Read a line of text from cin and then write the line out to a file
// Gist https://gist.github.com/30ad98e4ca6f0aa45db9e9a31c5625af
// Filename cpsc120_write_message.cc
// CompileCommand clang++ -std=c++17 cpsc120_write_message.cc
// Read a line of text from cin and then write the line out to a file
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
@mshafae
mshafae / cpsc120_skip_first_array.cc
Created October 20, 2022 00:30
CPSC 120 Exampl of how to skip the first element of an array using a boolean flag.
// Gist https://gist.github.com/746e191172af461f09f7b06bbebd3680
#include <array>
#include <iostream>
#include <string>
int main(int argc, char const* argv[]) {
std::array<int, 6> my_array{10, 11, 12, 13, 14, 15};
bool should_skip_first{true};
@mshafae
mshafae / cpsc120_skip_first_arg.cc
Last active December 13, 2023 23:17
CPSC 120 Example of how to skip the first command line argument using a boolean flag.
// Gist https://gist.github.com/77e6c030cb519c2cbb221a00eff2cbe2
#include <iostream>
#include <string>
#include <vector>
int main(int argc, char const* argv[]) {
std::vector<std::string> arguments{argv, argv + argc};
bool should_skip_first{true};
@mshafae
mshafae / cpsc120_fscat.cc
Last active April 16, 2024 21:11
CPSC 120 Read a file line by line and print the contents to the terminal. Use the filesystem library for the path instead of a std::string.
// Gist https://gist.github.com/5b341c7d272ce7442754699351008d3e
// Filename cpsc120_fscat.cc
// CompileCommand clang++ -std=c++17 cpsc120_fscat.cc
// An implementation of the `cat` program which prints the contents of a file
// to the std::cout (stdout) using the filesystem::path type.
#include <filesystem>
#include <fstream>
#include <iostream>
#include <string>
@mshafae
mshafae / cpsc120_find_value.cc
Last active December 13, 2023 23:17
CPSC 120 Find a value in an array.
// Gist https://gist.github.com/ccd1c720a571b84e855c59e00f66df99
#include <iostream>
#include <string>
#include <vector>
int main(int argc, char const* argv[]) {
vector<std::string> arguments{argv, argv + argc};
bool found{false};
@mshafae
mshafae / cpsc120_filter.cc
Last active December 13, 2023 23:17
CPSC 120 Filter through an array using an if condition and continue.
// Gist https://gist.github.com/37b21d3ba3d4630be6d97dae1b8fbde1
#include <array>
#include <iostream>
int main(int argc, char const* argv[]) {
std::array<int, 6> my_array{10, 11, 12, 13, 14, 15};
for (const int& number : my_array) {
if (number % 2 != 0) {
@mshafae
mshafae / cpsc120_cat.cc
Last active April 16, 2024 21:07
CPSC 120 Open a file and read it line by line; print the contents to your terminal.
// Gist https://gist.github.com/49124a3e4c73ad44ac331dc023b61326
// Filename cpsc120_cat.cc
// CompileCommand clang++ -std=c++17 cpsc120_cat.cc
// An implementation of the `cat` program which prints the contents of a file
// to the std::cout (stdout).
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
@mshafae
mshafae / cpsc120_pwd.cc
Last active October 20, 2022 00:43
CPSC 120 Program that mimics the command pwd.
// Gist https://gist.github.com/fba16c441b459231d6fc5d2e35d046aa
#include <filesystem>
#include <iostream>
int main(int argc, char const *argv[]) {
// works just like `pwd`
std::cout << std::filesystem::current_path().string() << "\n";
return 0;