Skip to content

Instantly share code, notes, and snippets.

Avatar

Dan Siwiec danielsiwiec

View GitHub Profile
@danielsiwiec
danielsiwiec / temperature.py
Created Dec 22, 2020
Steinhart Thermistor Temperature
View temperature.py
import math
import machine
def _steinhart_temperature_C(Rt, Ro=10000.0, To=25.0, beta=3950.0):
steinhart = math.log(Rt / Ro) / beta
steinhart += 1.0 / (To + 273.15)
steinhart = (1.0 / steinhart) - 273.15
return steinhart
def _get_thermistor_resistance(self, Rnom = 10000, adc_resolution=1023):
@danielsiwiec
danielsiwiec / mqtt.py
Created Dec 22, 2020
MQTT connection
View mqtt.py
from umqtt.simple import MQTTClient
import json
client_id = 'esp8266'
mqtt_topic = 'tempReading/bedroom'
mqtt_port = 8883
mqtt_host = 'a2XXXXXXXX.iot.us-west-2.amazonaws.com'
private_key = open("/private_key.der").read()
certificate = open("/cert.der").read()
@danielsiwiec
danielsiwiec / sleep.py
Created Dec 22, 2020
ESP8266 Deep Sleep
View sleep.py
rtc = machine.RTC()
rtc.irq(trigger=rtc.ALARM0, wake=machine.DEEPSLEEP)
rtc.alarm(rtc.ALARM0, seconds * 1000)
print('Entering deep sleep for %s seconds' % seconds)
machine.deepsleep()
@danielsiwiec
danielsiwiec / main.py
Last active Dec 23, 2020
esp8266-thermostat
View main.py
props = load_props()
connect_to_wifi(props['wifi_sid'], props['wifi_pass'])
mqtt = MQTT(props['client_id'], props['iot_endpoint'], props['iot_topic'])
thermistor = Thermistor()
while True:
temp = thermistor.get_temp()
mqtt.send({'temp': temp})
deep_sleep_seconds(props['sleep_seconds'])
View .zshrc
ZSH_THEME="clean"
plugins=(git)
alias venv="python3 -m venv .venv && source .venv/bin/activate"
source ~/.oh-my-zsh/oh-my-zsh.sh
@danielsiwiec
danielsiwiec / OrderProcessingTest.java
Created Oct 25, 2020
End to End Test (asynchronous)
View OrderProcessingTest.java
public class OrderProcessingTest {
@Autowired
RestTemplate restTemplate;
@Test
public void shouldProcessValidOrder() {
var validOrder = Order.withItems(Item.id("2fa2ac")).withCustomerId("123");
// submit Order
@danielsiwiec
danielsiwiec / OrderProcessingTest.java
Created Oct 25, 2020
End to End Test (synchronous)
View OrderProcessingTest.java
public class OrderProcessingTest {
@Autowired
RestTemplate restTemplate;
@Test
public void shouldProcessValidOrder() {
var validOrder = Order.withItems(Item.id("2fa2ac")).withCustomerId("123");
// submit Order
@danielsiwiec
danielsiwiec / PaymentServiceTest.java
Created Oct 25, 2020
Service Test (event-driven)
View PaymentServiceTest.java
@SpringBootTest
@EmbeddedKafka(topics = {"orders", "payments"})
public class PaymentServiceTest {
@Autowired
private Producer<Order> orderProducer;
@Autowired
private Consumer<Payment> paymentConsumer;
@danielsiwiec
danielsiwiec / PaymentServiceTest.java
Created Oct 25, 2020
Service Test (point-to-point)
View PaymentServiceTest.java
@SpringBootTest
public class PaymentServiceTest {
@Autowired
private RestTemplate restTemplate;
@Test
public void shouldProcessPaymentForValidOrder() {
var validOrder = Order
.withCustomerId(123)
View TaxCalculatorTest.java
public class TaxCalculatorTest {
@Test
public void shouldCalculateCaliforniaTaxOnOrderWithSingleItem() {
var singleItemOrder = Order.withItems(Item.withCost(50)).withCustomerLocation('CA');
var tax = TaxCalculator.calculate(singleItemOrder);
assertThat(tax).isEqualTo(3.625);
}
@Test