Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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
#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;
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()
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import io
import numpy as np
from numpy.random import randint, standard_normal
dtypes = ('float32', 'float64', 'int64', 'int32', 'int16')
def make_random_array():
s = randint(1, 5, size=randint(1, 5))
d = dtypes[randint(0, len(dtypes))]
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>My first three.js app</title>
<style>
body { margin: 0; }
canvas { display: block; }
</style>
</head>
import socket
import sys
msgFromClient = "Hello UDP Server"
if len(sys.argv) >= 2:
msgFromClient = sys.argv[1]
bytesToSend = str.encode(msgFromClient)
serverAddressPort = ("192.168.0.174", 3333)