Moving to nsclass.github.io

I am moving to https://nsclass.github.io

Leave a comment

WASM – Creating an WASM with Rust and React

The following github project shows how to create an WASM application with Rust and React framework

https://github.com/nsclass/react-wasm-game-of-life

Posted in Programming, Rust | Leave a comment

FP – Functional Programming with JavaScript

https://mostly-adequate.gitbooks.io/mostly-adequate-guide/

Posted in Functional Programming, Programming | Leave a comment

Rust – how async/await works

https://os.phil-opp.com/async-await/

Posted in Programming, Rust | Leave a comment

Sublime – matching multiple lines with regex

Start with (?s)

(?s)\[sometag\](.*?)\[\/sometag\]
Leave a comment

Java – Dropwizard http request accessing log customizing example

Dropwizard can allow to access the attributes in a request as shown in below example.
Full layout logback format details can be found from http://logback.qos.ch/manual/layouts.html

server:
  rootPath: /test/services/rest
  requestLog:
    appenders:
    - type: file
      currentLogFilename: ./logs/requests.log
      archivedLogFilenamePattern: ./logs/requests-%d.log
      archivedFileCount: 5
      timeZone: UTC
      logFormat: "%h %l %u [%t{dd/MMM/yyyy:HH:mm:ss Z,UTC}] %reqAttribute{attributeName} \"%r\" %s %b \"%i{Referer}\" \"%i{User-Agent}\" %D"

Posted in Java, Programming | Leave a comment

Linux – Top 10 Performance commands

1. uptime
2. dmesg | tail
3. vmstat 1
4. mpstat -P ALL 1
5. pipstat 1
6. iostat -xz 1
7. free -m
8. sar -n DEV 1
9. sar -n TCP, ETCP 1
10. top

Posted in Linux, Programming | Leave a comment

eBPF – Learn eBPF Tracing for Linux application performance

extended Berkeley Packet Filter
Linux application performance tracing tool

http://www.brendangregg.com/blog/2019-01-01/learn-ebpf-tracing.html

Posted in ebpf, Programming | Leave a comment

Kubernetes – Container networks


https://github.com/kristenjacobs/container-networking

Posted in Kubernetes | Leave a comment

SpringBoot WebFlux – Reading a request body with Spring WebFlux for Controller

SpringBoot WebFlux 2.2.x requires to load the request body by using an input stream.
Below example will show how it can convert the json data into the expected class after loading json data with an input stream.

Full source code can be found from https://github.com/nsclass/ns-svg-converter/blob/master/ns-main-service/src/main/java/com/acrocontext/reactive/rest/SvgConverterController.java

Github: https://github.com/nsclass/ns-svg-converter

    private <T> T toRequestBody(InputStream inputStream, Class<T> classValue) {
        try {
            return objectMapper.readValue(inputStream, classValue);
        } catch(Exception e){
            throw new RuntimeException(e);
        }
    }

    public static class InputStreamCollector {
        private InputStream inputStream;

        public void collectInputStream(InputStream inputStream) {
            if (this.inputStream == null) {
                this.inputStream = inputStream;
            }

            this.inputStream = new SequenceInputStream(this.inputStream, inputStream);
        }

        public InputStream getInputStream() {
            return this.inputStream;
        }
    }

REST Controller

    @PutMapping(path = "/conversion",
            consumes = MediaType.APPLICATION_JSON_VALUE,
            produces = MediaType.APPLICATION_JSON_VALUE)
    public Mono<SvgConvertRespondView> convertImage(ServerWebExchange exchange) {
        return exchange.getRequest().getBody()
                .collect(InputStreamCollector::new, (inputStreamCollector, dataBuffer)->
                        inputStreamCollector.collectInputStream(dataBuffer.asInputStream()))
                .map(InputStreamCollector::getInputStream)
                .map(inputStream -> toRequestBody(inputStream, SvgConvertRequestView.class))
                .map(this::convertRespondView);
    }
Posted in Programming, Spring | Leave a comment