Skip to content

Instantly share code, notes, and snippets.

@nevercast
nevercast / main.py
Created October 11, 2020 23:46
Simple DHT11 read and publish to AIO
import machine, network, time, dht, mqtt
# mqtt: https://github.com/micropython/micropython-lib/blob/master/umqtt.simple/umqtt/simple.py
## SECRETS
WIFI_NAME='<WIFI SSID>'
WIFI_PASS='<WIFI PASSWORD>'
MQTT_HOST='io.adafruit.com'
MQTT_PORT=1883
MQTT_USER='<ADAFRUIT USERNAME>'
MQTT_PASS='<ADAFRUIT IO KEY>'
@nevercast
nevercast / necto-viz.py
Created December 28, 2021 05:26
Neural Network visualisations
# https://stackoverflow.com/questions/52468956/how-do-i-visualize-a-net-in-pytorch
import os
import numpy as np
import torch
from torch.distributions import Categorical
import torch.nn.functional as F
from rlgym.utils.gamestates import GameState, PlayerData, PhysicsObject
from training.obs import NectoObsBuilder
@nevercast
nevercast / pixels.py
Last active November 20, 2022 17:34
Simple MicroPython ESP32 RMT NeoPixel / WS2812B driver.
# Copyright public licence and also I don't care.
# 2020 Josh "NeverCast" Lloyd.
from micropython import const
from esp32 import RMT
# The peripheral clock is 80MHz or 12.5 nanoseconds per clock.
# The smallest precision of timing requried for neopixels is
# 0.35us, but I've decided to go with 0.05 microseconds or
# 50 nanoseconds. 50 nanoseconds = 12.5 * 4 clocks.
# By dividing the 80MHz clock by 4 we get a clock every 50 nanoseconds.
@nevercast
nevercast / main.cpp
Created September 10, 2020 00:28
Several tests to run on an ESP32 for crystal, PSRAM and deepsleep stuff.
// If you're building this code from Arduino IDE, you wont need to import Arduino.h
#include "Arduino.h"
#include "soc/rtc.h"
#define uS_TO_S_FACTOR 1000000 /* Conversion factor for micro seconds to seconds */
#define TIME_TO_SLEEP ((60 * 60) * 1) /* Time ESP32 will go to sleep (in seconds) */
// Multiple ways to run this code to produce different reports
#define MODE_SLEEP 1
#define MODE_DIAG 2
@nevercast
nevercast / push.js
Created January 23, 2024 20:39
Push code to Screeps
const fs = require('fs');
const path = require('path');
const http = require('http');
const https = require('https');
const util = require('util');
const process = require('process');
const os = require('os');
const TEXT_EXTENSIONS = ['.js', '.json'];