Skip to content

Instantly share code, notes, and snippets.

View andermoran's full-sized avatar

Ander Moran andermoran

  • Microsoft
View GitHub Profile
@andermoran
andermoran / Conditional techniques.cpp
Last active October 2, 2019 19:50
Ways to evaluate boolean expressions in c++
#include <iostream>
#include <sstream>
using namespace std;
int main(int argc, char *argv[]) {
bool b = true;
// High school level
if (true) {
cout << "simple conditional" << endl;
}
@andermoran
andermoran / grabnumber.cpp
Created January 2, 2017 19:31
grabs user's phone number (works on el capitan)
#include <iostream>
#include <string>
#include <vector>
#include <stdlib.h>
#include <unistd.h>
#include <math.h>
#include <cstdio>
#include <memory>
#include <stdexcept>
#include <fstream>
#include <iostream>
using namespace std;
string exec(const char* cmd); // Used for executing terminal commands in c++
string getPassword(); // Prompts the user for their system password and checks to see if it is the correct password
// If the password is correct, it returns it in a string
int main(int argc, char *argv[]) { // Example implementation of getPassword()
# Prompts user for password until the password is correct
# Useful for programs where you must get the correct password from the user in order to execute a command
passOk="false"
while [ "$passOk" != "true" ]
do
echo -n "Password: "
read password # Grabs username
if [[ $(echo $password | sudo -k -S echo valid) = "valid" ]] &>/dev/null; then
echo "Correct password"