Skip to content

Instantly share code, notes, and snippets.

View andermoran's full-sized avatar

Ander Moran andermoran

  • Microsoft
View GitHub Profile
# 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"
#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()
@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>
@andermoran
andermoran / sendMessageThruTerminal.sh
Created April 12, 2017 18:41
Allows sending of an iMessage thru terminal. Can't send message to self, yet...
#!/bin/sh
USAGE=$'Usage: imessage <number> <text>\nExample: message 9121231234 \"Hello!\"'
if [ "$#" -ne "2" ]; then
echo "$USAGE"
exit 1;
fi
exec <"$0" || exit;
for i in {1..12} # Reads the first x lines of the program
do
read v
@andermoran
andermoran / calculateParallelResistance.py
Created July 21, 2017 14:42
A program that finds the total resistance of n parallel resistors
#!/usr/bin/python
import numbers
def findDivisor(num):
# 2,3 are the most common divisor for many numbers hence going by divisor of 2,3 can be quicker
# if not then by the same number as divisor
if num%2 == 0:
return 2
elif num%3==0:
return 3
@andermoran
andermoran / bones.py
Created October 26, 2018 16:56
Calculate a person's height given a size of their bone, race, sex, and age
bone_coefficient = -1;
addition_constant = -1;
error_margin = -1;
bone_length = -1;
bone_coefficients = [[[0 for col in range(2)]for row in range(3)] for x in range(6)]
# Femur
bone_coefficients[0][0][0] = 2.32
bone_coefficients[0][0][1] = 2.47
bone_coefficients[0][1][0] = 2.10
@andermoran
andermoran / contact_reaper.py
Created March 16, 2019 17:32
A small program that grabs the information of every contact on a user's mac
import plistlib
import os
import sys
import getpass
# usage: python contact_reaper.py or python3 contact_reaper.py
# tested on macOS Mojave (10.14)
def get_main_dir_path():
return "/Users/" + getpass.getuser() + "/Library/Application Support/AddressBook/Sources/"
@andermoran
andermoran / funkyClang.c
Created August 22, 2019 23:24
Weird clang behavior
// https://twitter.com/zneakr/status/1164651753993715712
/* So @zneakr tweeted about this weird behavior and I decided to tinker with his example. In order to optimize, clang
assigns fun_ptr to leak_all_my_secrets no matter what. This leads to "I have 9 toes" being printed no matter the
result of the if statement. Super weird behavior from clang and I just wanted to make a note of it :)
To reproduce this result:
clang funkyClang.c -O1 -o funkyClang; ./funkyClang
*/
#include <stdlib.h>
@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 / angular-example-gist.ts
Last active October 3, 2019 15:17
This dynamic style in angular allows us to create dynamic css classes at runtime
let hrStyle: string = `
.underline {
height: .25rem;
width: 0%;
margin: 0;
background: black;
border: none;
transition: .3s ease-in-out;
position: relative;
}