Wednesday, February 19, 2025

How to export Chromium bookmarks

To export bookmarks from Chromium, you can follow these steps:

Method 1: Using Chromium’s Built-in Export Function (Recommended)
Open Chromium browser.
Go to the Bookmarks Manager:
Type chrome://bookmarks/ in the address bar and press Enter, or
Click the three-dot menu in the top right → Bookmarks → Bookmark Manager.
Export bookmarks:
Click the three-dot menu in the Bookmarks Manager.
Select Export bookmarks.
Choose where to save the file (it will save as a .html file).
The exported HTML file can be imported into other browsers like Firefox, Edge, Chrome, or Ungoogled Chromium.
Method 2: Manually Backing Up the Bookmarks File
If you prefer to manually backup the bookmarks file, you can copy Chromium’s bookmarks database file.

Windows
1.Open File Explorer and navigate to:

C:UsersYourUsernameAppDataLocalChromiumUser DataDefault

2.Find the file named Bookmarks (without an extension).
3.Copy the file and save it to a secure location.
Linux
1.Open a terminal and run:

cp ~/.config/chromium/Default/Bookmarks ~/Desktop/

This will copy the bookmarks file to your desktop.
MacOS
1.Open Finder, press Command + Shift + G, and enter:

~/Library/Application Support/Chromium/Default/

2.Find the Bookmarks file and copy it.
Note:

This method does not generate an .html file but copies the original Chromium bookmarks database file.
You can replace this file with another Chromium or Ungoogled Chromium bookmarks file (ensure the browser is closed before doing this).
For easy importing, Method 1 is generally better as it creates an HTML file that can be used across different browsers! 🚀

Sunday, February 2, 2025

Here’s the process to create an online translation tool on a static webpage without needing a database.

Steps to Create an Online Translator on a Static Website:
You can implement a translation feature on a static webpage by integrating a third-party translation API like Google Translate API or MyMemory Translation API. The process involves creating a simple HTML page with JavaScript to interact with the translation API.

1. Frontend: HTML + CSS + JavaScript (Translation Interface)
1.1 HTML Structure for Translator
First, create a simple HTML interface with a text input box, a language selection dropdown, and a translate button. The JavaScript will interact with the API and display the translation result.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Online Translator</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            height: 100vh;
            margin: 0;
            background-color: #f7f7f7;
        }
        #translator-container {
            width: 400px;
            max-width: 100%;
            background-color: white;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            padding: 20px;
            display: flex;
            flex-direction: column;
        }
        textarea {
            width: 100%;
            padding: 10px;
            margin-bottom: 10px;
            height: 100px;
            border-radius: 5px;
            border: 1px solid #ccc;
            font-size: 14px;
        }
        select, button {
            padding: 10px;
            margin-bottom: 10px;
            border-radius: 5px;
            border: 1px solid #ccc;
            font-size: 14px;
        }
        #translated-text {
            padding: 10px;
            background-color: #e1e1e1;
            border-radius: 5px;
            min-height: 60px;
        }
    </style>
</head>
<body>
    <h1>Online Translator</h1>
    <div id="translator-container">
        <textarea id="text-input" placeholder="Enter text to translate..."></textarea>
        <select id="language-select">
            <option value="en">English</option>
            <option value="es">Spanish</option>
            <option value="fr">French</option>
            <option value="de">German</option>
            <option value="zh">Chinese</option>
        </select>
        <button onclick="translateText()">Translate</button>
        <div id="translated-text">Translation will appear here...</div>
    </div>

    <script>
        async function translateText() {
            const text = document.getElementById('text-input').value;
            const targetLanguage = document.getElementById('language-select').value;

            if (!text.trim()) {
                document.getElementById('translated-text').textContent = 'Please enter text to translate.';
                return;
            }

            const translatedTextDiv = document.getElementById('translated-text');
            translatedTextDiv.textContent = 'Translating...';

            // Send request to the translation API
            const response = await fetch(`https://api.mymemory.translated.net/get?q=${encodeURIComponent(text)}&langpair=en|${targetLanguage}`);
            const data = await response.json();
            
            if (data.responseStatus === 200) {
                translatedTextDiv.textContent = data.responseData.translatedText;
            } else {
                translatedTextDiv.textContent = 'Translation failed, please try again.';
            }
        }
    </script>
