Skip to content

Instantly share code, notes, and snippets.

@AliBarber
AliBarber / time-inode.md
Last active October 12, 2022 11:00
Ordering Files by Creation Order When the System Clock is Reset

File Creation Ordering

Problem Statement:

We wish to sort a set of arbitrary files by the order in which they were created. We cannot however rely on the system clock (hence the 'created at' time), file name, or time since reboot (e.g. millis). We do however have a linux operating system and file system. We should therefore be able to use the inode ids of the file to order them.

Example

Setup

Create some files, resetting the system clock in between each creation. The files will start with a number that is deliberately out of sequence in order to show that we're not sorting just by name.

#include <iostream>
#include <math.h>
using namespace std;
int main(int argc, char **argv){
if(argc != 2){
cout << "Usage:\n" << argv[0] << "\t BASE_FREQUENCY" << endl;
return 1;
}
@AliBarber
AliBarber / pwmcalc.cpp
Created January 2, 2021 16:44
PWL of PWM Pulses
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#define RISE_FALL_TIME 1e-9
#define LOW 0.0
#define HIGH 3.3
#define MAX(a,b) ((a) > (b)) ? (a) : (b)
@AliBarber
AliBarber / short2half.kernel.c
Last active December 12, 2020 19:13
Convert a signed short int to half precision floating point on the GPU with OpenCL
unsigned char constant BitReverseTable256[256] =
{
# define R2(n) n, n + 2*64, n + 1*64, n + 3*64
# define R4(n) R2(n), R2(n + 2*16), R2(n + 1*16), R2(n + 3*16)
# define R6(n) R4(n), R4(n + 2*4 ), R4(n + 1*4 ), R4(n + 3*4 )
R6(0), R6(2), R6(1), R6(3)
};
int constant MultiplyDeBruijnBitPosition[32] =
{
@AliBarber
AliBarber / AudioPipe.cpp
Last active June 25, 2017 15:02
Pipe audio from an input device to another input device using PortAudio. Tested / Built on Mac, should be cross platform. Not the most efficient - working on callback based method.
/*
* AudioPipe.cpp - Alastair Barber 2017.
* Will open a device, read from it, and write the audio to another device. Eg. Mic -> HDMI sound output
*/
#include "portaudio.h"
#include <iostream>
#include <signal.h>
#include <unistd.h>
#include <stdlib.h>