谷歌云安装图形界面一键脚本

Chrome 远程桌面还支持 Windows 系统, 不限于 linux 系统,可从本地计算机或移动设备使用图形界面远程访问应用。按照以下过程使用自定义启动脚本来自动执行此过程。
复制以下 Shell 脚本并将其粘贴到自动化/启动脚本文本框中:

#!/bin/bash -x
#
# Startup script to install Chrome remote desktop and a desktop environment.
#
# See environmental variables at then end of the script for configuration
#

function install_desktop_env {
  PACKAGES="desktop-base xscreensaver"

  if [[ "$INSTALL_XFCE" != "yes" && "$INSTALL_CINNAMON" != "yes" ]] ; then
    # neither XFCE nor cinnamon specified; install both
    INSTALL_XFCE=yes
    INSTALL_CINNAMON=yes
  fi

  if [[ "$INSTALL_XFCE" = "yes" ]] ; then
    PACKAGES="$PACKAGES xfce4"
    echo "exec xfce4-session" > /etc/chrome-remote-desktop-session
    [[ "$INSTALL_FULL_DESKTOP" = "yes" ]] && \
      PACKAGES="$PACKAGES task-xfce-desktop"
  fi

  if [[ "$INSTALL_CINNAMON" = "yes" ]] ; then
    PACKAGES="$PACKAGES cinnamon-core"
    echo "exec cinnamon-session-cinnamon2d" > /etc/chrome-remote-desktop-session
    [[ "$INSTALL_FULL_DESKTOP" = "yes" ]] && \
      PACKAGES="$PACKAGES task-cinnamon-desktop"
  fi

  DEBIAN_FRONTEND=noninteractive \
    apt-get install --assume-yes $PACKAGES $EXTRA_PACKAGES

  systemctl disable lightdm.service
}

function download_and_install { # args URL FILENAME
  curl -L -o "$2" "$1"
  dpkg --install "$2"
  apt-get install --assume-yes --fix-broken
}

function is_installed {  # args PACKAGE_NAME
  dpkg-query --list "$1" | grep -q "^ii" 2>/dev/null
  return $?
}

# Configure the following environmental variables as required:
INSTALL_XFCE=yes
INSTALL_CINNAMON=yes
INSTALL_CHROME=yes
INSTALL_FULL_DESKTOP=yes

# Any additional packages that should be installed on startup can be added here
EXTRA_PACKAGES="less bzip2 zip unzip"

apt-get update

! is_installed chrome-remote-desktop && \
  download_and_install \
    https://dl.google.com/linux/direct/chrome-remote-desktop_current_amd64.deb \
    /tmp/chrome-remote-desktop_current_amd64.deb

install_desktop_env

[[ "$INSTALL_CHROME" = "yes" ]] && \
  ! is_installed google-chrome-stable && \
  download_and_install \
    https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb \
    /tmp/google-chrome-stable_current_amd64.deb

echo "Chrome remote desktop installation completed"

每次重新启动机器时,此脚本都将执行以下任务:

  • 如果未安装远程桌面软件包:
    • 下载并安装 Chrome 远程桌面软件包。
    • 安装必需的软件包。
  • 安装 Xfce 或 Cinnamon 桌面环境(具体取决于脚本设置)。
  • 如果已启用完整桌面环境选项,请安装必要的软件包。
  • 如果已启用但未安装 Chrome 浏览器选项,请执行以下操作:
    • 下载并安装 Chrome 远程桌面软件包。
    • 安装必需的软件包。

监控进度,请使用 SSH 连接到虚拟机实例,并在实例的终端中运行以下命令:

sudo journalctl -o cat -f _SYSTEMD_UNIT=google-startup-scripts.service

//此命令显示启动脚本的输出。脚本完成后,您将看到以下内容:
INFO startup-script: Chrome remote desktop installation completed
INFO startup-script: Return code 0.
INFO Finished running startup scripts.

Debian安装图形界面

#环境 Linux 4.9.0-12-amd64 #1 SMP Debian 4.9.210-1 (2020-01-20) x86_64

#安装gnome图形相关软件
apt install x-window-system-core gnome-core  

#设置系统为图形界面启动,该命令执行后系统会重启
init 6 

#===设置系统可以root登录===

#修改/etc/gdm3/daemon.conf文件
vi /etc/gdm3/daemon.conf
#在[security]下增加一行AllowRoot = true

#修改/etc/pam.d/gdm-password文件
vi /etc/pam.d/gdm-password

#注释掉auth required pam_succeed_if.so user != root quiet_success

#重启系统后,即可使用root登录。

