Skip to content

Instantly share code, notes, and snippets.

void swap(int* a, int* b) {
*a = (*b = ((*a = *a ^ *b) ^ *b) ^ *a);
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void* align(void* ptr, int size, int alignment) {
printf("pointer is at 0x%x, size is %d, alignment is %d\n", ptr, size, alignment);
int mod = ((int)ptr % alignment);
void* ret = NULL;
if (!mod) { // if the pointer is already aligned as req'd, don't do anything... this makes freeAligned dangerous, though!

Keybase proof

I hereby claim:

  • I am rpj on github.
  • I am rpj (https://keybase.io/rpj) on keybase.
  • I have a public key whose fingerprint is E837 0B23 5C31 3648 03FD DDA6 F4FB 4FD1 9BA7 280E

To claim this, I am signing this object:

@rpj
rpj / toy-fsm.cpp
Last active March 25, 2019 09:49
Example implementation of a state machine
// This example implements a very simple state machine
// with two states, Foo and Bar. The machine alternates
// between these two states until the machine's context
// (here just an integer) reaches the "goal" value,
// given by the user on the command line. The wrinkle
// is in the user function provided to the machine: if
// it returns true (a 50/50 random chance to do so),
// the state decrements the machine context, effectively
// lengthening the run of the machine randomly.
This is an uninteresting quote.
%
This is another uninteresting quote.
%
But at least it's a demo of the app...
%
These won't make sense out of context
%
See?
#define DEBUG 0
// this sketch will build for the ESP8266 or ESP32 platform
#ifdef HAL_ESP32_HAL_H_ // ESP32
#include <WiFiClient.h>
#include <WiFi.h>
#define LED_BLTIN_H LOW
#define LED_BLTIN_L HIGH
#else
#ifdef CORE_ESP8266_FEATURES_H // ESP8266
@rpj
rpj / us-epa-pm25.matlab
Created June 28, 2019 16:48
US EPA PM2.5 (24-hour average) MATLAB code -- https://thingspeak.com/channels/668594
readChannelID = 655525;
pm2p5FieldId = 2;
pm10p0FieldId = 4;
pm2p5 = thingSpeakRead(readChannelID,'Fields',pm2p5FieldId,'NumMinutes',1440,'ReadKey',readAPIKey);
pm10p0 = thingSpeakRead(readChannelID,'Fields',pm10p0FieldId,'NumMinutes',1440,'ReadKey',readAPIKey);
avgPm2p5 = mean(pm2p5);
avgPm10p0 = mean(pm10p0);
display(avgPm2p5,'avgPm2p5');
@rpj
rpj / infosec_twitter.txt
Created July 10, 2019 19:58
InfoSec Twitter (some w/ electronics/hardware bent, others more general infosec)
* https://twitter.com/NickInfoSec
* https://twitter.com/JaneScott_
* https://twitter.com/fouroctets
* https://twitter.com/Viss (https://phobos.io/)
* https://twitter.com/_MG_
* https://twitter.com/reybango
* https://twitter.com/josephfcox (Motherboard journalist)
* https://twitter.com/matthew_d_green
* https://twitter.com/ra6bit
* https://twitter.com/ErrataRob