Skip to content

Instantly share code, notes, and snippets.

@calebreister
calebreister / BinTree.cc
Last active August 29, 2015 14:01
Simple Binary Tree (in class code)
#include <iostream>
#include <iomanip>
#include <cmath>
#include <stack>
#include <array>
#include <utility>
#include <cstdlib>
#include <ctime>
using namespace std;
@calebreister
calebreister / Queue.cc
Created April 28, 2014 23:29
This is a simple queue implementation (both array and linked list based) that I created in class.
#include <iostream>
using namespace std;
//A queue is a FIFO (first-in-first-out data structure
const int SIZE = 5;
class QueueA {
private:
int data[SIZE];
@calebreister
calebreister / Dog.hh
Created April 17, 2014 02:15
In class operator overloading and template examples.
#ifndef DOG_HH_
#define DOG_HH_
#include <ostream>
class Dog {
private:
int weightLbs;
int ageYears;
public:
@calebreister
calebreister / LinkedList.cc
Created April 7, 2014 23:19
A very very very very very simple linked list implementation. It it will probably not compile at this point, it is incomplete.
#include <iostream>
struct Node {
int item;
Node* next;
};
class LinkedList {
private:
Node* head;
@calebreister
calebreister / sonicRead.cc
Created April 3, 2014 17:05
This could be useful for some people involved in FIRST robotics, but I posted it in order to get it logic-checked.
//earlier in the program I run this to initialize the array
for (int i = 0; i < SONIC_SAMPLE * 2; i++)
sonicRead();
//Averages and returns the inch reading of the ultrasonic sensor
//Updates sonicHotZone
SonicData robot::sonicRead()
{
SonicData out;
out.avg = 0;
@calebreister
calebreister / ArduinoHelperFx.ino
Last active October 17, 2022 21:53
This is a list of useful functions for the Arduino. I found it posted on the MAKE magazine website.
//http://makezine.com/2014/03/24/arduino-helper-functions-2/
/*Here’s some helpful functions for Arduino.
Blinking an LED
This function blinks an LED light as many times as requested, at the requested blinking rate.
*/
void blinkLED(byte targetPin, int numBlinks, int blinkRate) {
for (int i=0; i < numBlinks; i++) {
digitalWrite(targetPin, HIGH);
delay(blinkRate);
@calebreister
calebreister / Strings.py
Created March 19, 2014 01:43
This is a simple string manipulation example in Python... the program is based loosely on the 1st assignment I did in CS162.
def checkVowels(inStr):
#Expects inStr to be 1 character long
vowels = ['A','a','E','e','I','i','O','o','U','u']
for v in range(len(vowels)):
if inStr == vowels[v]:
return True
return False
def rmVowels(inStr):
out = []
@calebreister
calebreister / TwentyOneFun.py
Last active August 29, 2015 13:57
This is a console implementation of the game 21 (Blackjack). I did it in C++ for CS161, but now I have redone it in Python and made it more "Pythonic".
#!/usr/bin/env python3.3
import random
from game import *
deck = util.deckInit()
random.shuffle(deck)
print(deck)
#Creating the Pythonic equivalent of a do...while loop
@calebreister
calebreister / sfml-depend.sh
Created March 13, 2014 15:49
Installs the dependencies for SFML using apt on Ubuntu, it should also work on other Debian systems.
#!/usr/bin/bash
# Install all necessary dependencies for Debian/Ubuntu systems
# Install CMake GUI
sudo apt-get install cmake-gui
# SFML Dependencies
sudo apt-get install libpthread-stubs0-dev
sudo apt-get install libgl1-mesa-dev
sudo apt-get install libx11-dev
@calebreister
calebreister / CPP-CLI-Parameters.cc
Created March 9, 2014 07:21
Simple example of a use of argc and argv.
#include <iostream>
#include <fstream>
using namespace std;
const int WIDTH = 2000;
const int HEIGHT = 300;
const int COLOR = 3; //0=red, 1=green, 2=blue
//void main(int argc, char** args[])