Chrome浏览器 net::ERR_BLOCKED_BY_CLIENT

问题:
维护网站发现上传到图床上的图片不显示,获取不到资源

GET https://xx.fankuiba.com/ad/screenshot.png net::ERR_BLOCKED_BY_CLIENT


很困惑,用手机Safari打开页面显示的是缓存,一时竟没反应过来是被广告拦截插件(uBlock Origin)给拦截了,折腾一番后用Firefox打开屁事儿没有

解决:
文件夹ad改成其他😢😢

WordPress文章日期批量随机修改

此方法对做WordPress批量采集的、发文章时间不符合实际的站点,例如文章状态为“草稿”很久了,原计划发布时间是上个月,结果这个月才完稿发布,类似情况很有帮助,省去一个个修改的烦恼。这是在网上找到的两段SQL语句,存在瑕疵:

//时间格式不对
UPDATE `wp_posts` SET `post_date` = DATE_ADD('2010-1-01', INTERVAL ROUND(RAND() * 3890+ 1) DAY) WHERE `ID` between 1 AND 100000;
update `wp_posts` set `post_modified` = `post_date` WHERE `ID` between 1 AND 100000;
update `wp_posts` set `post_date_gmt` = `post_date` WHERE `ID` between 1 AND 100000;
update `wp_posts` set `post_modified_gmt` = `post_modified` WHERE `ID` between 1 AND 100000;
update `wp_posts` set `post_status` = 'publish' WHERE `ID` between 1 AND 100000;

//时间格式不对
UPDATE `wp_posts` SET `post_date` = DATE_ADD('2018-1-10', INTERVAL ROUND(RAND() * 220 + 1) DAY)  WHERE `ID` between 1 AND 1215;
update `wp_posts` set `post_modified` = `post_date` WHERE `ID` between 1 AND 1215;
update `wp_posts` set `post_date_gmt` = `post_date` WHERE `ID` between 1 AND 1215;
update `wp_posts` set `post_modified_gmt` = `post_modified` WHERE `ID` between 1 AND 1215;
update `wp_posts` set `post_status` = 'publish' WHERE `ID` between 1 AND 1215;


起始时间 “2020-01-01”
随机日期范围 “180 天”
文章ID起始范围 “1 – 2000”
任意修改,然后依次执行以下SQL语句,每个分号是一句,一句一句执行,可以在指定的文章ID范围内,随机生成文章的发布日期,替换原来的日期。

//完美
UPDATE `wp_posts` SET `post_date` = DATE_ADD('2020-01-01', INTERVAL ROUND(RAND() * 180 + 1) DAY)  WHERE `ID` between 1 AND 2000;
update `wp_posts` set `post_modified` = `post_date` WHERE `ID` between 1 AND 2000;
update `wp_posts` set `post_date_gmt` = `post_date` WHERE `ID` between 1 AND 2000;
update `wp_posts` set `post_modified_gmt` = `post_modified` WHERE `ID` between 1 AND 2000;
update `wp_posts` set `post_status` = 'publish' WHERE `ID` between 1 AND 2000;


字段含义:
post_date(文章发布日期)
post_date_gmt(文章发布日期,格林威治时间)
post_modified(文章修改时间)
post_modified_gmt(文章修改时间,格林威治时间)
post_status(文章状态)
如果安装WordPress的时候数据库表前缀wp有修改过,记得做相应更改。

win10删除文件卡在99%

删除文件时还好,卡在99%进度大约1分钟时间,剪切/移动文件就悲剧了,一直卡
解决方法:
以管理员身份运行“命令提示符”

粘贴以下命令并执行如下
dism /online /Cleanup-Image /RestoreHealth & sfc /SCANNOW & pause

修复成功,但还在卡,只能到任务管理器中重启Windows 资源管理器+关闭Windows Search了,我执行的是移动文件操作,如果强行关闭对话框可能有丢文件的风险,经过测试修复后重启系统问题不再出现,刚才移动的文件也是完整的。

第七章第五题(打印不同的教)(Print distinct numbers) – 编程练习题答案

编写一个程序,读人10 个数并且显示互不相同的数(即一个数出现多次,但仅显示一次)。(提示,读人一个数,如果它是一个新数,则将它存储在数组中。如果该数已经在数组中,则忽略它。)输入之后,数组包含的都是不同的数。下面是这个程序的运行示例:

Write a program that reads in ten numbers and displays
the number of distinct numbers and the distinct numbers separated by exactly one
space (i.e., if a number appears multiple times, it is displayed only once). (Hint:
Read a number and store it to an array if it is new. If the number is already in the
array, ignore it.) After the input, the array contains the distinct numbers.

