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 / test_hello.py
Last active July 16, 2018 11:07
Hello World Test for python
import unittest
import hello
# Initialize a class to use with unittest framework
class HelloTest(unittest.TestCase):
# Test the hello world function from hello.py
def testHelloWorld(self):
# check whether the 'hello world' is returned by the method
self.assertEqual(hello.helloWorld(), 'hello world')
@kasvith
kasvith / .gitlab-ci.yml
Created July 16, 2018 12:59
Gitlab CI intro
test:
image: python:3.7
script:
- python -m unittest
@kasvith
kasvith / .gitlab-ci.yml
Created July 16, 2018 15:00
Production start
test:
image: python:3.7
script:
- python -m unittest
production:
script:
- tar -czvf release.tar.gz *.py
@kasvith
kasvith / .gitlab-ci.yml
Created July 16, 2018 15:13
GitLab CI final
stages:
- test
- production
test:
stage: test
image: python:3.7
script:
- python -m unittest
@kasvith
kasvith / stage1.java
Created February 18, 2019 06:26
Bootstrapping JavaFX app
public class App extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("JavaFX Realtime Chart Demo");
// show the stage
//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);
//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);
// setup scene
Scene scene = new Scene(lineChart, 800, 600);
primaryStage.setScene(scene);
// 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
@Override
public void stop() throws Exception {
super.stop();
scheduledExecutorService.shutdownNow();
}