分类 编程 下的文章

基于远程仓库创建新分支
git branch branch_name remote_name/branch

基于远程仓库创建新分支并且切换到新分支
git checkout -b branch_name remote_name/branch

获取上次提交hash
git rev-parse HEAD --short

一不小心把文件和目录权限弄错了,想恢复回原有的样子,只需要执行一条命令即可恢复:

find folder '(' -type f -exec chmod 644 {} ';' ')' -o '(' -type d -exec chmod 755 {} ';' ')'

这条命令其实是两条命令合成的:

find folder -type d -exec chmod 755 {} \;
find folder -type f -exec chmod 644 {} \;

-o means OR. This command processes all objects in the project tree that are of type “file” or type “directory”, and executes different commands based on which type each object is.

You can make this slightly more efficient by replacing the semicolons (';') with plus signs (+); this tells find to run chmod 644 once, with all the plain files’ names as arguments, and to run chmod 755 once, with all the directories’ names as arguments.

查看原文

Manually remove

First, reboot your System to be sure it is using the latest kernel. Then open terminal and check your current kernel:

uname -r

DO NOT REMOVE THIS KERNEL!

Next, type the command below to view/list all installed kernels on your system.

dpkg --list | grep linux-image

Find all the kernels that lower than your current kernel. When you know which kernel to remove, continue below to remove it. Run the commands below to remove the kernel you selected.

sudo apt-get purge linux-image-x.x.x-x-generic

Finally, run the commands below to update grub2

sudo update-grub2

Reboot your system.

All-in-one command

All-in-one version to remove images and headers (combines the two versions above):

echo $(dpkg --list | grep linux-image | awk '{ print $2 }' | sort -V | sed -n '/'`uname -r`'/q;p') $(dpkg --list | grep linux-headers | awk '{ print $2 }' | sort -V | sed -n '/'"$(uname -r | sed "s/\([0-9.-]*\)-\([^0-9]\+\)/\1/")"'/q;p') | xargs sudo apt-get -y purge

Question: How do I remove old kernel versions to clean up the boot menu?

字体特性

  • 无论相似的特征是区分的,比如 0O1lI
  • 字体样式(线宽,字符宽度/高度)是否易于阅读
  • 安装方式
  • 分辨率支持
  • 是否开源、收费

流行字体列表

1. Input

Input 是一个灵活的字体系统,由 David Jonathan Ross 专门为代码设计。提供等宽字体和比例字体,所有字体都具有宽度,粗细和样式,以实现更丰富的代码格式。

  • 灵活配置
  • 有 Mono,Sans 和 Serif 两种款式
  • 明确区分相似的字符
  • 清晰的低分辨率和视网膜显示

2. Fira Code

Fira 是 Mozilla 主推的字体系列,Fira Code 是基于 Fira Mono 等宽字体的一个扩展,主要特点是加入了编程连字特性(ligatures)。

Fira Code 就是利用这个特性对编程中的常用符号进行优化,比如把输入的「!=」 直接显示成 「≠」 或者把 「>=」 变成 「≥ 」 等等,以此来提高代码的可读性。

  • 连字特性
  • 多种编辑器、IDE 支持
  • 支持视网膜显示
  • 经常更新
  • 开源免费
  • 提供 CSS

- 阅读剩余部分 -

Automatic Snapshots for Google (gcloud) Compute Engine

Bash script for Automatic Snapshots and Cleanup on Google Compute Engine. Requires no user input!

Inspiration (and the installation instructions) taken from AWS script aws-ec2-ebs-automatic-snapshot-bash

How it works

gcloud-snapshot.sh will:

  • Determine the Instance ID of the Google Compute Engine server on which the script runs
  • Get all the Disk IDs attached to that instance
  • Take a snapshot of each Disk
  • The script will then delete all associated snapshots taken by the script for the Instance that are older than 7 days (optional: default snapshot retention can be changed by using -d flag)

Prerequisites

  • cURL must be installed
  • The VM must have the sufficient gcloud permissions, including "compute" set to "enabled":

    [    http://stackoverflow.com/questions/31905966/gcloud-compute-list-networks-error-some-requests-did-not-succeed-insufficie#31928399](http://stackoverflow.com/questions/31905966/gcloud-compute-list-networks-error-some-requests-did-not-succeed-insufficie#31928399)
  • The version of gcloud is up to date: gcloud components update

Installation

ssh on to the server you wish to have backed up

Install Script: Download the latest version of the snapshot script and make it executable:

cd ~
wget https://raw.githubusercontent.com/jacksegal/google-compute-snapshot/master/gcloud-snapshot.sh
chmod +x gcloud-snapshot.sh
sudo mkdir -p /opt/google-compute-snapshot
sudo mv gcloud-snapshot.sh /opt/google-compute-snapshot/

To manually test the script:

sudo /opt/google-compute-snapshot/gcloud-snapshot.sh

Setup CRON: You should then setup a cron job in order to schedule a daily backup. Example cron for Debian based Linux:

0 5 * * * root /opt/google-compute-snapshot/gcloud-snapshot.sh >> /var/log/cron/snapshot.log 2>&1

Please note: the above command sends the output to a log file: /var/log/cron/snapshot.log - instructions for creating & managing the log file are below.

Manage CRON Output: You should then create a directory for all cron outputs and add it to logrotate:

  • Create new directory:
sudo mkdir /var/log/cron 
  • Create empty file for snapshot log:
sudo touch /var/log/cron/snapshot.log
  • Change permissions on file:
sudo chgrp adm /var/log/cron/snapshot.log
sudo chmod 664 /var/log/cron/snapshot.log
  • Create new entry in logrotate so cron files don't get too big :
sudo nano /etc/logrotate.d/cron
  • Add the following text to the above file:
/var/log/cron/*.log {
    daily
    missingok
    rotate 14
    compress
    notifempty
    create 664 root adm
    sharedscripts
}

Snapshot Retention

By default snapshots will be kept for 7 days, however they can be kept for longer / shorter, by using the the -d flag:

Usage: ./snapshot.sh [-d <days>]

Options:

   -d  Number of days to keep snapshots. Snapshots older than this number deleted.
       Default if not set: 7 [OPTIONAL]

Q: 如何限制 php 访问其他目录

open_basedir 设置能将 PHP 所能打开的文件限制在指定的目录树,包括文件本身。

当一个脚本试图用例如 fopen() 或者 gzopen() 打开一个文件时,该文件的位置将被检查。当文件在指定的目录树之外时 PHP 将拒绝打开它。

; open_basedir, if set, limits all file operations to the defined
directory ; and below. This directive makes most sense if used in a
per-directory ; or per-virtualhost web server configuration file. ;
http://php.net/open-basedir ;open_basedir =

Q: 如何在 Nginx 对站点配置:

location ~ \.php$ {
  fastcgi_pass   127.0.0.1:9000;
  fastcgi_index  index.php;
  fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
  fastcgi_param  PHP_VALUE "open_basedir=/srv:/tmp";
  include        fastcgi_params;
}