wake on lan from internet WOL

Open the Router web configuration interface, and switch to the “Advanced” tab.

Go to Network » DHCP server » Address reservation, assign a static IP to machine you want.

Go to Security » IP & Mac Binding. Find your machine in the “ARP list”, and click the link icon on the far right. It should then show up in the “Binding list” below, and be listed as “Bound” in the ARP list.

Go to NAT Forwarding » Virtual Servers and create a new service called WakeOnLan:

Set external port to anything (say 9999)
Set internal port to 9
Set internal IP to the static address of your machine.
Create a service for SSH, whatever other services you need. (Changing the external SSH port to something other than 22 reduces the number of brute force attacks on your router by a lot.)

Go to Network » Dynamic DNS and enable one of the many services.

Now you can wake your computer remotely by:

wakeonlan -p 9999 -i router.tplinkdns.com <Mac Address>
and then connect to it by

ssh -p XXXX router.tplinkdns.com
For multiple computers, just assign different external ports for each computer.

Flask display pandas df

if i have datafram to display on how will my template looks like?

This is an example of how you can render a Pandas DataFrame in a Flask template:

<!doctype html>
<html>
  <head>
    <title>Stocks Information</title>
  </head>
  <body>
    <h1>Stocks Information</h1>
    <table>
      <thead>
        <tr>
          <th>Symbol</th>
          <th>Indicator 1</th>
          <th>Indicator 2</th>
          <th>Indicator 3</th>
        </tr>
      </thead>
      <tbody>
        {% for index, row in df.iterrows() %}
          <tr>
            <td>{{ row['Symbol'] }}</td>
            <td>{{ row['Indicator 1'] }}</td>
            <td>{{ row['Indicator 2'] }}</td>
            <td>{{ row['Indicator 3'] }}</td>
          </tr>
        {% endfor %}
      </tbody>
    </table>
  </body>
</html>
flask python photo
Photo by See-ming Lee (SML)

This template includes a table that displays the data from a Pandas DataFrame. The DataFrame is passed to the template as a variable named df. The template uses a for loop to iterate over the rows of the DataFrame and generate a row in the table for each row of the DataFrame.

To render the template in your Flask application, you can use the render_template() function and pass the DataFrame as a keyword argument. For example:

from flask import Flask, render_template
import pandas as pd

app = Flask(__name__)

@app.route('/')
def home():
    df = pd.read_csv('data.csv')
    return render_template('stocks.html', df=df)

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000)

This Flask application reads a CSV file containing the stocks information and loads it into a Pandas DataFrame named df. The df variable is then passed to the stocks.html template using the render_template() function.

I hope this helps!

python ML Python divergencce finder ML machine learning

machine learning photomachine learning photo

import pandas as pd
import numpy as np
import talib
from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import train_test_split

def extract_features(df):
    # Calculate RSI
    df['rsi'] = talib.RSI(df['close'].values, timeperiod=14)

    # Calculate Bollinger Bands
    upperband, middleband, lowerband = talib.BBANDS(df['close'].values, timeperiod=14)
    df['bollinger_upper'] = upperband
    df['bollinger_middle'] = middleband
    df['bollinger_lower'] = lowerband

    # Calculate Moving Average
    df['ma50'] = talib.SMA(df['close'].values, timeperiod=50)

    return df

def label_data(df):
    # Mark the rows where the RSI value is above 70 as "divergence" (0)
    # Mark the rows where the RSI value is below 30 as "convergence" (1)
    df['label'] = np.where(df['rsi'] > 70, 0, 1)
    df['label'] = np.where(df['rsi'] < 30, 1, df['label'])

    return df

def load_data(filename):
    df = pd.read_csv(filename)
    df = extract_features(df)
    df = label_data(df)

    return df

def train_model(df):
    # Split data into training and testing sets
    X = df.drop(['label'], axis=1)
    y = df['label']
    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42)

    # Train a decision tree model
    clf = DecisionTreeClassifier(random_state=0)
    clf.fit(X_train, y_train)

    # Test the model on the testing data
    accuracy = clf.score(X_test, y_test)
    print("Accuracy:", accuracy)

    return clf

def predict(clf, df):
    # Use the trained model to predict the labels for the test data
    X = df.drop(['label'], axis=1)
    y_pred = clf.predict(X)

    return y_pred

# Load the data from a CSV file
df = load_data('stock_data.csv')

# Train the model
clf = train_model(df)

# Use the trained model to predict the labels for new data
y_pred = predict(clf, df)