</body>
</html>

2. Use an API for Translation
2.1 Using MyMemory Translation API (No API Key Required)
This example uses the MyMemory Translation API, which is free and doesn’t require an API key. Here’s how it works:

q: The text to be translated.
langpair: The language pair (e.g., translating from English to Spanish, en|es).

const response = await fetch(`https://api.mymemory.translated.net/get?q=${encodeURIComponent(text)}&langpair=en|${targetLanguage}`);

2.2 Using Google Translate API
If you’d like to use the Google Translate API, you’ll need to first create a Google Cloud Platform account, enable the Cloud Translation API, and get an API key.

1.Get the API Key:

Sign up at Google Cloud Console.
Create a new project.
Enable Cloud Translation API.
Create an API key.
2.Use Google Translate API in JavaScript:

async function translateText() {
    const text = document.getElementById('text-input').value;
    const targetLanguage = document.getElementById('language-select').value;

    const apiKey = 'YOUR_GOOGLE_API_KEY'; // Replace with your actual API key

    if (!text.trim()) {
        document.getElementById('translated-text').textContent = 'Please enter text to translate.';
        return;
    }

    const translatedTextDiv = document.getElementById('translated-text');
    translatedTextDiv.textContent = 'Translating...';

    const response = await fetch(`https://translation.googleapis.com/language/translate/v2`, {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
        },
        body: JSON.stringify({
            q: text,
            target: targetLanguage,
            key: apiKey
        }),
    });

    const data = await response.json();
    if (data.data && data.data.translations) {
        translatedTextDiv.textContent = data.data.translations[0].translatedText;
    } else {
        translatedTextDiv.textContent = 'Translation failed, please try again.';
    }
}

3. Deploying to Your Static Website
Upload the HTML file and JavaScript to your web server (e.g., using Nginx, Apache, or GitHub Pages).
Make sure your website is served over HTTPS, especially if you’re using the Google Translate API (or any third-party APIs that require secure connections).
Summary
By following the steps above, you can create a simple online translation tool on a static webpage without requiring a database. The tool interacts with a translation API like MyMemory API (free) or Google Translate API (requires API key), and it displays the translated text in real-time.

Here’s a process to create an online AI chat tool without needing a database.

We’ll build it with front-end (HTML/CSS/JS), a back-end (Node.js + Express), and the AI model (e.g., OpenAI API).

Tech Stack:
Frontend: HTML + CSS + JavaScript for the chat interface.
Backend: Node.js + Express (or other lightweight backend frameworks) to handle user input.
AI: OpenAI GPT-3/4 API (or any other available AI models) to generate chat responses.
Core Idea:
The user sends input to the backend.
The backend uses an AI API (like OpenAI) to generate the response.
The response is returned to the frontend and displayed without any database storage.
Steps:
1. Frontend: HTML + CSS + JS (Simple Chat UI)
Here’s a simple chat interface where the user can type a message and see the AI response:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>AI Chat</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            height: 100vh;
            margin: 0;
            background-color: #f7f7f7;
        }
        #chat-container {
            width: 400px;
            max-width: 100%;
            background-color: white;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            padding: 20px;
            display: flex;
            flex-direction: column;
            justify-content: flex-start;
            height: 400px;
            overflow-y: auto;
        }
        #messages {
            flex-grow: 1;
            margin-bottom: 20px;
            overflow-y: auto;
        }
        .message {
            padding: 10px;
            margin-bottom: 10px;
            border-radius: 5px;
            background-color: #e1e1e1;
        }
        .user-message {
            background-color: #007bff;
            color: white;
            text-align: right;
        }
        .bot-message {
            background-color: #f0f0f0;
            color: #333;
        }
        input {
            padding: 10px;
            width: 100%;
            border: 1px solid #ddd;
            border-radius: 5px;
        }
    </style>
