Skip to content

Instantly share code, notes, and snippets.

View codemwnci's full-sized avatar

Wayne Ellis codemwnci

View GitHub Profile
@codemwnci
codemwnci / Dockerfile
Last active December 27, 2018 20:27
Dockerfile for Java/Kotlin Maven Build
# Part 1: Build the app using Maven
FROM maven:3.6.0-jdk-8-alpine
## download dependencies
ADD pom.xml /
RUN mvn verify clean
## build after dependencies are down so it wont redownload unless the POM changes
ADD . /
RUN mvn package
@codemwnci
codemwnci / ChatApplication.kt
Created January 27, 2018 17:08
The Kotlin serverside code the WebSocket implementation
package codemwnci.bootsocket
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.context.annotation.Configuration
import org.springframework.web.socket.*
import org.springframework.web.socket.config.annotation.*
import org.springframework.web.socket.handler.TextWebSocketHandler
@codemwnci
codemwnci / index.html
Last active January 27, 2018 17:08
The HTML / JS for the WebSocket Client
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Chat - Websocket Kotlin</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
buildscript {
ext {
kotlinVersion = '1.2.10'
springBootVersion = '2.0.0.M7'
}
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
@codemwnci
codemwnci / TodoResources.kt
Created September 17, 2017 09:47
Todo REST endpoints for Todo Kotlin App
package codemwnci.kotlinspringboot
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.web.bind.annotation.*
import javax.persistence.*
import java.time.Instant
@RestController @RequestMapping(value = "/todo")
class TodoResources(val todoRepo: TodoReposiory) {
package codemwnci
import spark.Spark.*
import kotliquery.*
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import java.time.LocalDateTime
fun main(args: Array<String>) {
setupDB()
}
@codemwnci
codemwnci / index.html
Created August 25, 2017 22:06
update todo vuejs / toggleCheck method
toggleCheck: function(todo) {
todo.done = !todo.done;
this.update(todo);
},
update: function(todo) {
axios.put("http://localhost:9000/todo/"+todo.id, {"text": todo.text, "done": todo.done}).then(response => {
for(var i = this.todos.length; i--;){
if (this.todos[i].id === todo.id) {
this.todos[i].done = response.data.done;
@codemwnci
codemwnci / index.html
Created August 25, 2017 22:03
update todo vuejs / list item code
<li v-for="todo in todos">
<input type="checkbox" :checked="todo.done" @click="toggleCheck(todo)">
{{todo.text}}
<a href="#" v-if="todo.done" @click="deleteTodo(todo.id)">(delete)</a>
</li>
@codemwnci
codemwnci / index.html
Created August 25, 2017 21:57
delete todo function
deleteTodo: function(id) {
axios.delete("http://localhost:9000/todo/"+id).then(response => {
if (response.data = "ok") {
for(var i = this.todos.length; i--;){
if (this.todos[i].id === id) this.todos.splice(i, 1);
}
}
});
},
@codemwnci
codemwnci / index.html
Created August 25, 2017 21:46
Load all todos on startup
mounted() {
axios.get('http://localhost:9000/todo/').then(response => {
this.todos = response.data;
});
}