import pandas as pd
import numpy as np
from sklearn.tree import DecisionTreeClassifier
from sklearn.metrics import accuracy_score
import joblib

def load_data(file_name):
    df = pd.read_csv(file_name)
    return df

def preprocess_data(df):
    df = df.dropna()
    df['rsi'] = calculate_rsi(df)
    df['bolinger_band'] = calculate_bolinger_band(df)
    df['ma50'] = calculate_ma50(df)
    return df

def calculate_rsi(df):
    gain = df['close'].diff().where(df['close'].diff() > 0, 0)
    loss = df['close'].diff().where(df['close'].diff() < 0, 0)
    avg_gain = gain.rolling(14).mean()
    avg_loss = loss.rolling(14).mean().abs()
    rs = avg_gain / avg_loss
    rsi = 100 - (100 / (1 + rs))
    return rsi

def calculate_bolinger_band(df):
    rolling_mean = df['close'].rolling(window=20).mean()
    rolling_std = df['close'].rolling(window=20).std()
    bolinger_high = rolling_mean + (rolling_std * 2)
    bolinger_low = rolling_mean - (rolling_std * 2)
    bolinger_band = (df['close'] - bolinger_low) / (bolinger_high - bolinger_low)
    return bolinger_band

def calculate_ma50(df):
    ma50 = df['close'].rolling(window=50).mean()
    return ma50

def create_features_and_labels(df):
    df['price_pattern'] = np.where(df['close'].diff(1) > 0, 1, 0)
    df['rsi_pattern'] = np.where(df['rsi'].diff(1) > 0, 1, 0)
    X = df[['rsi_pattern', 'bolinger_band', 'ma50']]
    y = df['price_pattern']
    return X, y

def train_model(X_train, y_train):
    model = DecisionTreeClassifier()
    model.fit(X_train, y_train)
    return model

def evaluate_model(model, X_test, y_test):
    y_pred = model.predict(X_test)
    accuracy = accuracy_score(y_test, y_pred)
    return accuracy

def save_model(model, file_name):
    joblib.dump(model, file_name)

def load_model(file_name):
    return joblib.load(file_name)

def write_result_to_csv(file_name, stock_name, result):
    with open(file_name, 'a') as f:
        f.write(f'{stock_name},{result}\n')

if __name__ == '__main__':
    stock_








# Get a list of all the CSV files in the directory
files = [f for f in os.listdir() if f.endswith('.csv')]

# Read each file into a separate DataFrame and store them in a list
dfs = [pd.read_csv(f) for f in files]

# Concatenate the DataFrames into a single DataFrame
df = pd.concat(dfs, ignore_index=True)

machine learning photomachine learning photomachine learning photo

disable all logging ubuntu 22.04

you can stop the rsyslog service using the sudo service rsyslog stop command. However, as the warning message indicates, stopping the rsyslog service will not necessarily prevent messages from being written to the log files if the syslog.socket unit is still active.

If you want to completely disable logging, you should disable or stop any other services or applications that might be writing to the log files. Additionally, you can also disable the syslog.socket unit to prevent any further messages from being logged:

bash

sudo systemctl disable syslog.socket

This command will prevent the syslog.socket unit from automatically starting on boot, which means that no further messages will be logged until the unit is manually started again.

free docker registry as of March 2023

Docker hub change their policy for docker registry

As of 2023, Docker Hub still offers a free plan, but with more limitations compared to the paid plans. The free plan includes one private repository and 500 MB of storage, with a limit of 200 pull requests per day.

If you need more storage and features, you can consider using alternative Docker registries that offer free plans, such as:

  1. GitHub Container Registry: This is a Docker registry that’s integrated with GitHub and allows you to store and manage Docker images in your GitHub repositories. It offers unlimited free storage and bandwidth, but has a limit of 500 MB per package size.
  2. Harbor: This is an open-source Docker registry that allows you to store and manage Docker images on your own infrastructure. It offers unlimited free storage and bandwidth, but requires you to set up and maintain your own registry server.
  3. Google Container Registry: This is a Docker registry that’s integrated with Google Cloud Platform and allows you to store and manage Docker images in your Google Cloud Storage buckets. It offers 5 GB of free storage per month and a limit of 1 GB per image size.
  4. Quay.io: This is a Docker registry that’s owned by Red Hat and allows you to store and manage Docker images in a private or public repository. It offers unlimited free storage and bandwidth for public repositories, and a limit of 500 MB per private repository.

Note that the free plans for these Docker registries may have some limitations or restrictions, so be sure to check their documentation and terms of service before using them.