Skip to content

Instantly share code, notes, and snippets.

View aeshirey's full-sized avatar
🏔️

Adam Shirey aeshirey

🏔️
View GitHub Profile
@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`
@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 / 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 / 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 / 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+"
}
#include <DHTesp.h>
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"
#include <ESP8266WiFi.h>
#define LOOP_MS 60000
#define DhtPin 14
DHTesp dht;
# 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
- id: '1234'
alias: ventilate_on
trigger:
- payload: 'on'
platform: mqtt
topic: ventilate
condition: []
action:
- data:
entity_id: switch.wind_tunnel
#!/usr/bin/env python
import paho.mqtt.client as mqtt
import json
import requests
BROKER = '192.168.0.1'
TOPIC = "weather/renton"
URL = "http://api.openweathermap.org/data/2.5/weather?id=5808189&APPID=<your api key goes here>"
API_DELAY_SEC = 60 * 10 # every 10 minutes
// Code accompanying my blog post on my kegerator setup, found here:
// http://www.dingostick.com/2018/12/kegerator-v10.html
// 1. https://www.pjrc.com/teensy/td_libs_OneWire.html
#include <OneWire.h>
// 2. https://github.com/milesburton/Arduino-Temperature-Control-Library
#include <DallasTemperature.h>
#define LOGGING