下面是参考答案代码:

// 缺陷版本
import java.util.Arrays;
import java.util.Scanner;

public class Ans7_5_page236 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.print("Enter ten numbers: ");
        int[] numberList = new int[10];
        // int[] distinctList = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
        int[] distinctList = new int[10];
        Arrays.fill(distinctList,-1);

        for (int i = 0; i < 10; i++)
            numberList[i] = input.nextInt();

        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 10;j++) {
                if (i == numberList[j])
                    distinctList[i] = numberList[j];
            }
        }

        int count = 0;
        for (int i = 0; i < 10; i++) {
            if (distinctList[i] != -1)
                count++;
        }
        System.out.print("The number of distinct number is " + count+
                "\nThe distinct numbers are: ");

        for (int i = 0; i < 10; i++) {
            if (distinctList[i] != -1) {
                System.out.print(distinctList[i] + " ");
            }
        }
    }
}

// 完善版本
import java.util.Arrays;
import java.util.Scanner;

public class Ans7_5_page236 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.print("Enter ten numbers: ");
        int[] numberList = new int[10];

        int maxInt = -99;
        for (int i = 0; i < 10; i++) {
            numberList[i] = input.nextInt();
            if (numberList[i] > maxInt)
                maxInt = numberList[i];
        }

        int[] distinctList = new int[maxInt];
        Arrays.fill(distinctList, -99);

        int disNum = 0;
        for (int i = 0; i < maxInt; i++) {
            for (int j = 0; j < 10; j++) {
                if (i == numberList[j])
                    distinctList[i] = numberList[j];
                else if (distinctList[i] != -99)
                    disNum = distinctList[i];
            }
        }

        int count = 0;
        for (int i = 0; i < maxInt; i++) {
            if (distinctList[i] != -99) {
                count++;
            }
        }
        System.out.print("The number of distinct number is " + disNum +
                "\nThe distinct numbers are: ");

        for (int i = 0; i < maxInt; i++) {
            if (distinctList[i] != -99) {
                System.out.print(distinctList[i] + " ");
            }
        }
        System.out.print(maxInt);
    }
}

//        Enter ten numbers: 1 2 3 2 1 6 3 4 5 2
//        The number of distinct number is 5
//        The distinct numbers are: 1 2 3 4 5 6

//        Enter ten numbers: 11 22 33 22 11 66 33 44 55 67
//        The number of distinct number is 66
//        The distinct numbers are: 11 22 33 44 55 66 67

适用Java语言程序设计与数据结构(基础篇)(原书第11版)Java语言程序设计(基础篇)(原书第10/11版)

