Category: Uncategorized

  • Introducing MoniServ: Your Lightweight, Vigilant Service Monitor

    In the world of system administration and development, keeping your services online and healthy is paramount. Manually checking if a web server is responding or a background process is still running is tedious and error-prone. That’s where MoniServ comes in—a simple, powerful, and highly convenient tool designed to take the worry out of service monitoring.

    MoniServ is a no-nonsense, Rust-written utility that excels at monitoring your services and performing simple, automated recoveries. Its brilliance lies in its blend of built-in functionality and limitless extensibility.

    MoniServ is available on: https://github.com/Afante/monitor-services

    Here’s why MoniServ is such a convenient tool for your toolkit:

    1. Effortless Setup and Configuration
    Getting started with MoniServ is refreshingly straightforward. There’s no complex installation procedure—just build the single executable file and copy it to where you need it. Configuration is equally painless, using simple, human-readable YAML files stored in a dedicated directory. This file-based approach makes it easy to version, back up, and manage your monitoring setups. The included sample configuration file is heavily commented, guiding you through every setting so you can have your first monitor running in minutes.

    2. Two Powerful Monitoring Modes in One
    MoniServ gives you flexibility without complexity:

    • Built-in Web Monitoring: For HTTP services, it’s ready to go. You can configure MoniServ to check a specific URL, using various HTTP methods (GET, POST, etc.), and it will intelligently verify the response by matching the status code or even the content of the reply using regular expressions. This provides deep, content-aware verification.
    • Custom Command Monitoring: For anything else, MoniServ’s power truly shines. By setting the kind to custom, you can run any script or command as your health check. This means you’re not limited to web services—you can monitor databases, local processes, disk space, or any other system state you can check with a script.

    3. Automated Recovery & Smart Alerting
    MoniServ isn’t just a passive observer; it’s an active defender.

    • Self-Healing: When a service fails, you can define a recovery_cmd. This allows MoniServ to automatically execute a script to restart the service, clear a cache, or perform any other remedial action—often resolving the issue before you even know it happened.
    • Email Notifications: You won’t be left in the dark. MoniServ can be configured to send detailed error reports via email, ensuring you’re promptly alerted to any persistent issues that require your attention.

    4. Simple Yet Robust & Extensible
    Written in Rust, MoniServ is fast, reliable, and memory-safe. It handles the essential details like connection and read timeouts to prevent it from hanging. And while it’s perfect out-of-the-box for most needs, its ability to execute any custom script means its potential use cases are virtually limitless. It grows with your needs.

    In essence, MoniServ is the ultimate “set and forget” tool. It handles the routine vigilance, automates first-response recoveries, and alerts you when intervention is needed—all from a single, easy-to-configure executable. Say goodbye to manual checks and hello to peace of mind with MoniServ.

  • Why Predicting the Next Day Price of a Stock Using the Stock’s Price History Is Impossible, with a DNN.

    It can always be a fascinating dream to predict the next day price of a stock by looking at the stock’s price curve. However, by thinking it through, I doubt the meaningfulness of do so, even with a very powerful technology, deep neural network.

    A stock’s price, as time goes, rises or falls, from minute to minute. To view it abstractly, one can think of it can a continuous curve. A prediction task usually shifts a time window from past time toward current time. In each shift of the window, the oldest value is removed, and a newest value is added. In this process, one problem happens, that is the subsequence of any window is very similar to the subsequence of the next window. And next day’s price can either rise or fall, seemingly randomly. So, the input dataset is like assigning different labels to the same input data. Hence, the best that any model can do it to make a random guess on whether the next day’s price will rise or fall.

    Some people have made some videos on predicting stock price using LSTM, or other models. As long as they use the stock price history to predict price of the same stock, it will not work, just because the inputs do not distinguish labels.

    However, does it mean that stock prices cannot be predicted? Asserting this is still too early. There can be some relationships among various stocks, so there is still some possibility that one stock’s price can be predicted by other stocks.

  • Rust練習問題:弟の算数検査

    問題文

    弟は100以内の足し算と引き算をやりました。チャックしてあげてください。核問題の形式はa+b=c或いはa-b=c、どれも100を超えない非負整数です。cは弟が算出した回答で、200以内の比数整数であるか、一個の「?」かです。「?」は回答不能を意味します。

    入力形式

    入力は100行以内とし、EOF記号で終了します。一行ごとに、一問があります。形式は前述規定に則し、いかなるスペースを含みません。入力されたすべての整数に左に不要な0をつけていません。

    出力形式

    一行のみを出力します。一個の非負整数のみが出て、つまり、弟が正解した問題の数。

    入力サンプル

    1+2=3
    3-1=5
    6+7=?
    99-0=99

    回答案

    use std::io;
    use core::iter::Peekable;
    use core::str::Chars;
    pub struct Expression {
        a: i32,
        b: i32,
        op: char,
        answer: i32,
        unanswered: bool
    }
    
    fn main() {
        let mut line: String = String::new();
        let mut correct_count: i32 = 0;
        while io::stdin().read_line(&mut line).unwrap() > 0 {
            let mut char_seq: Peekable<Chars<'_>> = line.trim().chars().peekable();
            let a: i32   = read_number(&mut char_seq).unwrap().unwrap();
            let op: char = char_seq.next().unwrap();
            let b: i32   = read_number(&mut char_seq).unwrap().unwrap();
            assert!(char_seq.next().unwrap()=='=');
            let got_answer = read_number(&mut char_seq).unwrap();
            let expression = Expression {
                a: a,
                op: op,
                b: b,
                answer: got_answer.unwrap_or_default(),
                unanswered: got_answer.is_none()
            };
            match check_expression(&expression) {
                Ok(r) => correct_count += if r {1} else {0},
                Err(e) => println!("Error: {}", e)
            }
            line.clear();
        }
        println!("{}", correct_count);
    }
    
    fn read_number(text_iter: &mut Peekable<Chars<'_>>) -> Result<Option<i32>, &'static str> {
        let mut number_str: String = String::new();
        while let Some(&c) = text_iter.peek() {
            match c {
                c if c >= '0' && c <= '9' => {
                    number_str.push(c);
                    text_iter.next();
                },
                '?' => {
                    number_str.push(c);
                    text_iter.next();
                    break;
                },
                _ => break
            }
        }
        if number_str == "?" {
            Ok(None)
        } else if number_str.len() > 0 {
            Ok(Some(number_str.parse().unwrap()))
        }
        else {
            Err("Reading a number while not at a number.")
        }
    }
    
    fn check_expression(expr: &Expression) -> Result<bool, &'static str> {
        let expected: i32;
        match expr.op {
            '+' => expected = expr.a + expr.b,
            '-' => expected = expr.a - expr.b,
            '*' => expected = expr.a * expr.b,
            '/' => expected = expr.a / expr.b,
            _ => return Err("Invalid operator.")
        }
        Ok(!expr.unanswered && expr.answer == expected)
    }
  • Start Anew

    It has been a year perhaps? I lost my sites. Now it’s about time to start anew.

    With this simple post, I just try to get familiar with the newest WordPress functions at the time of being.