Skip to content

Instantly share code, notes, and snippets.

View SharpCoder's full-sized avatar
🛰️
inventing

Josh Cole SharpCoder

🛰️
inventing
View GitHub Profile
@SharpCoder
SharpCoder / HMC5883L.cpp
Last active April 19, 2021 22:29
HMC5883L Magnetometer Code
#include "compass.h"
// COMPASS_MULTIPLIERS are calibrated per sensor and require an rigorous
// test environment. See README.md for more information.
int16_t COMPASS_MULTIPLIERS[360] = {
-213, -215, -213, -213, -213, -211, -208, -208, -204, -208, -206, -204, -204, -202, -200, -200, -200, -200, -202, -196, -196, -196, -196, -196, -196, -196, -192, -196, -192, -192, -192, -192, -192, -190, -189, -189, -189, -189, -189, -189, -189, -189, -189, -189, -187, -188, -185, -189, -185, -185, -185, -185, -185, -185, -185, -185, -185, -185, -185, -185, -185, -185, -185, -185, -185, -185, -185, -185, -185, -185, -185, -189, -185, -185, -185, -185, -185, -185, -185, -185, -189, -189, -187, -189, -185, -189, -189, -189, -189, -189, -192, -189, -190, -190, -190, -192, -192, -192, -192, -192, -196, -192, -196, -196, -196, -196, -196, -196, -196, -196, -200, -200, -200, -196, -200, -200, -200, -201, -204, -204, -200, -204, -204, -204, -204, -204, -204, -208, -208, -208, -208, -213, -213, -208, -208, -208, -208, -213, -213
@SharpCoder
SharpCoder / IARR.md
Created April 28, 2021 15:29
IARR Atmospheric Correction Algorithm

Algorithm

There is surprisingly very little information about what the actual IARR algorithm is. IARR stands for Internal Average Relative Reflectance and the idea is that you extract the spectral information from the raw data by measuring the mean spectrum of the whole image. Every pixel vector is normalised by this global spectral mean to produce a 'relative reflectance' image. The psuedo-code for this algorithm is as follows:

for each band
   compute mean
for each pixel in a particular bad
   divide by the computed mean for this band
#!/usr/bin/env bash
{ # this ensures the entire script is downloaded #
nvm_has() {
type "$1" > /dev/null 2>&1
}
nvm_install_dir() {
command printf %s "${NVM_DIR:-"$HOME/.nvm"}"
This is how I wire up an ESP8266 and the power-on sequence I use to initialize the device.
It seems really hard to find such simple information, so here it is in this gist for all eternity.
------
VCC - 3.3v
GND - Gnd
RST - High
En - High
Rx - Tx
pub fn get_color(&mut self, time: u64) -> Color {
// Take the current time we are interested in (typically
// system uptime in milliseconds) and modulus it by
// the total time of our gradient so we end up with
// a point between 0 and the total_time.
let normalized_time = time % self.total_time;
// The internal representation for this builder pattern
// is a linked-list, so do some sanity checks.
if self.root.is_none() {
return self.color;
@SharpCoder
SharpCoder / interpolate.rs
Created March 14, 2022 16:29
Basic interpolation method written in rust
pub fn interpolate(start: u32, end: u32, elapsed: u64, duration: u64) -> u32 {
// Calculate step
let x0 = 0f32;
let y0 = min(start, end) as f32;
let x1 = duration as f32;
let y1 = max(end, start) as f32;
let x = min(elapsed, duration) as f32;
let delta = (x * ((y1 - y0)/(x1 - x0))) as u32;
if start > end {
return start - delta;
@SharpCoder
SharpCoder / evernote.css
Last active August 18, 2022 14:13
Evernote theme for Trilium Notes
@font-face {
font-family: 'Roboto-Regular';
font-style: normal;
font-weight: 400;
src: url('/custom/fonts/Roboto-Regular.woff2') format('woff2');
}
:root {
--main-bg: var(--white);
--main-text: #000;
@SharpCoder
SharpCoder / finder-splitter.scad
Created June 30, 2022 14:49
2-way telescope splitter
$fn=100;
mount_base_w = 32.4;
mount_top_w = 23.8;
mount_depth = 10.0;
splitter_stem = 7;
splitter_height = 30;
platform_length = 45;
platform_angle = 22.5;
@SharpCoder
SharpCoder / README.md
Last active December 17, 2022 01:27
Bit-Smooshing over Serial

Bit Smoosher

This algorithm will take a 10/12/14 bit word and distribute it among 2 8-bit words. But in a lossless, efficient way. Why might someone want this? Well, it lets you stream uniquely sized words over 8-bit serial. That's why I need it anyway. Here's an example:

Suppose you have an 8-bit serial port and you want to stream 12-bit audio at 8kHz. Well, serial is typically maxing out around 115200 bits/s. You can't just use 2 bytes per datapoint, because you'll generate too much content. In order to solve

@SharpCoder
SharpCoder / grate.scad
Created January 17, 2023 16:10
Grate for zenith space command controller
SPACING = 1.5;
W = 25;
H = 100;
module grate(W, H, SPACING) {
for (i = [0:W/SPACING/2]) {
translate([(SPACING * 2 * i) - ((W-SPACING)/2), 0, 0])
square([SPACING, H], center=true);
}
}