</head>
<body>
    <h1>AI Chat</h1>
    <div id="chat-container">
        <div id="messages"></div>
        <input type="text" id="user-input" placeholder="Type a message..." />
    </div>

    <script>
        const messagesDiv = document.getElementById('messages');
        const userInput = document.getElementById('user-input');

        async function sendMessage() {
            const userMessage = userInput.value;
            if (userMessage.trim() === "") return;
            
            // Display user message
            const userMessageDiv = document.createElement('div');
            userMessageDiv.classList.add('message', 'user-message');
            userMessageDiv.textContent = userMessage;
            messagesDiv.appendChild(userMessageDiv);

            // Clear input field
            userInput.value = '';

            // Scroll to the bottom
            messagesDiv.scrollTop = messagesDiv.scrollHeight;

            // Fetch AI response
            const response = await fetch('/chat', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                },
                body: JSON.stringify({ message: userMessage }),
            });
            const data = await response.json();
            
            // Display bot response
            const botMessageDiv = document.createElement('div');
            botMessageDiv.classList.add('message', 'bot-message');
            botMessageDiv.textContent = data.reply;
            messagesDiv.appendChild(botMessageDiv);
            
            // Scroll to the bottom
            messagesDiv.scrollTop = messagesDiv.scrollHeight;
        }

        userInput.addEventListener('keydown', (event) => {
            if (event.key === 'Enter') {
                sendMessage();
            }
        });
    </script>
</body>
</html>

2. Backend: Node.js + Express Example
This part will handle requests from the frontend, and use the OpenAI API to get the AI response.

1.Install Node.js and required dependencies:

npm init -y
npm install express axios body-parser

2.Create server.js file with basic API route handling:

const express = require('express');
const axios = require('axios');
const bodyParser = require('body-parser');
const app = express();
const port = 3000;

// Replace with your OpenAI API key
const OPENAI_API_KEY = 'your_openai_api_key';

app.use(bodyParser.json());

// Serve static chat page
app.use(express.static('public')); // Assuming your HTML file is in the 'public' folder

// Chat route to interact with OpenAI API
app.post('/chat', async (req, res) => {
    const userMessage = req.body.message;

    try {
        const response = await axios.post('https://api.openai.com/v1/completions', {
            model: 'text-davinci-003', // or any other GPT-3 model
            prompt: userMessage,
            max_tokens: 150,
            temperature: 0.7,
        }, {
            headers: {
                'Authorization': `Bearer ${OPENAI_API_KEY}`,
                'Content-Type': 'application/json',
            },
        });

        const botReply = response.data.choices[0].text.trim();
        res.json({ reply: botReply });
    } catch (error) {
        console.error('Error:', error);
        res.status(500).send('Error with AI request');
    }
});

// Start server
app.listen(port, () => {
    console.log(`Server running at http://localhost:${port}`);
});

3. Run the Service
1.Start the server:

node server.js

2.Open the chat page at http://localhost:3000, type a message, and get a response from the AI.

4. Deploy to an HTTPS-Enabled Server
1.Upload the frontend files (e.g., index.html) and the backend to your server.
2.Set up HTTPS using Let’s Encrypt (or use your own SSL certificates) and configure your server accordingly.
Summary
You’ve just built a simple AI chat tool without needing a database. The system uses:

Frontend (HTML/CSS/JS) to create a user interface.
Backend (Node.js) to handle user input and interact with the OpenAI API.
AI Model (e.g., OpenAI GPT-3) to generate chat responses.
The system works on-demand and does not rely on a database.

Automated Optimization Script (debian11_optimize.sh)

Here’s the automated optimization script for Debian 11 on a KVM VPS!
Save the following script as debian11_optimize.sh and run it:
#!/bin/bash

