Skip to content

Instantly share code, notes, and snippets.

/**
* tske a {@link FilePart}, transfer it to disk using {@link AsynchronousFileChannel}s and return a {@link Mono} representing the result
*
* @param filePart - the request part containing the file to be saved
* @return a {@link Mono} representing the result of the operation
*/
private Mono<String> saveFile(FilePart filePart) {
LOGGER.info("handling file upload {}", filePart.filename());
// if a file with the same name already exists in a repository, delete and recreate it
@entzik
entzik / threader.py
Last active May 26, 2018 19:58
Raspberry PI AM3203 to Lambda
#!/usr/bin/python
import sys
import Adafruit_DHT
import json
import urllib2
import time
humidity, temperature = Adafruit_DHT.read_retry(Adafruit_DHT.AM2302, 2)
buildscript {
ext {
springBootVersion = '1.5.11.RELEASE'
wrapperVersion = '1.0.9.RELEASE'
shadowVersion = '2.0.1'
}
repositories {
jcenter()
mavenLocal()
mavenCentral()
@entzik
entzik / Application.java
Created May 27, 2018 19:56
Spring Cloud Function Entry Point
@SpringBootApplication
public class Application {
@Autowired
ClimateReadingRepository climateReadingRepository;
@Bean(name = "saveReadings")
public Function<ClimateReading, ClimateReading> saveReadings() {
return (reading) -> climateReadingRepository.save(reading);
}
@entzik
entzik / application.properties
Created May 27, 2018 20:03
specifying a function name
...
function.name=saveReadings
...
public interface ClimateReadingRepository extends CrudRepository<ClimateReading, String> {
}
@entzik
entzik / Handler.java
Created May 30, 2018 21:32
Spring Cloud Function AWS Lambda Request Handler
public class Handler extends SpringBootApiGatewayRequestHandler {
}
@entzik
entzik / application.properties
Created May 30, 2018 21:48
liquibase properties
liquibase.change-log=classpath:/db/liquibase-changelog.xml
liquibase.enabled=true
@entzik
entzik / homeautomation-v1.xml
Created May 30, 2018 21:53
liqubase change log
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<changeSet id="2" author="ek">
<createTable tableName="climate_reading">
@entzik
entzik / create-database.sh
Created May 31, 2018 21:33
A shell script to create a postgres database on AWS RDS
#!/bin/sh
aws rds create-db-instance \
--db-instance-identifier HomeAutomationDB \
--db-instance-class db.t2.micro \
--region eu-west-3 \
--engine postgres \
--allocated-storage 5 \
--no-publicly-accessible \
--db-name homeautomation \