分类 编程 下的文章

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;
}

input.gif

函数防抖(debounce)

在事件被触发n秒后再执行回调,如果在这n秒内又被触发,则重新计时。

input-debounce.gif

函数节流(throttle)

规定在一个单位时间内,只能触发一次函数。如果这个单位时间内触发多次函数,只有一次生效。

input-throttle.gif

使用listbucket命令列举出需要复制的当前空间

qshell listbucket bucket_name bucket.txt

上步操作后会在当前目录下生成一个名为bucket.txt的list文件列表,格式如下:

photo1.jpg  109787  FvaTV7fZz6G_1W6WyzQdktMbqPuv    14526031733113853   image/jpeg
photo2.jpg  256148  Fq3vt4smenbZ_ev-iba2Yukx5d9B    14526031741765437   image/jpeg
photo3.jpg  194277  FtxVybqCmEm_ZWEJ6l2vg-qKbzWh    14526031747456153   image/jpeg
photo4.jpg  131862  FslN6hs8puP_ksS6KYCl0OxgcWoO    14526031770721477   image/jpeg

而我们只需要得到最前面的文件key就可以了,可以使用一条awk字符处理命令就可以了

cat bucket.txt | awk '{print $1}' >files.txt 

这样就在当前目录生成了一个如下只包含文件的key的txt文件files.txt

photo1.jpg
photo3.jpg
photo4.jpg
photo5.jpg

使用batchcopy命令将文件同步到需要复制的空间里面

qshell batchcopy bucket_1 bucket_2 files.txt

闭包的概念:为包含外部变量的函数及外部变量所创建的内存栈叫闭包
闭包的作用:通过函数调用的方式改变一个变量从而防止直接修改变量

Closures are created whenever a variable that is defined outside the
current scope is accessed from within some inner scope.



- 阅读剩余部分 -