Skip to content

Instantly share code, notes, and snippets.

@calebreister
calebreister / delay.cpp
Created December 18, 2013 06:34
This is just a simple delay function I found on the internet.
#include<stdio.h>
#include<time.h>
void delay(unsigned int mseconds)
{
clock_t goal = mseconds + clock();
while (goal > clock());
}
int main()
{
int i;
@calebreister
calebreister / IOissues.cpp
Last active December 31, 2015 17:09
If an invalid operation is attempted on a stream, the stream variable will subsequently evaluate to false. This can be used to allow the programmer to detect and handle errors as follows...
#include <fstream>
#include <string>
using namespace std;
int main() {
string fileName = "myfile.txt";
ifstream inputData;
//open the file, if error, bail out
@calebreister
calebreister / EnvironVars.py
Created December 18, 2013 06:38
Python script for accessing environment variables.
>>> import os
>>> os.environ.keys()
KeysView(<os._Environ object at 0x013B8C70>)
>>> list(os.environ.keys())
['TMP', 'COMPUTERNAME', 'USERDOMAIN', 'PSMODULEPATH', 'COMMONPROGRAMFILES',
...many more deleted...
'NUMBER_OF_PROCESSORS', 'PROCESSOR_LEVEL', 'USERPROFILE', 'OS', 'PUBLIC', 'QTJAVA']
>>> os.environ['TEMP']
@calebreister
calebreister / xBoxBind.cpp
Created December 18, 2013 06:46
Code for joystick bindings for xbox controller using WPILib for FRC (copied from https://github.com/bobwolff68/FRCTeam1967). "Team 1967 created a Janky Joystick Investigator that puts button and axis values on SmartDashboard. That way when you click a button or move a thumbstick you will be able to figure out which button number/axis that physic…
#include "WPILib.h"
/*******************************
* RobotDemo.cpp *
* *
* Created on: Jan 20, 2013 *
* Author: Team1967 *
*******************************/
/**********************************************************************************************
@calebreister
calebreister / SSHscp.sh
Created December 18, 2013 16:48
This is how you use the scp (secure copy) command to move a file to your SSH server, for instance a --bare Git repo.
scp -P22 -r local_file username@remote_url:/remote/directory/
#P22 is port 22, which SSH uses
@calebreister
calebreister / ArrayString.cpp
Last active January 3, 2016 06:09
Simple program to convert an array to a string.
#include <iostream>
#include <string>
using namespace std;
int main()
{
int array[2][2] =
{ 1, 2, 3, 4 };
string converted = "{";
#ifdef WINDOWS
#include <direct.h>
#define GetCurrentDir _getcwd
#else
#include <unistd.h>
#define GetCurrentDir getcwd
#endif
int main()
{
@calebreister
calebreister / GetHome.cpp
Created March 6, 2014 05:49
Simple code to get the user's home directory. With that information, it is much easier to get to a location on the hard drive such as documents or customization storage.
#include <unistd.h>
#include <sys/types.h>
#include <pwd.h>
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int myuid;
@calebreister
calebreister / ConfigFile.json
Created March 9, 2014 07:10
JSON parsing example written in C++, it uses the JSON++ library (https://bitbucket.org/tunnuz/json/src). I will post my asteroids project once I have completed it and the CS-162 class.
{
"FRAME_RATE": 120,
"LASER": {
"COLOR": [
255,
255,
255
],
"EDGE_DEATH": true,
"PULSE_LIFE": 100
@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[])