Skip to content

Instantly share code, notes, and snippets.

@tomtzook
tomtzook / CMakeLists.txt
Last active February 12, 2024 01:20
Compile c++ program for Beaglebone Black PRU with CMake
cmake_minimum_required(VERSION 3.16)
project(bbb_pru C CXX)
set(STACK_SIZE 0x100)
set(HEAP_SIZE 0x100)
set(CMAKE_C_COMPILER ${PRU_COMPILER_HOME}/bin/clpru)
set(CMAKE_CXX_COMPILER ${PRU_COMPILER_HOME}/bin/clpru)
set(CMAKE_LINKER ${PRU_COMPILER_HOME}/bin/lnkpru)
set(CMAKE_AR ${PRU_COMPILER_HOME}/bin/arpru)
@tomtzook
tomtzook / CMakeLists.txt
Created January 16, 2021 11:15
Compiling C++ EFI application with CMake and GNU-EFI, and running in QEMU
cmake_minimum_required(VERSION 3.16.3)
project(cppefi C CXX)
if (NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
endif()
if (NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
endif()
@tomtzook
tomtzook / Makefile
Created January 16, 2021 10:16
Compiling C++ EFI application with Make and GNU-EFI, and running in QEMU
ARCH=x86_64
OBJS=main.o
TARGET=main.efi
CC=gcc
EFI_INCLUDE_PATH=/usr/local/include/efi
EFI_INCLUDES=-I$(EFI_INCLUDE_PATH) -I$(EFI_INCLUDE_PATH)/$(ARCH) -I$(EFI_INCLUDE_PATH)/protocol
@tomtzook
tomtzook / Makefile
Created January 16, 2021 09:50
Compiling C EFI application with Make and GNU-EFI, and running in QEMU
ARCH=x86_64
OBJS=main.o
TARGET=main.efi
CC=gcc
EFI_INCLUDE_PATH=/usr/local/include/efi
EFI_INCLUDES=-I$(EFI_INCLUDE_PATH) -I$(EFI_INCLUDE_PATH)/$(ARCH) -I$(EFI_INCLUDE_PATH)/protocol
@tomtzook
tomtzook / LockFreeQueue.java
Last active May 14, 2020 04:06
Basic lock-free queue in Java
import java.util.concurrent.atomic.AtomicReference;
public class LockFreeQueue<T> {
private final AtomicReference<Node<T>> mHead;
private final AtomicReference<Node<T>> mLast;
public LockFreeQueue() {
Node<T> baseNode = new Node<>(null);
mHead = new AtomicReference<>(baseNode);
@tomtzook
tomtzook / linux_get_cpu_usage.c
Created May 9, 2020 21:34
Reading CPU usage on a Linux computer from a C program
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <dirent.h>
#include <linux/limits.h>
#include <regex.h>
#include <stdbool.h>
#include <stdlib.h>
@tomtzook
tomtzook / linux_get_battery.c
Last active May 5, 2024 06:29
Get battery status on a Linux laptop from a C program
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <dirent.h>
#include <linux/limits.h>
#include <regex.h>
#include <stdbool.h>
#include <stdlib.h>
#define DATADIR "/sys/class/power_supply"