Skip to content

Instantly share code, notes, and snippets.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import threading
import serial
import queue
import time
# make thread-safe queue for data logging/writing
global_dataMsgQ = queue.Queue()
# make a thread-safe queue to inform different threads when it's time to stop
global_stopQ = queue.Queue()
#include <stdio.h> // for printf
#include <math.h> // for testing only, not used by cordic
#include "cordic-32bit.h" // for actual cordic algo
//Print out sin(x) vs fp CORDIC sin(x)
int main(int argc, char **argv)
{
float p;
// sin_int, cos_in;
@standarddeviant
standarddeviant / two_timing.py
Created January 3, 2020 15:37
Simple script to calculate the error of polling multiple sample rates with Python `time.sleep`
import time
import numpy as np
fs_list = [120.0, 2.0]
dt_list = [1/fs for fs in fs_list]
prevt_list = [time.time(), ] * len(fs_list)
sample_times = [list() for fs in fs_list]
timeout_seconds = 10
sleep_seconds = min(dt_list) * 0.1
@standarddeviant
standarddeviant / golf_dates.ipynb
Created November 25, 2019 15:20
Days Between Trump's Golf Outings
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@standarddeviant
standarddeviant / base.c
Last active November 5, 2019 12:44
Soundpipe ex_biquad only, embedded exercise
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#ifndef NO_LIBSNDFILE
#include <sndfile.h>
#endif
#include "soundpipe.h"
int sp_create(sp_data **spp)
@standarddeviant
standarddeviant / git_version_hooks_for_c.py
Created June 6, 2019 03:33
A python script to generate git hooks to dump git version to a C header
import os
git_version_hook_lines = [
"#!/bin/sh\n",
"git_version_str=$(printf '#define GIT_VERSION_STRING \"%s\"' $(git rev-parse --short=16 HEAD))\n",
"echo $git_version_str\n",
"echo $git_version_str > ./git_version.h\n",
]
hooks_dir = os.path.join(os.getcwd(), '.git', 'hooks')
@standarddeviant
standarddeviant / WarCardSim.ipynb
Created December 30, 2018 03:55
Simulation of War, the card game
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@standarddeviant
standarddeviant / listen_connect_test.jl
Last active December 9, 2018 12:12
Julia Network listen/connect on IPv4(0)
# On a normal machine, this should run just fine
# But some machines require an agressive network security policiy
# And this simple test will fail
using Sockets
TEST_PORT = 12567
# Listen asynchronously
listen_task = @async begin
@standarddeviant
standarddeviant / README.md
Last active November 19, 2018 22:38
Hardware Clock Drift Measurement with Python + NTP

Hardware Clock Drift Measurement with Python + NTP

I've been tinkering with microcontroller code and have learned about "real time clocks" and how computers attempt to keep accurate time.

More recently, I've become loosely familiar with NTP at the UDP level and realized that I could measure the clock drift over time just by repeatedly fetching hardware time and NTP time and comparing their differences over time.

I found that my desktop machine's RTC drifted by about 6 seconds in 33 hours. This kind of error is acceptable for some applications and unacceptable for others.

I did this on a Windows 10 machine, but I first