HomeTom - CS

Wednesday, March 25, 2026

github 类似 开源网站

github 类似 开源网站 - 实践

From: https://www.cnblogs.com/jzssuanfa/p/19491107

分类整理:就是除了 GitHub,国内外还有许多优秀的代码托管和开发者协作平台,各有特色。以下

全球知名平台

1. GitLab

  • 特点:最强的一体化 DevOps 平台,CI/CD 功能内建且强大,社区版免费且功能齐全。

  • 网址gitlab.com(云端版)或可自行部署。

2. Bitbucket

  • 特点:Atlassian 旗下,与 Jira、Trello 等项目管理工具深度集成,适合企业团队。

  • 网址bitbucket.org

3. AWS CodeCommit

  • 特点:亚马逊 AWS 生态内的托管 Git 仓库,与 AWS 服务无缝集成。

  • 适用:深度使用 AWS 云服务的团队。

4. SourceForge

  • 特点:历史悠久,早期著名的开源项目托管地,现在也协助 Git。

  • 网址sourceforge.net

5. Launchpad

  • 特点:由 Canonical 运营,主要托管 Ubuntu 相关项目,使用 Bazaar 版本控制系统。

  • 网址launchpad.net

国内优秀平台

1. Gitee(码云)

  • 特点:国内最大、最流行的代码托管平台,速度快,符合中国本地化需求,提供企业版。

  • 网址gitee.com

2. 腾讯云开发者平台(Coding)

  • 特点:提供一站式 DevOps、项目管理、持续集成,与腾讯云服务集成。

  • 网址dev.tencent.com / coding.net(已合并)

3. 阿里云 Codeup

  • 特点:阿里云旗下,集成于“云效”DevOps 平台,献出代码管理和智能研发功能。

  • 网址codeup.aliyun.com

4. 开源中国(GitCode)

  • 特点:开源中国社区推出的代码托管服务,与 OSC 社区紧密结合。

  • 网址gitcode.net

特色/新兴平台

1. Radicle

  • 特点:基于点对点网络的去中心化代码协作平台,无需中央服务器。

  • 网址radicle.xyz

2. Codeberg

  • 特点:基于 Forgejo(Gitea 分支),在德国运营的非营利性开源托管平台。

  • 网址codeberg.org

3. Gitea / Forgejo

  • 特点:轻量级、可自托管的 Git 服务,许多小规模托管站基于它们搭建。

选择建议

  • 个人/开源工程GitHub仍是全球首选,社区最活跃。国内访问考虑Gitee

  • 企业/私有方案GitLab(功能强大)、Bitbucket(集成 Jira)、腾讯云 DevOps阿里云云效(国内企业)。

  • 注重隐私与自主权:自建 GitLabGiteaForgejo

  • 深度集成特定云:选择对应厂商的平台(AWS CodeCommit、Azure Repos)。

 

Tuesday, February 24, 2026

Install Keras on Mac

 To install Keras on a Mac, install TensorFlow (which includes Keras) using  

pip install tensorflow 

or  

pip install tensorflow-macos for Apple Silicon (M1/M2/M3) chips. 

For best performance on M1/M2/M3 chips, use conda to install tensorflow-deps

Verify with python -c "import keras; print(keras.__version__)"

 

== Use PIP (Standard & Apple Silicon)

# Upgrade pip
pip3 install --upgrade pip

# Install TensorFlow (includes Keras)
pip3 install tensorflow
 
Note: TensorFlow works with Python 3.9-2.12. 

The recommended way to install and manage multiple Python versions on a Mac is by using a version manager like pyenv, which prevents conflicts with the system's default Python installation.

== Use pyenv (Recommended for Developers)

brew install pyenv 

You may also want the pyenv-virtualenv plugin for creating isolated project environments: 

bash  brew install pyenv-virtualenv

Configure your shell: You need to initialize pyenv in your shell (e.g., Zsh, the default for modern macOS). Add the necessary lines to your shell's configuration file (commonly ~/.zshrc or ~/.bashrc) and restart your terminal as per the pyenv documentation instructions.

pyenv install 3.12.0

