Skip to content

Instantly share code, notes, and snippets.

# nargoutTest.jl
function nargoutTest(a,b)
@show a, b
return "outp1", "outpTWO"
end
@standarddeviant
standarddeviant / build_and_run.sh
Last active January 18, 2018 04:21
Usable julia embedding example (julia 0.6.2)
# 0.6.2 in the home directory
#export JULIA_DIR="$HOME/julia-d386e40c17/"
#export JULIA_HOME="$JULIA_DIR/bin"
echo "JULIA_DIR = $JULIA_DIR"
echo "JULIA_HOME = $JULIA_HOME"
#
gcc -o wizbang -fPIC -I$JULIA_DIR/include/julia \
-std=gnu99 \
-L$JULIA_DIR/lib -L$JULIA_DIR/lib/julia \
@standarddeviant
standarddeviant / isr_test.ino
Last active April 19, 2018 15:03
Trying to figure out where how to user interrupts safely on a a MKRZERO
#include <SD.h>
// START https://mcuoneclipse.com/2014/01/26/entercritical-and-exitcritical-why-things-are-failing-badly/
#define CpuCriticalVar() uint8_t cpuSR
#define CpuEnterCritical() \
do { \
asm ( \
"MRS R0, PRIMASK\n\t" \
@standarddeviant
standarddeviant / plot_for_FilterCoefficients.jl
Last active May 24, 2018 22:46
Plotting function for FilterCoefficient types from DSP.jl
import Plots
function Plots.plot(fc::FilterCoefficients, w=linspace(0, pi, 500); fs=2,
domag=true, dophase=true,
doimp=false, impn=500,
dostep=false, stepn=500, size=(800, 600))
# calculate plottable vectors
if domag || dophase
h = freqz(fc, w)
end
if doimp
@standarddeviant
standarddeviant / dsp_plot.jl
Last active August 28, 2018 05:00
Prototype of DSP.jl aware plotting via RecipesBase.jl
# using Plots
# theme(:juno)
# pyplot(size=(900, 300))
# plot(randn(10), m=:o)
using DSP
PlottableFilter = Union{FilterCoefficients}
f = digitalfilter(
Lowpass(10, fs=40),
Butterworth(8)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@standarddeviant
standarddeviant / gr_live_window.jl
Last active October 20, 2018 14:59
Simulation of live plotting from received packets using GR.jl in Julia
# gr_live_window.jl
using GR
function keyboard_channel()
# allow 'q' and <ENTER> sequentially pressed on the keyboard to break the loop
count = 0
kb2loop = Channel(10)
@async while true
kb_input = readline(STDIN)
# maybe we hit an error or something got messed up...
@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

@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 / 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.