Daily Shaarli

All links of one day in a single page.

March 17, 2020

abstract syntax tree - Evaluating a math expression with variables. (java 8) - Stack Overflow
thumbnail
Manual:CAPsMAN - MikroTik Wiki
How to use ssh-keygen to generate a new SSH key

Ssh-keygen is a tool for creating new authentication key pairs for SSH. This is a tutorial on its use, and covers several special use cases.

Docker Tips: Running a Container With a Non Root User
thumbnail

One best practice when running a container is to launch the process with a non root user. This is usually done through the usage of the USER instruction in the Dockerfile. But, if this instruction…

Introduction to REST | RESTfu­l Java­ with ­JAX-­RS 2.0­
DataHubSystem/MetalinkBuilder.java at master · SentinelDataHub/DataHubSystem · GitHub
thumbnail
How to create a Maven archetype in NetBeans - Tarin Gamberini
Data Modeling – ThatJeffSmith
java - How to evaluate a math expression given in string form? - Stack Overflow
thumbnail

public static double eval(final String str) {
return new Object() {
int pos = -1, ch;

    void nextChar() {
        ch = (++pos < str.length()) ? str.charAt(pos) : -1;
    }

    boolean eat(int charToEat) {
        while (ch == ' ') nextChar();
        if (ch == charToEat) {
            nextChar();
            return true;
        }
        return false;
    }

    double parse() {
        nextChar();
        double x = parseExpression();
        if (pos < str.length()) throw new RuntimeException("Unexpected: " + (char)ch);
        return x;
    }

    // Grammar:
    // expression = term | expression `+` term | expression `-` term
    // term = factor | term `*` factor | term `/` factor
    // factor = `+` factor | `-` factor | `(` expression `)` | number
    //        | functionName `(` expression `)` | functionName factor
    //        | factor `^` factor

    double parseExpression() {
        double x = parseTerm();
        for (;;) {
            if      (eat('+')) x += parseTerm(); // addition
            else if (eat('-')) x -= parseTerm(); // subtraction
            else return x;
        }
    }

    double parseTerm() {
        double x = parseFactor();
        for (;;) {
            if      (eat('*')) x *= parseFactor(); // multiplication
            else if (eat('/')) x /= parseFactor(); // division
            else return x;
        }
    }

    double parseFactor() {
        if (eat('+')) return +parseFactor(); // unary plus
        if (eat('-')) return -parseFactor(); // unary minus

        double x;
        int startPos = this.pos;
        if (eat('(')) { // parentheses
            x = parseExpression();
            if (!eat(')')) throw new RuntimeException("Missing ')'");
        } else if ((ch >= '0' && ch <= '9') || ch == '.') { // numbers
            while ((ch >= '0' && ch <= '9') || ch == '.') nextChar();
            x = Double.parseDouble(str.substring(startPos, this.pos));
        } else if (ch >= 'a' && ch <= 'z') { // functions
            while (ch >= 'a' && ch <= 'z') nextChar();
            String func = str.substring(startPos, this.pos);
            if (eat('(')) {
                x = parseExpression();
                if (!eat(')')) throw new RuntimeException("Missing ')' after argument to " + func);
            } else {
                x = parseFactor();
            }
            if (func.equals("sqrt")) x = Math.sqrt(x);
            else if (func.equals("sin")) x = Math.sin(Math.toRadians(x));
            else if (func.equals("cos")) x = Math.cos(Math.toRadians(x));
            else if (func.equals("tan")) x = Math.tan(Math.toRadians(x));
            else throw new RuntimeException("Unknown function: " + func);
        } else {
            throw new RuntimeException("Unexpected: " + (char)ch);
        }

        if (eat('^')) x = Math.pow(x, parseFactor()); // exponentiation

        return x;
    }
}.parse();

}

Manual:IP/Cloud - MikroTik Wiki
How to Install Docker on Debian 10 (Buster) – TecAdmin

Docker is a container-based application framework, which wraps a specific application with all its dependencies in a container. Docker containers can easily to ship to the remote location on start there without making entire application setup. This tutorial will help you to install Docker on Debian 10 Buster Linux distribution. Step 1 – Prerequisites First …

Доступ к устройству по протоколу HTTPS через службу KeenDNS и доменное имя 4-го уровня – Keenetic

Указанная в статье информация актуальна для устройств с KeeneticOS до версии 2.15. Начиная с версии 2.15.С0 реализовано автоматическое...

How to Enable Docker Remote REST API on Docker Host - Little Big Extra

Enable Docker Remote REST API on Docker Host. Connect to a remote docker host to manage the container remotely over a browser easily

Build a RESTful Web service using Jersey and Apache Tomcat – IBM Developer
thumbnail
TheNEXUS | A Community Project
thumbnail