Skip to content

Instantly share code, notes, and snippets.

@calebreister
calebreister / ParseHeader.py
Created August 10, 2014 02:28
This script parses a C or C++ header and generates an implementation file based on the function prototypes found within. It is designed to take one class or namespace at a time, so the scope resolution is based off of the header file's name.
#!/usr/bin/env python3
#This program parses C/C++ header files and outputs a corresponding
#implementation file. It uses a regular expression to isolate function
#prototypes and converts them to implementations.
#This program is designed to take a single class or namespace as input.
import sys
import os
import re
@calebreister
calebreister / Queue.h
Last active August 29, 2015 14:05
These files contain simple array-based stack and queue templates. I designed them to be Arduino-compatible. They do not use any dynamic memory (which can cause various issues on Arduino boards due to their low specs) and I have kept features to a minimum. Note that they can have multiple sizes via template. This is not necessarily efficient on m…
#ifndef QUEUE_H
#define QUEUE_H
template <class type, unsigned int SIZE>
class Queue {
private:
type data[SIZE];
int b;
int f;
void inc(int& x);
@calebreister
calebreister / makefile
Created September 9, 2014 04:47
I have been messing with Fortran some lately... here is some code that allows you to call a Fortran function from a C program. It is very simple at this point
test: test.o mysum.o
gcc -o test test.o mysum.o -lgfortran
test.o: test.c
gcc -c test.c
mysum.o: mysum.f90
gfortran -ffree-form -c mysum.f90
@calebreister
calebreister / backup.sh
Last active August 29, 2015 14:10
This is a shell script that runs incremental backups on the btrfs filesystem. I used the instructions on the wiki for the initial setup. It is designed to work with the Ubuntu btrfs configuration. THIS SCRIPT COMES WITH ABSOLUTELY NO WARRANTY. Any loss of data is not my responsibility. However, it does work for me, and I regularly use it.
#!/bin/sh
#Find a date in file name:
#ls | grep -E $datematch
if [ "$(whoami)" != "root" ]; then
echo Please run this script as root.
exit
fi
#ifndef _PID_SOURCE_
#define _PID_SOURCE_
#include <iostream>
#include <cmath>
#include "pid.h"
using namespace std;
class PIDImpl
@calebreister
calebreister / threadTest.cc
Last active August 29, 2015 14:16
Basic multithread testing. We may use something like this to run a camera on our 2015 FRC robot.
//g++ test.cc -std=c++11 -lpthread
#include <iostream>
#include <thread>
#include <chrono>
using namespace std;
void f() { //function to run in 2nd thread
for (int i = 0; i < 10; ++i)
{
@calebreister
calebreister / synaptic_quickfind.sh
Last active November 25, 2016 17:52
Enables the quick search bar in Synaptic Package Manager in LXDE (tested on Raspberry Pi and Lubuntu)
sudo apt-get install apt-xapian-index && sudo update-apt-xapian-index -vf
@calebreister
calebreister / NumIntegral.cc
Created March 28, 2015 05:53
Simple numerical integration algorithm.
// https://helloacm.com/c-function-to-compute-numerical-integral-using-function-pointers/
double integral(double(*f)(double x), double a, double b, int n) {
double step = (b - a) / n; // width of each small rectangle
double area = 0.0; // signed area
for (int i = 0; i < n; i ++) {
area += f(a + (i + 0.5) * step) * step; // sum up each small rectangle
}
return area;
}

Assuming that you have a program running in the foreground, press ctrl-Z, then:

[1]+  Stopped                 myprogram
$ disown -h %1
$ bg 1
[1]+ myprogram &
$ logout

If there is only one job, then you don't need to specify the job number. Just use disown -h and bg. Explanation of the above steps: