dwm 和 st 的安装及补丁
发布时间:2023-05-05 15:59:30
归档分类:

前言

得益于近些日子在学校深入学习了很多关于 Linux 的知识,加之之前也多次重装过 Arch ,这些因素综合起来后,这一次的系统安装可以说颇为顺畅,之前因无法理解的地方而导致难以下手的操作,所赖知识见长,逐渐克服且熟练了起来。

本次为了更加深入地去学习 Linux ,所以放弃了像 Gnome 这样简单易用的桌面环境, 而是使用像 DWM 这样更简单的窗口管理器,虽然是自找麻烦,但我也乐在其中,我会在本文中简略地记录下折腾的过程。

DWM 和 st 的安装

事实上安装 DWM 非常的简单,自需要从 suckless 官网下载源码文件即可。


$ git clone git://git.suckless.org/dwm
$ cd dwm
$ make
# sudo make install

编译安装后,我这里是通过 xrog 的 .xinitrc 从 tty 终端使用 startx 命令启动的:

exec dwm

启动之后的第一眼就是简陋,目前还什么都干不了,因为我甚至还没安装终端,suckless 也提供了一个 xrog 下的终端实现,叫 st 。 通过魔法键回到 tty (ps.当然也可以通过快捷键:Alt + Shift + Q 退出 dwm ),通过 tty 的终端去下载 st 源码。

同样也是通过源码安装:

$ git clone https://git.suckless.org/st
$ cd st
$ make
# sudo make install

编译安装完后,在dwm便应该通过Alt + Shift + Enter 组合键启动 st 管终端。但是毫无疑问,也是十分简陋,甚至字体小到无法看清……

不过问题不大,我学过 C ,源码文件是能看懂的,首先就是修改了字体大小,顺带一提我还通过 pacman 包管理下载了 [ttf-fira-code] 字体。

首先来修改一下 dwm 的字体和其大小:

# dwm > config.h

static const char *fonts[]          = { "Fira Code:size=14" };
static const char dmenufont[]       = "Fira Code:size=14";

保存后通过 sudo make clean install 命令安装即可

接着修改 st 终端的字体和大小:

# st > config.h

static char *font = "Fira Code:style=Bold:pixelsize=23:antialias=true:autohint=true";

保存后通过 sudo make clean install 命令安装即可

这样修改完后,便好看很多了。

安装 dmenu

这个就是 suckless 的程序托盘? 总之,安装后,可以快速打开程序,也是蛮好的,这个就没有使用源码安装了,不过听说它也有很多好玩之处,之后再研究吧,总之 dmenu 通过包管理器安装:

$ sudo pacman -S dmenu

给 dwm 打补丁

Dwm 目前其实足够我使用了, 这里就打一个透明补丁: 「 alpha.diff

$ wget https://dwm.suckless.org/patches/alpha/dwm-alpha-20201019-61bb8b2.diff
$ patch p1 < dwm-alpha-20201019-61bb8b2.diff

通过 patch 命令 把补丁打进去即可,之前我都没怎么用过这个 patch 命令,用多了其实也还好,出现错误了,手动去修改源文件即可。

给 st 打补丁

这里打了好几个补丁:

也是一样地通过 patch 命令打进去,这里就不再赘述了。

安装 picom

这是一个合成管理器,可以给窗口管理器带来需要效果,比如透明、阴影,上面的透明补丁也需要它的安装才能真正起作用。

$ sudo pacman -S picom

安装完后,编辑 ~/.xinitrc 文件,进程让它以 Daemon(后台) 的形式运行。

compton -b

(未完待续)

  • dwm
  • st
  • dmenu
  • 重新安装 Archlinux
    发布时间:2023-05-03 11:22:11
    归档分类:

    前言

    最近系统频繁死机,通过初步判断,应该是图形界面的卡死,但不合理的是 —— 我无法通过魔法键退出到tty界面……

    我尝试了复现,但这似乎是没有规律的,我其实开始怀疑是我的SSD的问题了,但转头用了两天DWM,期间没有出现卡死现象,那问题很大可能就是图形界面卡死,Gnome和我目前的系统内核不匹配?

    总之,我决定对系统做一次全面的重置。

    这里放一个 Chrome 插件: Ghelper

  • archlinux
  • [NFS] mount: Connection timed out
    发布时间:2023-04-06 20:09:29
    归档分类:

    问题描述

    Linux 服务端和 Arm 开发板客户端进行 NFS 服务的连接。

    Linux 和 Arm 开发板之间能ping通,并且处于同一网端,且掩码、网口相同,但是在执行下面的程序时发生超时错误。

    在服务端的nfs配置完全正确的情况下,Arm开发板还是无法正确连接nfs服务器。

    [root@FORLINX6410]# mount -t nfs -o nolock,hard 192.168.1.5:/home/yarnom/nfs /mnt
    mount: mounting 192.168.1.5:/home/yarnom/nfs on /mnt failed: Connection timed out
    
    

    解决

    这个问题困扰了我两天终于在这个帖子里找到了解决方案。

    Mount the NFS filesystem using the TCP protocol instead of the default UDP protocol. Many NFS servers only support UDP.

    这是在NFSv3中添加了对TCP协议的支持:

    总之,我尝试了下面的命令,使用了tcp协议:

    $ mount -t nfs -o nolock,proto=tcp,port=2049 192.168.1.5:/home/yarnom/nfs /mnt
    

    这个协议最终使我正确连接上了nfs服务器。

  • NFS
  • ARM
  • 2023-03-31 英语翻译练习
    发布时间:2023-03-31 13:20:27
    归档分类:

    Studying for a graduate exam can be challenging, but with the right mindset and study strategies, it can be manageable. It's important to prioritize your time, focusing on your weak areas while also reviewing what you already know. Practice exams can be helpful in identifying areas for improvement and getting a sense of the exam format. Additionally, developing good study habits, such as taking breaks and getting enough sleep, can increase your overall productivity and retention of material. Remember to stay motivated and keep a positive attitude, as this will help you stay focused and achieve your goals.

    备考研究生考试可能是具有挑战性的,但是只要拥有正确的心态和学习策略,就可以应对。重要的是要优先考虑时间,专注于自己的薄弱领域,同时复习已经掌握的知识。模拟考试可以帮助您确定需要改进的方面,并了解考试的格式。此外,养成良好的学习习惯,如休息和充足的睡眠,可以提高您的总体生产力和记忆材料的能力。记住要保持动力和积极的态度,因为这将帮助您保持专注,实现自己的目标。

    prioritize - 优先考虑 weak areas - 薄弱领域 retention - 记忆 productivity - 生产力/工作效率 positive attitude - 积极态度

  • 英语
  • 对未来的一些思考
    发布时间:2023-03-28 14:43:31
    归档分类:

    这段时间我在写积分题,写到后面的难题感觉特别的痛苦,我自然是不应该放弃的,我应该坚持下去。

    虽然如此劝慰自己,但在行动上还是逃避,退后。

    自闭。

    走了出来,为了什么?

    不去逃避就是最大的勇气。

  • 思考
  • 工程 [2023_3_25] 附录文件「二」 - Flask SQLAlchemy
    发布时间:2023-03-26 16:19:51
    归档分类:

    前言

    本文主要介绍 Flask SQLAlchemy 的具体使用。

    如需要了解 Flask 入门文档可跳转:

    Setup

    Install MySQL/MariaDB

    1. Installation

    MariaDB is the default implementation of MySQL in Arch Linux, provided with the mariadb package.

    Install mariadb, and run the following command before starting the mariadb.service

    # mariadb-install-db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
    

    2. Configuration

    Once you have started the MariaDB server and added a root account, you may want to change the default configuration.

    To log in as root on the MariaDB server, use the following command:

    # mariadb -u root -p
    
    2.1 Add user

    Creating a new user takes two steps: create the user; grant privileges. In the below example, the user monty with some_pass as password is being created, then granted full permissions to the database mydb:

    # mariadb -u root -p
    
    MariaDB> CREATE USER 'monty'@'localhost' IDENTIFIED BY 'some_pass';
    MariaDB> GRANT ALL PRIVILEGES ON mydb.* TO 'monty'@'localhost';
    MariaDB> quit
    

    安装 PyMySQL 和 Flask-SQLAlchemy

    使用python 提供 pip 包管理器安装 pymysqlFlask-SQLAlchemy

    $ pip install PyMySQL
    $ pip install flask-sqlalchemy
    

    Connection URI Format

    For a complete list of connection URIs head over to the SQLAlchemy documentation under (Supported Databases). This here shows some common connection strings.

    SQLAlchemy indicates the source of an Engine as a URI combined with optional keyword arguments to specify options for the Engine. The form of the URI is:

    dialect+driver://username:password@host:port/database
    

    MySQL:

    mysql://scott:tiger@localhost/mydatabase
    

    Configuration Keys

    SQLALCHEMY_DATABASE_URI

    The database URI that should be used for the connection. Examples:

    • sqlite:////tmp/test.db
    • mysql://username:password@server/db

    创建数据库

    安装完上边的套件后,就可以正式创建Mysql数据库了。

    使用root用户创建数据库

    sudo mariadb -u root -p
    

    进入mariadb后,使用如下命令创建数据库:

    MariaDB [(none)]> create database proj_20230325;
    Query OK, 1 row affected (0.000 sec)
    

    给予权限

    之后给予用户 Yarnom 该数据库的所有权限:

    MariaDB [(none)]> GRANT ALL PRIVILEGES ON proj_20230325.* TO 'yarnom'@'localhost';
    Query OK, 0 rows affected (0.009 sec)
    

    安装 FLask-Migrate

    $ pip install Flask-Migrate
    

    配置

    from flask_migrate import Migrate
    app = Flask(__name__)
    app.config['SQLALCHEMY_DATABASE_URI'] = "mysql+pymysql://yarnom:root@localhost:3306/proj_20230325"
    db = SQLAlchemy(app)
    Migrate(app,db)
    

    初始化

    $ flask db init
    

    Flask 使用Mysql数据库

    创建出相应的模板:

    class Student(db.Model):
        id = db.Column('id', db.String(100),primary_key=True)
        name = db.Column('name',db.String(100))
        def __init__(self, id, name):
            self.id =id
            self.name = name
    

    使用如下命令更新数据库

    $ flask db migrate -m "說明文字"
    $ flask db upgrade
    

    Flask-Sqlalchemy 使用

    以下内容转载自flask-sqlalchemy 官方文档

    Flask 添加数据

    me = User('admin', '[email protected]')
    db.session.add(me)
    db.session.commit()
    

    Flask 查询数据

    So how do we get data back out of our database? For this purpose Flask-SQLAlchemy provides a query attribute on your Model class. When you access it you will get back a new query object over all records. You can then use methods like filter() to filter the records before you fire the select with all() or first(). If you want to go by primary key you can also use get().

    The following queries assume following entries in the database: |id|username|email| |---|---|---| |1|admin|[email protected]| |2|peter|[email protected]| |3|guest|[email protected]|

    Retrieve a user by username:

    >>> peter = User.query.filter_by(username='peter').first()
    >>> peter.id
    2
    >>> peter.email
    u'[email protected]'
    

    Same as above but for a non existing username gives None:

    >>> missing = User.query.filter_by(username='missing').first()
    >>> missing is None
    True
    

    Selecting a bunch of users by a more complex expression:

    >>> User.query.filter(User.email.endswith('@example.com')).all()
    [<User u'admin'>, <User u'guest'>]
    

    Ordering users by something:

    >>> User.query.order_by(User.username).all()
    [<User u'admin'>, <User u'guest'>, <User u'peter'>]
    

    Limiting users:

    >>> User.query.limit(1).all()
    [<User u'admin'>]
    

    Getting user by primary key:

    >>> User.query.get(1)
    <User u'admin'>
    
  • 开发记录
  • Flask
  • Debtap
    发布时间:2023-03-26 15:54:44
    归档分类:

    Setup

    ==> You must run at least once "debtap -u"
    with root privileges (preferably recently),
    before running this script
    
    ==> Syntax: debtap [option] package_filename
    
    ==> Run "debtap -h" for help
    

    Update debtap source

    $ debtap -u
    

    Convert deb package

    debtap xxx.deb
    

    Install

    sudo pacman -U xxx.pkg
    
  • debtap
  • 工程 [2023_3_25] 附录文件「一」 - Flask 起步
    发布时间:2023-03-26 15:21:24
    归档分类:

    前言

    因为前段时间实验室老师要求我完成一个项目,是有关学校教务系统的,要求完成一个微信小程序。

    目前处于实验阶段,老师也没有给我需求文档,所以目前的情况就是做些东西练练手。这里记录一下,之后正式工作了能快速完成基本的构建。

    以下内容转载自 Flask官方文档

    Flask Installation

    Create an environment

    Create a project folder and a venv folder within:

    $ mkdir myproject
    $ cd myproject
    $ python3 -m venv venv
    

    Activate the environment

    Before you work on your project, activate the corresponding environment:

    $ . venv/bin/activate
    

    Install Flask

    Within the activated environment, use the following command to install Flask:

    $ pip install Flask
    

    Quickstart

    A minimal Flask application looks something like this:

    from flask import Flask
    
    app = Flask(__name__)
    
    @app.route("/")
    def hello_world():
        return "<p>Hello, World!</p>"
    

    So what did that code do?

    1. First we imported the Flask class. An instance of this class will be our WSGI application.

    2. Next we create an instance of this class. The first argument is the name of the application’s module or package. __name__ is a convenient shortcut for this that is appropriate for most cases. This is needed so that Flask knows where to look for resources such as templates and static files.

    3. We then use the route() decorator to tell Flask what URL should trigger our function.

    4. The function returns the message we want to display in the user’s browser. The default content type is HTML, so HTML in the string will be rendered by the browser.

    Save it as hello.py or something similar. Make sure to not call your application flask.py because this would conflict with Flask itself.

    To run the application, use the flask command or python -m flask. You need to tell the Flask where your application is with the --app option.

    $ flask --app hello run
     * Serving Flask app 'hello'
     * Running on http://127.0.0.1:5000 (Press CTRL+C to quit)
    

    Externally Visible Server

    If you run the server you will notice that the server is only accessible from your own computer, not from any other in the network. This is the default because in debugging mode a user of the application can execute arbitrary Python code on your computer.

    If you have the debugger disabled or trust the users on your network, you can make the server publicly available simply by adding --host=0.0.0.0 to the command line:

    $ flask run --host=0.0.0.0
    

    This tells your operating system to listen on all public IPs.

    Debug

    To enable debug mode, use the --debug option.

    $ flask --app hello run --debug
     * Serving Flask app 'hello'
     * Debug mode: on
     * Running on http://127.0.0.1:5000 (Press CTRL+C to quit)
     * Restarting with stat
     * Debugger is active!
     * Debugger PIN: nnn-nnn-nnn
    

    Routing

    Modern web applications use meaningful URLs to help users. Users are more likely to like a page and come back if the page uses a meaningful URL they can remember and use to directly visit a page.

    Use the route() decorator to bind a function to a URL.

    @app.route('/')
    def index():
        return 'Index Page'
    
    @app.route('/hello')
    def hello():
        return 'Hello, World'
    

    HTTP Methods

    Web applications use different HTTP methods when accessing URLs. You should familiarize yourself with the HTTP methods as you work with Flask. By default, a route only answers to GET requests. You can use the methods argument of the route() decorator to handle different HTTP methods.

    from flask import request
    
    @app.route('/login', methods=['GET', 'POST'])
    def login():
        if request.method == 'POST':
            return do_the_login()
        else:
            return show_the_login_form()
    

    The Request Object

    The request object is documented in the API section and we will not cover it here in detail (see Request). Here is a broad overview of some of the most common operations. First of all you have to import it from the flask module:

    from flask import request
    

    The current request method is available by using the method attribute. To access form data (data transmitted in a POST or PUT request) you can use the form attribute. Here is a full example of the two attributes mentioned above:

    @app.route('/login', methods=['POST', 'GET'])
    def login():
        error = None
        if request.method == 'POST':
            if valid_login(request.form['username'],
                           request.form['password']):
                return log_the_user_in(request.form['username'])
            else:
                error = 'Invalid username/password'
        # the code below is executed if the request method
        # was GET or the credentials were invalid
        return render_template('login.html', error=error)
    
  • 开发记录
  • Flask