发布在博客:(https://cn.fankuiba.com)

第七章第四题(分析成绩)(Analyze scores) – 编程练习题答案

编写一个程序,读人个数不确定的考试分数,并且判断有多少个分数是大于或等于平均分,多少个分数是低于平均分的。输人一个负数表示输入的结束。假设最高分为100。

Write a program that reads an unspecified number of scores and
determines how many scores are above or equal to the average and how many
scores are below the average. Enter a negative number to signify the end of the
input. Assume that the maximum number of scores is 100.

下面是参考答案代码:

// https://cn.fankuiba.com
import java.util.Scanner;

public class Ans7_4_page236 {
    public static void main(String[] args) {
        double[] scoreList = new double[100];
        Scanner input = new Scanner(System.in);
        System.out.print("Enter scores: (negative number signifies end): ");
        int count= 0;double score;
        do {
            score = input.nextDouble();
            scoreList[count] = score;
            count++;
        }while (score >= 0);

        double average,sum = 0;
        for (int i = 0; i < count-1; i++)
            sum += scoreList[i];

        average = sum / (count - 1);
        System.out.println("Average of scores: "+average);
        int minAverge = 0;
        int maxAverge = 0;
        for (int i = 0; i < count-1; i++) {
            if (scoreList[i] >= average)
                minAverge++;
            else
                maxAverge++;
        }
        System.out.println("Number of scores above or equal to average: " +minAverge+
                "\n"+"Number of scores below average: "+(maxAverge));
    }
}

适用Java语言程序设计与数据结构(基础篇)(原书第11版)Java语言程序设计(基础篇)(原书第10/11版)

发布在博客:(https://cn.fankuiba.com)

第七章第三题(计算数字的出现次数)(Count occurrence of numbers) – 编程练习题答案

编写程序,读取在1到100 之间的整数,然后计算每个数出现的次数。假定输入是以0 结束的。

下面是这个程序的一个运行示例:

Write a program that reads the integers between 1and 100 and counts the occurrences of each. Assume the input ends with 0.Note that if a number occurs more than one time, the plural word “times” is used

in the output.

Enter the integers between 1 and 100: 2 5 6 5 4 3 23 43 2 0
2 occurs 2 times
3 occurs 1 time
4 occurs 1 time
5 occurs 2 times
6 occurs 1 time
23 occurs 1 time
43 occurs 1 time

下面是参考答案代码:

// https://cn.fankuiba.com
import java.util.Scanner;

public class Ans7_3_page236 {
    public static void main(String[] args) {
        int[] number = new int [101];
        Scanner input = new Scanner(System.in);
        int num;
        System.out.print("Enter the integers between 1 and 100: ");
        do {
            num = input.nextInt();
            number[num] = number[num] + 1;
        }
        while (num != 0);
        for (int i = 1; i < number.length; i++) {
            if (number[i] == 1) {
                System.out.println(i + " occurs " + number[i] + " time");
            }else if (number[i] > 1)
                System.out.println(i + " occurs " + number[i] + " times");
        }
    }
}

适用Java语言程序设计与数据结构(基础篇)(原书第11版)Java语言程序设计(基础篇)(原书第10/11版)

发布在博客:(https://cn.fankuiba.com)

第七章第二题(倒置输入的数)(Reverse the numbers entered) – 编程练习题答案

编写程序,读取10 个整数,然后按照和读入顺序相反的顺序将它们显示出来。

Write a program that reads ten integers and displays
them in the reverse of the order in which they were read.

// https://cn.fankuiba.com
import java.util.Scanner;

public class Ans7_2_page236 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.print("Enter 10 integers: ");
        int[] number = new int[10];
        for (int i = 0; i < 10; i++) {
            number[i] = input.nextInt();
        }
        for (int i = 9; i >= 0; i--)
            System.out.print(number[i]+" ");
    }
}

适用Java语言程序设计与数据结构(基础篇)(原书第11版)Java语言程序设计(基础篇)(原书第10/11版)

发布在博客:(https://cn.fankuiba.com)

第七章第一题(指定等级)(Assign grades) – 编程练习题答案

(指定等级)编写一个程序,读入学生成绩,获取最髙分best, 然后根据下面的规则陚等级值

• 如果分数>=best-10, 等级为A

• 如果分数>=best-20, 等级为B

• 如果分数>=best-30, 等级为C

• 如果分数>=best-40, 等级为D

• 其他情况下,等级为F

程序提示用户输入学生总数,然后提示用户输入所有的分数,最后显示等级得出结论。下面

是一个运行示例:

Enter the number of students: 4
Enter 4 scores: 40 55 70 58
Student 0 score is 40 and grade is C
Student 1 score is 55 and grade is B
Student 2 score is 70 and grade is A
Student 3 score is 58 and grade is B

下面是参考答案代码:

// https://cn.fankuiba.com
import java.util.Arrays;
import java.util.Scanner;


public class Ans7_1_page235 {
    public static void main(String[] args) {
        String[] grade = {"A","B","C","D","F"};
        Scanner input = new Scanner(System.in);
        System.out.print("Enter the number of students: ");
        int number = input.nextInt();
        System.out.print("Enter " + number + " scores: ");

        int[] score = new int[number];
        for (int i = 0; i < number; i++)
            score[i] = input.nextInt();

        int[] scoreSort = new int[number];
        System.arraycopy(score,0,scoreSort,0,score.length);

        Arrays.sort(scoreSort);

        int maxSort = scoreSort[number-1];
        for (int i = 0; i < number; i++) {
            if (score[i] >= maxSort-10)
                System.out.println("Student " + i + " score is " + score[i] +
                        " and grade is " + grade[0]);
            else if (score[i] >= maxSort-20)
                System.out.println("Student " + i + " score is " + score[i] +
                        " and grade is " + grade[1]);
            else if (score[i] >= maxSort-30)
                System.out.println("Student " + i + " score is " + score[i] +
                        " and grade is " + grade[2]);
            else if (score[i] >= maxSort-40)
                System.out.println("Student " + i + " score is " + score[i] +
                        " and grade is " + grade[3]);
            else
                System.out.println("Student " + i + " score is " + score[i] +
                        " and grade is " + grade[4]);
        }
    }
}

适用Java语言程序设计与数据结构(基础篇)(原书第11版)Java语言程序设计(基础篇)(原书第10/11版)

发布在博客:(https://cn.fankuiba.com)