Skip to content

Instantly share code, notes, and snippets.

View aeshirey's full-sized avatar
🏔️

Adam Shirey aeshirey

🏔️
View GitHub Profile
# maximum allowable delta (°F) before we start the fans
TEMP_DELTA = 5.0
def check_temp():
global VENTILATION_STATE
c = db.cursor()
# get the last ten minutes of data only
c.execute("SELECT temp, room FROM temps WHERE (julianday('now') - julianday(timestamp))*86400 < 600 ORDER BY timestamp")
inside_temps, outside = [], 0.0
@aeshirey
aeshirey / Read ADL file.py
Created March 9, 2020 21:26
Code to read an adl:// file in Python
import fsspec
filename = 'adl://path/to/file.csv'
adl_auth = {
'tenant_id': "<tenant_id>",
'client_id': "<client_id>",
'client_secret': "PGNsaWVudF9zZWNyZXQ+"
}
@aeshirey
aeshirey / main.rs
Last active December 3, 2020 03:14
Parallelized quantile estimation with Greenwald-Khanna
// `probably` crate @ https://github.com/aeshirey/probably/
// Use it by specifying probably = "0.2.0" in your Cargo.toml
use probably::quantile::greenwald_khanna;
use std::fs::File;
use std::io::{BufRead, BufReader};
fn main() {
const EPSILON: f64 = 0.001;
const QUANTILE: f64 = 0.5; // median
@aeshirey
aeshirey / compass.rs
Last active December 19, 2020 19:46
Azimuth/Distance calculator
// Algorithm from http://cosinekitty.com/compass.html
// Code ported to Rust by @aeshirey
use core::f64::consts::PI;
#[derive(Debug, Copy, Clone)]
pub struct Location {
latitude: f64,
longitude: f64,
elevation_meters: f64,
}
@aeshirey
aeshirey / scout-camp-gen.py
Last active July 8, 2022 05:56
Python to generate SMT-LIB for scheduling scouts in tents
#!/usr/bin/python3
# Blog post here:
# https://aeshirey.github.io/code/2022/07/08/smt-for-scheduling-scouts-in-tents.html
# Run this as:
# ./scout-camp-gen.py > scout-camp.smt2
# Then check satisfiability with:
# z3 scout-camp.smt2 > solved.txt
# This will output something like:
# ...
@aeshirey
aeshirey / main.rs
Last active February 21, 2023 19:32
Rust binary to remove `nulls` from JavaScript input
//! To use this gist:
//!
//! ```shell
//! cargo new remove-nulls
//! cd remove-nulls
//! cargo add serde serde_json
//! ```
//!
//! Then paste the contents of this file into src/main.rs.
//! Run `cargo build --release`