Skip to content

Instantly share code, notes, and snippets.

View kasvith's full-sized avatar
🏠
Working from home

Kasun Vithanage kasvith

🏠
Working from home
View GitHub Profile
@kasvith
kasvith / api.yaml
Created July 16, 2019 15:26
API Parameters description
id: # ID of API
providerName: admin # Provider name for API [required]
apiName: SwaggerPetstore # Name of the API without Spaces(see publisher UI for more) [required]
version: 1.0.0 # Version of API(required)
description: 'This is a sample server Petstore server.' # Description of API
type: HTTP # Type of API {HTTP|WS} [required]
context: /v2 # Context of API with a leading slash, CLI tool will append version on import(if you want to put version like /1.0.0/v2 just set context to /{version}/v2 please refer UI for this) [required]
tags: # tags for API as a list
- pets
- petstore
package main
import (
"fmt"
"math/rand"
"sync"
"time"
)
type DataEvent struct {
package main
import (
"fmt"
"math/rand"
"sync"
"time"
)
type DataEvent struct {
@kasvith
kasvith / eventbus.go
Created March 11, 2019 08:19
A simple eventbus written with go
package main
import (
"fmt"
"math/rand"
"sync"
"time"
)
type Data struct {
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.stage.Stage;
import java.text.SimpleDateFormat;
@Override
public void stop() throws Exception {
super.stop();
scheduledExecutorService.shutdownNow();
}
// this is used to display time in HH:mm:ss format
final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm:ss");
// setup a scheduled executor to periodically put data into the chart
ScheduledExecutorService scheduledExecutorService;
scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
// put dummy data onto graph per second
scheduledExecutorService.scheduleAtFixedRate(() -> {
// get a random integer between 0-10
// setup scene
Scene scene = new Scene(lineChart, 800, 600);
primaryStage.setScene(scene);
//defining a series to display data
XYChart.Series<String, Number> series = new XYChart.Series<>();
series.setName("Data Series");
// add series to chart
lineChart.getData().add(series);
//defining the axes
final CategoryAxis xAxis = new CategoryAxis(); // we are gonna plot against time
final NumberAxis yAxis = new NumberAxis();
xAxis.setLabel("Time/s");
xAxis.setAnimated(false); // axis animations are removed
yAxis.setLabel("Value");
yAxis.setAnimated(false); // axis animations are removed
//creating the line chart with two axis created above
final LineChart<String, Number> lineChart = new LineChart<>(xAxis, yAxis);