Long Luo's Life Notes

每一天都是奇迹

相信未来 食指

当蜘蛛网无情地查封了我的炉台, 当灰烬的余烟叹息着贫困的悲哀, 我依然固执地铺平失望的灰烬, 用美丽的雪花写下:相信未来。

当我的紫葡萄化为深秋的露水, 当我的鲜花依偎在别人的情怀, 我依然固执地用凝霜的枯藤, 在凄凉的大地上写下:相信未来。

我要用手指那涌向天边的排浪, 我要用手撑那托起太阳的大海, 摇曳着曙光那支温暖漂亮的笔杆, 用孩子的笔体写下:相信未来。

我之所以坚定地相信未来, 是我相信未来人们的眼睛—— 她有拨开历史风尘的睫毛, 她有看透岁月篇章的瞳孔。

不管人们对于我们腐烂的皮肉, 那些迷途的惆怅,失败的苦痛, 是寄予感动的热泪,深切的同情, 还是给以轻蔑的微笑,辛辣的嘲讽。

我坚信人们对于我们的脊骨, 那无数次地探索、迷途、失败和成功, 一定会给予热情、客观、公正的评定, 是的,我焦急地等待着他们的评定。

朋友,坚定地相信未来吧, 相信不屈不挠的努力, 相信战胜死亡的年轻, 相信未来,热爱生命。

By Long Luo

CONFIGURING GIT

git config –global user.name “[name]” Set the name that will be associated with your commits

git config -global user.email “[email]” Set the email that will be associated with your commits

git config -global alias.[alias] [command] Create a shortcut for a Git command (e.g. alias.glog “log —graph —oneline”)

git config -global core.editor [editor] Set the default text editor to use for commit messages (e.g. vi)

git config -global —edit Open the global config file in a text editor for manual editing

INITIALIZING AND CLONING

git init Initialize an empty Git repository in the current directory

git init [directory] Create an empty Git repo in the specified directory

git clone [url] Clone a remote Git repository from the url into a local directory

git clone [url] [directory] Clone a remote repo into the specified local directory

EXAMINING LOGS

git log Show the commit history for the current branch

git log -p Show the diffs from each commit in the commit history

git log —stat Show stats (files changed, insertions,deletions) for each commit

git log —oneline Show condensed summary of commits in one line each

git log —graph —decorate Draw a text based graph of commits with branch names

git diff Show unstaged file differences compared to current index

git diff -cached Show differences between staged changes and the last commit

git diff [commitl] [commit2] Show changes between two commits

git show [commit] Show changes made in the specified commit

VERSIONING FILES

git add [file] Stage file changes to be committed

git commit -m “[message]” Commit the staged snapshot with commit message

git rm [file] Remove file from staging index and working directory

git mv [file] [newpath] Move or rename file in Git and stage the change

BRANCHING AND MERGING

git branch List all the branches in the current repository

git branch [branch] Create a new branch with name [branch]

git checkout [branch] Switch the current branch to [branch]

git checkout -b [branch] Create a new branch and switch to it

git merge [branch] Merge the history of [branch] into the current branch

git branch -d [branch] Delete the local branch [branch]

RETRIEVING AND UPDATING REPOSITORIES

git fetch [remote] Fetch branches and commits from the remote repository

git pull [remote] Fetch remote changes and directly merge into local repository

git pull —rebase [remote] Fetch remote changes and rebase onto local branch

git push [remote] [branch] Push local branch to remote repository

git push –all [remote] Push all local branches to remote

git push —tags [remote] Push all local tags to remote repository

REWRITING GIT HISTORY

git rebase [branch] Rebase current branch onto [branch]

git rebase -i [commit] Interactively rebase current branch onto [commit]

git reflog Show history of Git commands for current repository

git reset —hard [commit] clear staging area, rewrite working tree from specified commit

REMOTE REPOSITORIES

git remote add [name] [url] Create remote connection with url and alias [name]

git fetch [remote] Fetch all branches from remote repository

git pull [remote] Fetch remote changes and merge into local repository

git push [remote] [branch] Push local branch to remote repository

UNDOING CHANGES

git reset [file] Remove file from staging index but leave unchanged locally

git clean -n Shows which files would be removed from working directory. Use -f option to execute clean.

git revert [commit] Undo changes from specified commit by creating a new commit

$ git add .

$ git add -u .

git reset是指将当前head的内容重置,不会留log信息。

git reset HEAD filename 从暂存区中移除文件

git reset –hard HEAD~3 会将最新的3次提交全部重置,就像没有提交过一样。

git reset –hard commit (38679ed709fd0a3767b79b93d0fba5bb8dd235f8) 回退到 38679ed709fd0a3767b79b93d0fba5bb8dd235f8 版本

根据–soft –mixed –hard,会对working tree和index和HEAD进行重置:

git reset –mixed:此为默认方式,不带任何参数的git reset,即时这种方式,它回退到某个版本,只保留源码,回退commit和index信息 git reset –soft:回退到某个版本,只回退了commit的信息,不会恢复到index file一级。如果还要提交,直接commit即可 git reset –hard:彻底回退到某个版本,本地的源码也会变为上一个版本的内容

git 放弃本地修改 强制更新

git fetch –all

git reset –hard origin/master

git fetch 只是下载远程的库的内容,不做任何的合并 git reset 把HEAD指向刚刚下载的最新的版本

git新手。本地做了一些修改,我用git rebase说有冲突。我现在想把本地的请求都干掉,可能有的已经commit过了(没有push过),完全同步成远程版本,应该用什么命令?

使用命令:

git reset –hard ORIGIN/BRANCH

比如master分支:

git reset –hard origin/master

Git

Git dojo

https://www.shortcutfoo.com/

Try Git

https://try.github.io/levels/1/challenges/1

LearnGitBranching

http://learngitbranching.js.org/

查看所有远程分支:

git branch -r

拉取远程分支并创建本地分支

git checkout -b 本地分支名x origin/远程分支名x

使用该方式会在本地新建分支x,并自动切换到该本地分支x。

采用此种方法建立的本地分支会和远程分支建立映射关系。

使用如下命令:

git fetch origin 远程分支名x:本地分支名x

使用该方式会在本地新建分支x,但是不会自动切换到该本地分支x,需要手动 checkout。

采用此种方法建立的本地分支不会和远程分支建立映射关系。

三、本地分支和远程分支建立映射关系的作用

git branch –set-upstream-to origin/远程分支名 本地分支名

切换分支

git checkout 本地分支名

合并分支

git merge 本地分支名称

参考文献

Git

By Long Luo

本站目前采用 Hexo 作为后台系统,托管在Github上。此前我曾在很多地方安过家,最开始新浪和QQ空间上写过博客,后来到网易博客,再后来看到程序员都有自己的个人网站,于是2014年也新建了一个人网站,当时是买了域名和一个VPS,使用的LNMP架构。

在使用了流行的WordPress两年后看到码农的乐土,Jekyll ,一个以纯静态文件的博客系统。但后来我发现Jekyll实在太慢,而且美观度也不够,于是投奔了在Hexo

LNMP (Linux + Nginx + MySQL + PHP)

Ubuntu 20.04

使用Nginx官方源安装Nginx。

Nginx安装前必要环境。

sudo apt install -y curl gnupg2 ca-certificates lsb-release ubuntu-keyring

导入官方nginx签名密钥。

curl https://nginx.org/keys/nginx_signing.key | gpg –dearmor | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null

设置apt仓库。

echo “deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/ubuntu lsb_release -cs nginx” | sudo tee /etc/apt/sources.list.d/nginx.list

更新软件包列表并安装nginx。

说明 默认安装最新稳定版本Nginx,如果对版本有要求可以使用sudo apt list -a nginx搜索支持的Nginx版本并将安装命令替换为具体版本(例:安装1.22.1-1~focal版本,修改命令为sudo apt install -y nginx=1.22.1-1~focal)。

sudo apt update -y && sudo apt install -y nginx

安装MySQL数据库并设置密码。

更新软件包列表并安装MySQL服务器。

sudo apt update -y && sudo apt install -y mysql-server

将MySQL的配置文件中监听地址从127.0.0.1(即只监听本地连接)更改为0.0.0.0(即监听所有可用网络接口),从而允许远程连接到MySQL服务器。

sudo sed -i “s/127.0.0.1/0.0.0.0/” /etc/mysql/mysql.conf.d/mysqld.cnf

修改数据库root用户主机部分从localhost更改为%以允许从任何地址连接,同时修改root用户的密码和身份认证插件。您需要将命令中替换为您的密码。

重要 由于本地root用户的默认身份认证插件是auth_socket,如果命令执行后提示输入密码,请直接按回车跳过。

sudo mysql -uroot -p -e “ALTER USER ‘root’@‘localhost’ IDENTIFIED WITH caching_sha2_password BY ‘’;” -e “UPDATE mysql.user SET Host=‘%’ WHERE User=‘root’ AND Host=‘localhost’;” -e “FLUSH PRIVILEGES;”

重启MySQL数据库服务使配置生效。

sudo systemctl restart mysql

安装PHP。

更新软件包,安装software-properties-common包,并添加PPA仓库ppa:ondrej/php。

sudo apt update && sudo apt install -y software-properties-common && sudo add-apt-repository -y ppa:ondrej/php

安装PHP8.4及相关组件,包括FPM和MySQL扩展。

说明 您可以通过sudo apt search php查看所有支持安装的PHP版本,安装其他版本需要修改命令中对应版本号(例:安装PHP8.1需修改命令sudo apt install -y php8.1 php8.1-fpm php8.1-mysql)。

sudo apt install -y php8.4 php8.4-fpm php8.4-mysql

验证LNMP环境。

查询php-fpm配置文件默认监听地址,需要替换为您的PHP版本(例:PHP8.4需要将替换为8.4)。

sudo grep ‘^listen =’ /etc/php//fpm/pool.d/www.conf

sudo grep ‘^listen =’ /etc/php/8.4/fpm/pool.d/www.conf

如果返回sock文件地址说明默认监听sock文件。

如果返回127.0.0.1:9000说明默认监听本地9000端口。

listen = /run/php/php8.4-fpm.sock

编辑 /etc/nginx/conf.d/default.conf 文件,在server内填写PHP转发规则,需要替换为您的监听地址(如果是sock文件需要在地址前方增加unix:)。

重要 如果监听的sock文件,需要sock文件的权限设置为允许读写,您可以使用以下命令来更改权限sudo chmod 666 更改为您的sock文件地址。

location / { index index.php index.html index.htm; } location ~ .php$ { root /usr/share/nginx/html; fastcgi_pass ; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME \(document_root\)fastcgi_script_name; include fastcgi_params; }

location / { index index.php index.html index.htm; } location ~ .php$ { root /usr/share/nginx/html; fastcgi_pass unix:/run/php/php8.4-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME \(document_root\)fastcgi_script_name; include fastcgi_params; }

重启Nginx服务使修改后的配置文件生效。

sudo systemctl restart nginx

远程访问MySQL数据库

运行以下命令后,输入root用户的密码登录MySQL。

sudo mysql -uroot -p

依次运行以下命令,创建远程登录MySQL的账号,并允许远程主机使用该账号访问MySQL。

本示例账号为dmsTest、密码为Ecs@123****。

实际创建账号时,需将示例密码Ecs@123

更换为符合要求的密码,并妥善保存。密码要求:长度为8至30个字符,必须同时包含大小写英文字母、数字和特殊符号。可以使用以下特殊符号:

()` ~!@#$%^&*-+=|{}[]:;’<>,.?/

创建数据库用户dmsTest,并授予远程连接权限。

create user ‘frank’@‘%’ identified by ‘wp291563pd’;

为dmsTest用户授权数据库所有权限。

grant all privileges on . to ‘frank’@‘%’;

刷新权限。

flush privileges;

运行以下命令,为WordPress网站创建一个名称为wordpress的数据库。

create database wordpress;

create user ‘wpuser’@‘localhost’ identified by ‘25789pwdb’;

cd /usr/share/nginx/html

sudo wget https://cn.wordpress.org/latest-zh_CN.zip

启动nginx服务

sudo systemctl enable nginx sudo systemctl start nginx

enable:设置 Nginx 服务在系统启动时自动启动。 start:立即启动 Nginx 服务。

Nginx服务是否启动成功

sudo systemctl status nginx

status:查看 Nginx 服务的状态。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
● nginx.service - nginx - high performance web server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2025-01-03 19:25:38 CST; 1h 47min ago
Docs: https://nginx.org/en/docs/
Main PID: 2658 (nginx)
Tasks: 3 (limit: 1930)
Memory: 3.3M
CPU: 14ms
CGroup: /system.slice/nginx.service
├─2658 "nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf"
├─2659 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
└─2660 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""

Jan 03 19:25:38 iZwz9bi9yxqor74jqvhsr1Z systemd[1]: Starting nginx - high performance web server...
Jan 03 19:25:38 iZwz9bi9yxqor74jqvhsr1Z systemd[1]: Started nginx - high performance web server.

3 当修改了配置的时候,需要重启nginx,使配置生效的时候使用一下命令:

sudo systemctl reload nginx

  1. Nginx的配置文件存放的位置?

在Ubuntu环境中,Nginx的存放位置在以下目录中:

mysql -u wpuser -p -h localhost wordpress

Jekyll

$ git –version git version 1.7.1

$ ssh-keygen -t rsa -C “youremail@example.com”

id_rsa.pub

ssh -t git@github.com

$ git config –global user.name “Your Name” $ git config –global user.email “email@example.com”

1
2
3
4
5
6
7
The authenticity of host 'github.com (192.30.253.112)' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,192.30.253.112' (RSA) to the list of known hosts.
PTY allocation request failed on channel 0
Hi longluo! You've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.

修改SSH密码。登录ssh后, 通过passwd命令修改即可,命令格式:

1
passwd {用户名}

出现:(current) UNIX password: 然后输入当前系统登陆用户的密码 回车 出现:New password: 再输入新密码(新的密码必须是字母数字都有,不然的话不成功)

Hexo

参考文献

  1. 手动部署LNMP环境
  2. 在Linux实例中安装MySQL数据库
  3. 手动搭建WordPress(Linux)

By Long Luo

继第一篇 Android自定义View:如何实现一个模拟时钟? ,我们使用Android自定义View实现了一款模拟表盘,第二篇 Android自定义View:另一种实现手表指针转动的方法 ,我们又通过另外一种方法实现了手表指针的另外一种转动实现。

在日程生活中,我们常见的挂钟实际都是有个钟摆的,那么,如果我们想在我们所作的模拟时钟实现这种钟摆动画呢?那么具体应该如何实现呢?

一、钟摆

遇到问题,我们需要先分析钟摆动画的具体动画效果,然后再做下一步工作。

单摆是能够产生往复摆动的一种装置,将无重细杆或不可伸长的细柔绳一端悬于重力场内一定点,另一端固结一个重小球,就构成单摆

那么钟摆就是在一定角度内来回摆动,具体更多细节可以自行Google。

二、Android Animation分析

在这一节里,我们会简单谈谈Android动画。

2.1 动画分类

Android动画目前可分为以下3种:

2.1.1 补间动画(Tween Animation)

所谓的补间动画,其实就是定义了我们动画的起始点和终止点的状态,而动画的过程我们是不关心的,只需要达到我们想要的效果就行。

  1. 渐变动画支持四种类型:平移(Translate)、旋转(Rotate)、缩放(Scale)、不透明度(Alpha)
  2. 只是显示的位置变动,View的实际位置未改变,表现为View移动到其他地方,点击事件仍在原处才能响应
  3. 组合使用步骤较复杂。
  4. View Animation也是指此动画

对于补间动画来说,无论是用纯java代码构建Animation对象,还是通过xml文件定义Animation,其实最终的结果都是

1
2
3
4
Animation a = new AlphaAnimation();
Animation b = new ScaleAnimation();
Animation c = new RotateAnimation();
Animation d = new TranslateAnimation();

2.1.2 帧动画(Frame Animation)

所谓的帧动画就是可以设置我们的动画的每一帧的效果,其实视频或者Gif的效果都是由许多张图片在很短的时间内播放,从而产生动画效果。

  1. 用于生成连续的Gif效果图。
  2. DrawableAnimation也是指此动画。

2.1.3 属性动画(Property Animation)

属性动画是Android动画里面最复杂也是最能做出复杂的动画效果的一种类型。

  1. 支持对所有View能更新的属性的动画(需要属性的setXxx()和getXxx())。
  2. 更改的是View实际的属性,所以不会影响其在动画执行后所在位置的正常使用。
  3. Android3.0(API 11)及以后出现的功能,3.0之前的版本可使用github第三方开源库nineoldandroids.jar进行支持。

属性动画的相关的API:

  • ValueAnimator:值动画执行类,常配合AnimatorUpdateListener使用。
  • ObjectAnimator:对象动画执行类。
  • PropertyValuesHolder: 属性存储器,为两个执行类提供更新多个属性的功能。
  • AnimatorListener:动画执行监听,在动画开始、重复、结束、取消时进行回调。
  • Keyframe:为PropertyValuesHolder提供多个关键帧的操作值。
  • AnimatorSet:一组动画的执行集合类:设置执行的先后顺序,时间等。
  • TimeInterpolator:时间插值,用于控制动画执行过程。
  • AnimatorUpdateListener:动画更新监听。
  • TypeEvaluator:类型估值,用于设置复杂的动画操作属性的值。

ValueAnimator和ObjectAnimator是属性动画里面经常使用的对象类,ObjectAnimator是 ValueAnimator的子类。

当然Android属性动画是很复杂,达到熟练运用还需要深入研究,大家想了解可以去网上寻找相关知识学习。

阅读全文 »

By Long Luo

— 井中月 —

仿《繁星·春水》

1
2
3
4
5
6
7

水井啊

只要你的内心有哪怕那么一点点波澜

就不能拥有美丽的月亮了

*** Long Luo at 2016-8-22 23:24:49 @Shenzhen.***

0%