Skip to content

Instantly share code, notes, and snippets.

View sophec's full-sized avatar
🖤
[[maybe_unused]]

Sophie Eccles sophec

🖤
[[maybe_unused]]
View GitHub Profile
@sophec
sophec / oodle.cpp
Created October 13, 2016 03:00
Replaces every vowel in given phrase(s) with "oodle"
// compile with:
// g++ oodle.cpp -o oodle -std=c++14
#include <iostream>
#include <string>
#include <regex>
#include <vector>
int main(int argc, char* argv[]) {
if (argc == 1) {
@sophec
sophec / binadd.cpp
Last active October 3, 2016 16:12
Add and subtract ints in C++ without using + or - operators.
#include <iostream>
// not sure why i included this but now i will just leave it here. yolo
#include <string>
// add a and b
int binadd(int a, int b) {
int carry = (a & b) << 1;
int result = a ^ b;
if (carry == 0)
return result;
@sophec
sophec / calcpi.cpp
Last active October 3, 2016 15:15
Calculate pi using n iterations, t threads, and d decimal places.
// compile with:
// g++ -O3 calcpi.cpp -o calcpi.o -std=c++11
// run with:
// ./calcpi.o <threads> <iterations> <decimal places>
// it's recommended to use multiple threads if possible, but to always specify iterations, as if you don't, it will take forever and a half.
// decimal places is completely optional, and goes up to 51. by default it uses 10 digits.
// NOTE: KEEP IN MIND THIS IS AN ESTIMATION. IT WILL BE USUALLY ACCURATE TO 10 OR SO DIGITS, BUT PAST THAT WILL TAKE MORE ITERATIONS.
// at the moment, time is bugged. if you run with one thread, it will be accurate,
@sophec
sophec / concatString.m
Last active March 18, 2021 12:50
How to easily concatenate strings in Objective C
// This is a genius macro from EthanB on StackOverflow
// It's meant to work around Obj-C's missing string concatenation operator
// answer: http://stackoverflow.com/a/16862414/2712525
#define stringConcat(...) \
[@[__VA_ARGS__] componentsJoinedByString:@""]
// so now instead of this...
NSString *str = @"things are ";
NSString *str2 = [str stringByAppendingString:@"cool."];
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int place = 1;
int places = 100;
int main(int argc, char* argv[]) {
if (argc >= 3) {
places = atoi(argv[2]);
@sophec
sophec / speakfile.sh
Last active August 13, 2016 17:09
Bash file to speak a file out loud on OS X, with options for volume, voice, and interactive reading.
#! /bin/bash
if (( $# == 1 )) && [ "$1" == "?" ]
then
say -v ?
echo ""
echo "Voices should be specified in quotes if 2+ words."
exit 0
fi
#include <iostream>
#include <regex>
#include <string>
#include <fstream>
#include <vector>
#include <ctime>
#include <thread>
using namespace std;
@sophec
sophec / github powershell.ps1
Created April 8, 2016 20:59
A few git-related methods for PowerShell.
# Set up the github profile, as outlined in the profile itself.
# this will only work if you have installed github desktop
. (Resolve-Path "$env:LOCALAPPDATA\GitHub\shell.ps1")
clear
#on this line I run archeyjs, but I removed that here.
# define your github folder path
$gitfolder="C:\path\to\github\folder"
@sophec
sophec / Day9.cpp
Created December 9, 2015 22:42
This is how I did Day9. Not the most efficient, but I am lazy and am willing to wait a bit longer. Also, this /can/ be wrong, but most likely won't be.
#include "stdafx.h"
#include "Day9.h"
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <algorithm>
#include <map>
using namespace std;
@sophec
sophec / Day8.cpp
Last active December 8, 2015 22:13
Part 1 of Day 8 of Advent of Code. The reason for it being a whole new class called Day8 is that I use a single main.cpp to run each day's code, just instantiating a Day6, 7, 8, etc... and using the run() method.
#include "stdafx.h"
#include "Day8.h"
#include <iostream>
#include <string>
#include <fstream>
#include <regex>
using namespace std;
// this is just to make my code later on cleaner and simpler, whereas up here I don't really care.