Skip to content

Instantly share code, notes, and snippets.

View justbuchanan's full-sized avatar

Justin Buchanan justbuchanan

View GitHub Profile
@justbuchanan
justbuchanan / .gitignore
Last active October 4, 2016 15:50
cpp-channel test
main
cpp-channel
@justbuchanan
justbuchanan / main.cpp
Created July 24, 2016 17:29
Move semantics vs pass by reference on heap in c++
#include <iostream>
#include <vector>
#include <memory>
using namespace std;
struct MyObject {
std::vector<char> v;
char addr;
char port;
#!/usr/bin/env python2
#
# This script builds a ball-placement SSL Referee message for the yellow team
# and repeatedly broadcasts it. Usage:
# ./send_ssl_placement_cmd.py <x coord> <y coord>
#
# Install protobuf:
# pip2 install protobuf
#
# Compile protobuf files (this creates referee_pb2.py):
@justbuchanan
justbuchanan / keybase.md
Created May 22, 2016 01:31
Keybase GitHub proof

Keybase proof

I hereby claim:

  • I am justbuchanan on github.
  • I am justbuchanan (https://keybase.io/justbuchanan) on keybase.
  • I have a public key ASD1L3Wi4J_PeKhF5_YV_X1V1B9Em2Sepm6HRtob8TqFRwo

To claim this, I am signing this object:

/*
This is a simple program for the MBED intended to determine what happens if a signal for a thread is
set before the corresponding wait is called. It behaves as expected, so the bug I'm tracking down is somewhere else...
*/
#include <mbed.h>
#include <rtos.h>
#include <cmsis_os.h>
void thread(const void* arg) {
@justbuchanan
justbuchanan / readme.md
Last active March 1, 2021 17:21
Show icons for open programs in i3's status bar. See a demo here: http://gfycat.com/AfraidAmusingCoyote
@justbuchanan
justbuchanan / to_binary.hpp
Created February 25, 2016 17:28
Get the binary representation of integral types in C++ as strings
#include <string>
template<typename TYPE, char BYTE_SEPARATOR = ' '>
std::string toBinary(TYPE val) {
std::string str("b");
for (int i = sizeof(TYPE)*8-1; i >= 0; i--) {
str += ((val & 1 << i) ? "1" : "0");
if (i % 8 == 0 && i !=0 ) str += BYTE_SEPARATOR;
}
return str;
@justbuchanan
justbuchanan / main.cpp
Last active February 17, 2016 20:49
Stream-based logging test
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
class LogHelper : public stringstream {
public:
LogHelper(string level) {
@justbuchanan
justbuchanan / sources.list
Created September 16, 2015 20:21
/etc/apt/sources.list from an Ubuntu 14.04 installation
#deb cdrom:[Ubuntu 14.04.3 LTS _Trusty Tahr_ - Beta amd64 (20150805)]/ trusty main restricted
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://us.archive.ubuntu.com/ubuntu/ trusty main restricted
deb-src http://us.archive.ubuntu.com/ubuntu/ trusty main restricted
## Major bug fix updates produced after the final release of the
## distribution.
deb http://us.archive.ubuntu.com/ubuntu/ trusty-updates main restricted
@justbuchanan
justbuchanan / ParameterByValueVsByRef.md
Last active May 26, 2022 20:26
Performance test of passing a small struct by value vs by reference in C++

Comparison of passing a small struct by value vs by reference in C++

Below are the results from running this on my 2011 MacBook Pro with an Intel Core i7-2635QM CPU @ 2.00GHz.

With no compiler optimizations turned on:

$ make compare
time ./by-ref
 7.07 real 7.05 user 0.00 sys