echo "🚀 Starting Debian 11 CLI Optimization for KVM VPS"

# 1. Update System
apt update && apt upgrade -y
apt autoremove --purge -y
apt clean

# 2. Remove Unnecessary Packages
apt remove --purge -y apport popularity-contest avahi-daemon cups rpcbind xserver-common x11-common

# 3. Install KVM-Optimized Kernel
apt install -y linux-image-cloud-amd64

# 4. Update GRUB and Apply Optimizations
sed -i 's/GRUB_CMDLINE_LINUX_DEFAULT="[^"]*/& mitigations=off noibrs no_stf_barrier/g' /etc/default/grub
update-grub

# 5. Enable BBR TCP Congestion Control
echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf
echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf
sysctl -p

# 6. Configure DNS for Faster Resolution
sed -i 's/#DNS=/DNS=8.8.8.8 1.1.1.1/g' /etc/systemd/resolved.conf
systemctl restart systemd-resolved

# 7. SSH Hardening - Change SSH Port
sed -i 's/#Port 22/Port 22022/g' /etc/ssh/sshd_config
systemctl restart ssh

# 8. Install Fail2Ban to Prevent SSH Brute Force
apt install -y fail2ban

# 9. Setup Firewall with UFW
apt install -y ufw
ufw allow 22022/tcp
ufw allow 80/tcp
ufw allow 443/tcp
ufw enable

# 10. Disk & I/O Optimization
tune2fs -o journal_data_writeback /dev/vda1
tune2fs -m 1 /dev/vda1
echo "vm.swappiness=10" >> /etc/sysctl.conf
sysctl -p

# 11. CPU & Memory Optimization - Disable Unnecessary Services
systemctl disable --now systemd-resolved avahi-daemon cups
echo "performance" | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor

echo "✅ Optimization Complete! Please reboot your server."

Article 9 can be removed, because the firewall is not properly set up, it is easy for you to not even be able to log in to SSH.

1.How to Run the Script:
Create the script file:

nano debian11_optimize.sh

2.Paste the script content into the file, save, and exit.

3.Make the script executable:

chmod +x debian11_optimize.sh

4.Run the script with sudo:

sudo ./debian11_optimize.sh

This will automatically apply all optimizations for your Debian 11 CLI on a KVM VPS. After the script finishes, a reboot is recommended for all settings to take effect.

Saturday, February 1, 2025

Debian Optimization Guide

This guide is for Debian 11 CLI on a KVM VPS (/dev/vda1).

Manual Optimization Steps
1.1 Minimal System

sudo apt update && sudo apt upgrade -y
sudo apt autoremove --purge -y
sudo apt clean

Remove unnecessary packages:

sudo apt remove --purge -y apport popularity-contest avahi-daemon cups rpcbind xserver-common x11-common

1.2 Kernel Optimization

sudo apt install -y linux-image-cloud-amd64
sudo sed -i 's/GRUB_CMDLINE_LINUX_DEFAULT="[^"]*/& mitigations=off noibrs no_stf_barrier/g' /etc/default/grub
sudo update-grub

1.3 Network Optimization
Enable BBR:

echo "net.core.default_qdisc=fq" | sudo tee -a /etc/sysctl.conf
echo "net.ipv4.tcp_congestion_control=bbr" | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
lsmod | grep bbr

Improve DNS resolution:

sudo sed -i 's/#DNS=/DNS=8.8.8.8 1.1.1.1/g' /etc/systemd/resolved.conf
sudo systemctl restart systemd-resolved

1.4 Security Optimization
Change SSH port:

sudo sed -i 's/#Port 22/Port 22022/g' /etc/ssh/sshd_config
sudo systemctl restart ssh

1.5 Disk & CPU Optimization

sudo tune2fs -o journal_data_writeback /dev/vda1
sudo tune2fs -m 1 /dev/vda1
echo "vm.swappiness=10" | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
echo "performance" | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor

Now your Debian 11 VPS is optimized for performance and security! 🚀