Skip to content

Instantly share code, notes, and snippets.

View willeccles's full-sized avatar
🖤
probably out driving

Will Eccles willeccles

🖤
probably out driving
View GitHub Profile
@willeccles
willeccles / 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,
@willeccles
willeccles / 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;
@willeccles
willeccles / 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) {
@willeccles
willeccles / README.md
Last active October 27, 2016 02:36
how to thread

Threading

So, you want to learn about std::thread added in C++11? This will include that and a small bit on lambdas, which were also added.

How to make two things happen at once:

note: all code samples assume that <thread>, <iostream>, and (later) <future> have been included.

// both threads will run this
void printThreadNum(int num) {
@willeccles
willeccles / bin.c
Last active December 27, 2016 04:46
Add and subtract numbers using bitwise operators :D
// add a and b
int binadd(int a, int b) {
int carry = (a & b) << 1;
int result = a ^ b;
if (carry == 0)
return result;
else
result = binadd(result, carry);
return result;
@willeccles
willeccles / gitrepo
Last active January 27, 2017 16:11
A bash script to easily open a repo on GitHub.com
#! /bin/bash
# likely only works on OS X, but hey, that's just too bad :)
# default username if one is not given
username="willeccles"
if (( $# >= 2 )); then
open "https://www.github.com/$1/$2"
elif (( $# == 1 )); then
@willeccles
willeccles / javacr
Last active February 7, 2017 16:13
Compile and run a java program in one command.
#! /bin/bash
echo Compiling $1...
# make the build directory if it doesn't exist already
mkdir -p "`pwd`/build"
javac "$1" -d "`pwd`/build"
rc=$? # return code of javac
[ $rc -eq 0 ] || exit $rc; # exit if the return code of the compilation isn't 0
@willeccles
willeccles / stack.h
Last active April 11, 2017 17:29
Basic link-based stack implementation in C++.
#ifndef STACK_H
#define STACK_H
#include <iostream>
template <class T>
class stack {
private:
// the node class to be used in the stack
template <class nT = T>
@willeccles
willeccles / newstack.h
Last active May 9, 2017 16:33
Node-based stack in C++ using C-style pointers vs. C++11 smart pointers.
/**
* This is the right way to do this in C++11+, which is a lot of +'s.
* This uses the std::shared_ptr type to manage memory and access to it magically.
*/
#ifndef STACK_H
#define STACK_H
#include <iostream>
#include <vector>
@willeccles
willeccles / english wordlist.txt
Created September 27, 2017 18:32
a list of english words, can be used for spellcheck or whatever you want :)
This file has been truncated, but you can view the full file.
aa
aah
aahed
aahing
aahs
aal
aalii
aaliis
aals
aardvark