Skip to content

Instantly share code, notes, and snippets.

View danielsiwiec's full-sized avatar

Dan Siwiec danielsiwiec

View GitHub Profile
@danielsiwiec
danielsiwiec / declarative.groovy
Created March 24, 2022 21:46
Declarative Pipeline
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building...'
}
}
stage('Test') {
steps {
@danielsiwiec
danielsiwiec / runner.groovy
Created March 23, 2022 18:42
Pipeline runner
def execute(step, services) {
stage(step.name) {
if (step.shared) {
runSharedStep(step.command)
} else {
parallel services.collectEntries {service -> [service, {runServiceStep(service, step.command)}]}
}
}
}
@danielsiwiec
danielsiwiec / pipeline.groovy
Created March 22, 2022 16:47
Pipeline definition
[
[
name : 'Build',
command : 'make build',
shared : false,
],
[
name : 'Service Test',
command : 'make service-test',
shared : false,
@danielsiwiec
danielsiwiec / shouldRunAll.groovy
Created March 22, 2022 16:33
Check if should run all
def runAllLocations = ['common/', 'Jenkinsfile']
def shouldRunAll(changedFiles) {
def hasChangesInCommon = changedFiles.any { file -> runAllLocations.any { file.matches("$it.*") } }
def hasChangesInRoot = changedFiles.any { !it.contains('/') }
hasChangesInCommon || hasChangesInRoot || changedFiles.isEmpty()
}
@danielsiwiec
danielsiwiec / whatServices.groovy
Last active March 22, 2022 01:45
Identifying services to run
def changedServices(changedFiles) {
listServices().findAll { service -> changedFiles.any { it.contains("services/$service") } }
}
def listServices() {
sh(script: "ls -1 $WORKSPACE/services/", returnStdout: true)
.split()
.findAll {!it.endsWith('@tmp')}
}
@danielsiwiec
danielsiwiec / changes.groovy
Last active March 22, 2022 01:30
Files changed since last successful build
def changedFilesSinceLastPass() {
def files = []
def lastSuccessfulBuildNumber = currentBuild.previousSuccessfulBuild?.number
if (lastSuccessfulBuildNumber == null) {
return []
}
def build = currentBuild
while (build.number > lastSuccessfulBuildNumber) {
@danielsiwiec
danielsiwiec / main.py
Last active December 23, 2020 02:09
esp8266-thermostat
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'])
@danielsiwiec
danielsiwiec / temperature.py
Created December 22, 2020 20:28
Steinhart Thermistor Temperature
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 December 22, 2020 20:02
MQTT connection
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 December 22, 2020 05:10
ESP8266 Deep Sleep
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()