Switch between versions:

  • Globally: Set a global default version for all your shell sessions:
    bash
    pyenv global 3.12.0
    
  • Per Project: Navigate to a project directory and set the local Python version, which creates a .python-version file:
    bash
    pyenv local 3.12.0
    
  • Create a Virtual Environment: Use pyenv-virtualenv to create an isolated environment for a project with a specific Python version:
    bash
    pyenv virtualenv 3.12.0 myprojectenv
    cd myprojectdir
    pyenv local myprojectenv
    

 

Create local env:

# Create a virtual environment (e.g., named 'tf-env')
python -m venv tf-env

# Activate it (Linux/macOS)
source tf-env/bin/activate
 
Then install:
pip install tensorflow
 
Verify:
import tensorflow as tf
print(tf.keras.__version__)
print(tf.__version__) 
  


Monday, February 16, 2026

Run apache and nginx on same server

AI Overview

Common Configuration Methods
 
You have several options to run both servers simultaneously:
  • Different Ports: This is the simplest method. Configure one server (e.g., Apache) to listen on a non-standard port like 8080 or 81, while the other (e.g., Nginx) uses the default 80 (HTTP) and 443 (HTTPS) ports. Users would access the second server by appending the port number to the URL (e.g., http://yourdomain.com:8080).
  • Different IP Addresses: If your server has multiple IP addresses, you can bind each web server to a unique IP address on the same port (80/443).
  • Nginx as a Reverse Proxy (Recommended): This leverages the strengths of both servers. Nginx (known for speed and efficiency in static content and high concurrency) listens on the public ports 80 and 443. It serves static files directly and proxies requests for dynamic content (like PHP applications that rely on .htaccess files) to Apache, which is configured to listen on an internal, loopback IP and port (e.g., 127.0.0.1:8080). This setup improves overall performance and resource usage.
Steps for a Reverse Proxy Setup (Nginx in front of Apache)
 
A typical configuration involves these general steps (specific file paths may vary by operating system):
  1. Configure Apache to use a different port: Edit the Apache configuration files (ports.conf and the default virtual host file) to change the listening ports from 80/443 to an internal port like 8080.
  2. Configure Nginx as a reverse proxy: Set up Nginx to listen on the public ports 80/443. For dynamic requests, add proxy directives within the Nginx virtual host configuration to forward traffic to the Apache port (e.g., proxy_pass http://localhost:8080;).
  3. Install mod_rpaf (or mod_remoteip) on Apache: This module ensures Apache logs the client's real IP address instead of Nginx's localhost IP, which is useful for statistics and authentication.
  4. Restart services: After configuration changes, restart both Nginx and Apache to apply the new settings.
This combined approach allows you to benefit from Nginx's performance for static content while still using Apache for applications that require its specific features.

How To Deploy a React Application with Nginx on Ubuntu

 

Learn how to deploy a React app with Nginx on Ubuntu. Step-by-step guide covering build, server config, reverse proxy, SSL, and production optimization.

To host a React application on an Ubuntu server, you need to
install Node.js and npm, build your application, and then use a web server like Nginx to serve the static files.
 
Prerequisites
  • An Ubuntu server (virtual machine or physical).
  • SSH access to your server (use a client like PuTTY on Windows).
  • A React application built on your local machine.
Step-by-Step Deployment Guide
  1. Connect to Your Server
    Use SSH to connect to your Ubuntu server using its IP address and your credentials.
  2. Install Node.js and npm
    React requires Node.js and npm to build the application.
    • Update your server's package list: sudo apt update
    • Install Node.js and npm: sudo apt install nodejs npm
    • Verify the installation: node -v and npm -v
  3. Transfer Your React App Files
    Build your React application on your local machine using the command: npm run build. This creates a production-optimized build directory. Transfer the contents of this build directory to your Ubuntu server using tools like scp, rsync, or by cloning your repository from GitHub on the server itself.
  4. Install and Configure Nginx
    Nginx is a high-performance web server that will serve your application's static files.
    • Install Nginx: sudo apt install nginx
    • Start and enable the Nginx service: sudo systemctl start nginx and sudo systemctl enable nginx
    • Create a new Nginx configuration file for your site in the /etc/nginx/sites-available/ directory. You can use a text editor like nano (e.g., sudo nano /etc/nginx/sites-available/your_domain):
      nginx
      server {
          listen 80;
          server_name your_domain www.your_domain;
      
          root /var/www/your_domain/html;
          index index.html index.htm;
      
          location / {
              try_files $uri $uri/ /index.html;
          }
      }
      
      (Replace your_domain with your actual domain name and adjust the root path to where you placed your build files, for example, /var/www/your_domain/html).
  5. Enable Your Nginx Site
    • Create a symbolic link from your configuration file in sites-available to the sites-enabled directory:
      sudo ln -s /etc/nginx/sites-available/your_domain /etc/nginx/sites-enabled/
    • Test your Nginx configuration for syntax errors: sudo nginx -t
    • Restart Nginx to apply the changes: sudo systemctl restart nginx
Your React application should now be accessible in a web browser via your server's IP address or domain name. For a secure connection, you should also set up SSL certificates using a tool like Certbot.

How To Deploy a React Application with apache on Ubuntu

 

To deploy a React application with Apache on Ubuntu, you need to
build your application for production, configure Apache to serve the static files, and ensure proper handling of client-side routing using an .htaccess file.
 
Prerequisites
  • An Ubuntu server with Apache installed.
  • Node.js and npm installed on your local machine or server.
  • A React application ready for deployment.
Step-by-Step Guide
 
 
1. Build the React Application
On your local machine, navigate to your project's root directory in the terminal and run the build command to generate production-ready static files:
bash
npm run build
This command creates an optimized build (or dist if using Vite) folder containing your static assets.
2. Prepare the Ubuntu Server and Upload Files
 
Connect to your Ubuntu server via SSH and prepare a directory to host your application.
  • Create a directory for your site (replace yourwebsite.com with your domain or desired folder name):
    bash
    sudo mkdir -p /var/www/yourwebsite.com
    
  • Set ownership of the directory:
    bash
    sudo chown -R $USER:$USER /var/www/yourwebsite.com
    
  • Upload the contents of the local build folder to the server's directory (e.g., /var/www/yourwebsite.com) using an FTP client like FileZilla or scp.
 
3. Configure Apache for React Routing
 
React applications use client-side routing, which means direct access to sub-routes (e.g., ://yourwebsite.com) will result in a 404 error without proper server configuration. Apache needs to be instructed to redirect all requests to the index.html file.
  • Enable the mod_rewrite module:
    bash
    sudo a2enmod rewrite
    
  • Create a .htaccess file: Inside your application's root directory on the server (e.g., /var/www/yourwebsite.com), create a file named .htaccess and add the following snippet:
    apache
    Options -MultiViews
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.html [QSA,L]
    
    This snippet tells Apache that if a requested file does not exist, it should load index.html.
  • Ensure AllowOverride All is set: You might need to edit your Apache configuration to allow .htaccess files to override settings.
    • Open your virtual host file or the main apache2.conf file (e.g., /etc/apache2/sites-available/000-default.conf or /etc/apache2/apache2.conf).
    • Find the <Directory /var/www/html> block (or your custom directory block) and ensure AllowOverride is set to All:
    apache
    <Directory /var/www/yourwebsite.com>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
    
4. Restart Apache
 
After making configuration changes, restart Apache for them to take effect:
bash
sudo systemctl restart apache2
Your React application should now be deployed and accessible via your server's IP address or domain name.

Python: virtual environments (venv) and environment variables (.env)

 

The venv module supports creating lightweight “virtual environments”, each with their own independent set of Python packages installed in their site ...
In Python, creating a "private environment" generally refers to two primary concepts:
 
- virtual environments for project isolation and managing dependencies, and 
- using environment variables and .env files for securely managing sensitive information (secrets).
1. Project Isolation with Virtual Environments (venv)
 
A virtual environment is a self-contained directory that contains a specific Python interpreter and its own isolated set of Python packages. This prevents conflicts between the dependencies of different projects and keeps your global Python installation clean.
Key Steps:
  • Creation: Navigate to your project directory in the terminal and run the following command to create a virtual environment named .venv (a common convention):
    bash
    python -m venv .venv
    
    This creates a directory containing the isolated Python installation.
  • Activation: Before working on your project, you must activate the environment:
    • macOS/Linux:
      bash
      source .venv/bin/activate
      
    • Windows:
      bash
      .venv\Scripts\activate
      
    Once activated, your terminal prompt will usually change to indicate the active environment (e.g., (.venv) YourName: ).
  • Deactivation: To leave the virtual environment, simply run:
    bash
    deactivate
    
  • Version Control: You should add the environment directory (e.g., .venv) to your .gitignore file to prevent accidentally committing it to source control. The environment is considered disposable and can be recreated from a requirements.txt file at any time.
  • Managing Python Versions: For managing multiple Python versions themselves on a single system (e.g., switching between Python 3.10 and 3.12), tools like pyenv can be used alongside venv.
 
2. Storing Secrets with .env Files
 
To keep sensitive information like API keys, passwords, and credentials out of your source code, you use environment variables loaded from a .env file.
Key Steps:
  • Create a .env file: In your project's root directory, create a file named .env. Inside this file, store key-value pairs (e.g., API_KEY=your_secret_key).
    • Crucial: Add the .env file to your .gitignore file immediately to prevent it from being committed to source control.
  • Install python-dotenv: Install the required package using pip within your activated virtual environment:
    bash
    pip install python-dotenv
    
    You can find the package on the official PyPI repository.
  • Load Variables in Python: In your Python code (e.g., app.py), use the load_dotenv function to read the variables, and access them using the standard os module.
    python
    import os
    from dotenv import load_dotenv
    
    # Load environment variables from .env file
    load_dotenv()
    
    # Access the variables
    api_key = os.getenv("API_KEY")
    database_url = os.getenv("DATABASE_URL")
    
    print(f"Key: {api_key}")
    
This ensures your sensitive data is kept private and can be easily managed across different deployment environments.

Ubuntu installation log

- sudo apt update
- sudo apt install vim
- sudo apt install build-essential
  This command will install G++, GCC, make, and other core development libraries.
  - gcc/g++ 15.2.0
    g++-15 -std=c++20 hello.cpp -o hello
  - perl 5, version 40, subversion 1 (v5.40.1)
- sudo apt install default-jdk
  This installs Java.
  - javac --version : javac 21.0.10
  - java --version  : openjdk version "21.0.10" 2026-01-20
- sudo apt install php
  This installs PHP.
  - PHP 8.4.11 (cli) (built: Jan  7 2026 08:44:00) (NTS)

- sudo apt install apache2
  apache2 is already the newest version (2.4.64-1ubuntu3.2)
  - sudo systemctl status apache2
  - server is running
  - conf: /etc/apache2/
  - /var/www/html/ 

- Python is pre-installed on all modern Ubuntu:
  - Python 3.13.7
- sudo apt install python3-pip
  This installs pip (Python package manager)
  - pip 25.1.1 from /usr/lib/python3/dist-packages/pip (python 3.13)

- sudo apt install python3-venv
  sudo apt install python3.14-venv
  Install venv (virtual environment module): This is crucial for creating isolated environments 
  for your projects to manage dependencies without affecting the system Python.
  - You also need to install for each python version

- sudo apt install software-properties-common
  This installs the add-apt-repository command in Ubuntu.
  - type add-apt-repository
    add-apt-repository is /usr/bin/add-apt-repository
  - You can now use the command to add a new repository, for example, a Personal Package Archive (PPA):
    sudo add-apt-repository ppa:some/ppa-name
- sudo add-apt-repository ppa:deadsnakes/ppa
  sudo apt update
  - This adds the deadsnakes PPA.

- sudo apt install python3.14
  - Installs Python 3.14
  - python3.14 --version
    3.14.0
  - python3 --version
    3.13.7

- make Python an alias of python3.14:
  - vi ~/.bash_aliases
  - add: alias python=python3.14
  - source ~/.bash_aliases

- mkdir wschat
  cd wschat
  python -m venv .myenv
  source .myenv/bin/activate
  - pip install autobahn[twisted]
  deactivate


Blog Archive

Followers