This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// .h file | |
// Similar to strncpy but with safe zero-termination behavior | |
// and doesn't fill extra space with zeroes. | |
// Returns true if the string fit without truncation. | |
// Always performs the copy though. | |
bool truncate_cpy(char *dest, size_t destSize, const char *src); | |
template<size_t Count> | |
inline bool truncate_cpy(char(&out)[Count], const char *src) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
uint32_t bit_cast(float f) { | |
uint32_t x; | |
memcpy(&x, &f, 4); | |
return x; | |
} | |
float bit_cast(uint32_t x) { | |
float f; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Simple Arduino timing game. | |
// Made for Nano but probably works on Uno too. | |
// by Henrik Rydgård | |
// [email protected] | |
// | |
// Connect: | |
// * a 0.96" no-name I2C OLED screen to pins SDA=A4,SCL=A5 | |
// * a button to pin 4 and ground (we use internal pullup to avoid adding a resistor) | |
// * a 8-LED RGB strip to pin 2 | |
// and that's pretty much it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Minimal audio streaming using OpenSL. | |
// | |
// Loosely based on the Android NDK sample code. | |
// Hardcoded to 44.1kHz stereo 16-bit audio, because as far as I'm concerned, | |
// that's the only format that makes any sense. | |
#include <assert.h> | |
#include <string.h> | |
// for native audio |