0%

最近辦了新域名想說另外開個port來用密碼登入ssh
因為不想在預設port使用密碼登入
把步驟記錄一下,不過來源是stackorflow,所以算是翻譯(?
來源網址 : 2 sshd configurations 1 for internal and 1 external

  • 第一步 複製原本ssh server的設定檔

    1
    $ sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config_external
  • 第二步 複製原本 ssh server 的 service 腳本

    1
    $ sudo cp /lib/systemd/system/ssh.service /lib/systemd/system/sshd-external.service
    • 更改 /lib/systemd/system/sshd-external.service 檔案內容

      1
      2
      3
      ExecStart=/usr/sbin/sshd -D $SSHD_OPTS 
      改成
      ExecStart=/usr/sbin/sshd -D $SSHD_OPTS -f /etc/ssh/sshd_config_external
  • 第三步

    • 設定額外新的設定檔像是把port從22換到別的port

    • 要改的檔案 /etc/ssh/sshd_config_external

    • 改port的話

      1
      2
      3
      Port 22
      改成你想要的port
      Port 9999
    • 允許密碼登入

      1
      2
      3
      PasswordAuthentication no
      改成
      PasswordAuthentication yes
  • 第四步

    • 讓新的ssh server能夠在開機時自動啟動

      1
      $ sudo systemctl enable sshd-external.service
  • 第五步 啟動!!

    1
    $ sudo service sshd-external start
  • 這樣應該就可以連上去了

  • 對了,新開啟的port記得去開GCP的防火牆喔

本篇文章適用於已經用 crouton 裝好 ubutun ,且已經有 GUI 環境的開發者,如果還沒裝好可以去看我之前的教學文章。

點擊查看
  • 下載 android studio for linux

官方載點

  • 解壓縮 android studio

    Ctrl+Alt+Tab 後輸入 shell

    • 使用gui直接解壓縮

      1
      $ sudo startxfce4

      透過 Ctrl+Alt+Shift+Back 來切換畫面

      然後找到下載的地方右鍵解壓縮

    • 使用命令行解壓縮

      cd到你下載的地方,chrome OS 下應該是 Downloads

      1
      $ cd ~/Downloads/
      1
      $ unzip android-stusio-ide-*-linux-zip

      *字看狀況可以自行更換成下載對應的版本

  • 安裝 android studio

    • 使用gui安裝

      找到解縮的資料夾 android-studio

      底下有 bin 資料夾

      進入後執行裡面的 studio.sh

    • 使用命令行安裝

      1
      $ sh ~/Downloads/android-studio/bin/studio.sh

      *字看狀況可以自行更換成下載對應的版本

  • 設定 Command-line-launcher

    安裝完後點選開啟一個新專案

    開好後點選

    Tools -> Create Command line Launcher

    Tools -> Create Desktop Entry

    開啟命令列確定有安裝 python

    1
    $ sudo apt install python
  • 啟動 android studio

    關掉 android studio ,現在來確認可以開啟

    command line 輸入

    1
    $ studio

    或是左上角 Applications -> Development -> Android Studio

    • 有安裝 xiwi

    退到 chrome 桌面

    Ctrl+Alt+Tab 後輸入 shell

    1
    $ sudo enter-chroot xiwi studio
  • 透過 ADB 測試 app

    開啟Chrome terminal (Ctrl+Alt+Tab 輸入 shell)

    不想跟著步驟可以自己看著官方教學做 我下面是整理好的步驟官方教學(英文)

    1
    $ sudo crossystem dev_boot_signed_only=0
    1
    $ sudo /usr/libexec/debugd/helpers/dev_features_rootfs_verification

    執行下面這部會重開機,記得要 Ctrl+D 來進入

    1
    $ sudo reboot

    再次開啟Chrome terminal (Ctrl+Alt+T 輸入 shell)

    1
    $ sudo /usr/libexec/debugd/helpers/dev_features_ssh
  • 開啟 Pixelbook 裡 Android settings 下的 ADB Debugging

    • 點擊右下角時鐘
    • 點開設定
    • 往下滑,找到Google Play Stores
    • 進入找到 Manage Android preferences
    • 往下找到 About device 進入
    • 點擊 build number 七次來開啟開發者模式
    • 點擊左上返回
    • 進入開發者選項 ( Developer Options )
    • 啟用 ADB debugging
  • ADB 連接

    進入 Chrome terminal (Ctrl+Alt+T 輸入 shell)

    • ADB 連接
      1
      $ adb connect localhost:22
      正常運作會顯示 connected to localhost:22

    如果沒顯示,設定可能有錯

    • 測試 android studio 連接 adb

    先重啟adb

    1
    $ shell adb kill-server
    1
    $ adb connect localhost:22

    xiwi 啟動 android studio

    1
    $ sudo enter-chroot xiwi studio

    直接 run 應該可以看到 Pixelbook 出現在列表上了

    這時候就可以直接在 Pixelbook 上安裝及測試

在部屬 hexo 的時候發生錯誤,筆記一下解決方法

1
2
3
4
5
6
7
8
9
10
Error: watch /home/user/Downloads/GitHub/vn7n24fzkq.github.io/themes/next/layout/_macro/wechat-subscriber.swig ENOSPC
at exports._errnoException (util.js:870:11)
at FSWatcher.start (fs.js:1234:19)
at Object.fs.watch (fs.js:1262:11)
at createFsWatchInstance (/home/casper/Downloads/GitHub/vn7n24fzkq.github.io/node_modules/chokidar/lib/nodefs-handler.js:37:15)
at setFsWatchListener (/home/casper/Downloads/GitHub/vn7n24fzkq.github.io/node_modules/chokidar/lib/nodefs-handler.js:80:15)
at FSWatcher.NodeFsHandler._watchWithNodeFs (/home/casper/Downloads/GitHub/vn7n24fzkq.github.io/node_modules/chokidar/lib/nodefs-handler.js:228:14)
at FSWatcher.NodeFsHandler._handleFile (/home/casper/Downloads/GitHub/vn7n24fzkq.github.io/node_modules/chokidar/lib/nodefs-handler.js:255:21)
at FSWatcher.<anonymous> (/home/casper/Downloads/GitHub/vn7n24fzkq.github.io/node_modules/chokidar/lib/nodefs-handler.js:473:21)
at FSReqWrap.oncomplete (fs.js:82:15)
  • 解決方法
    1
    echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
    這行指令可以增加可以觀看的文件數量

今年入手了pixelbook,利用時間把建構開發環境的步驟整理出來


1.將chrome os開啟開發者模式

(注意,這個步驟會清除原本的所有資料)

  • 同時按下esc + refesh + 電源鍵

refesh就是最右邊那個

  • 接下來按 Ctrl + D

注意:畫面上不會有任何提示,你自己要知道要這樣做,每次開機都要按

當然你也可以按照開機畫面的教學隨時關閉開發者模式,要注意的是每次這樣做都會清除系統資料

2.下載crouton

crouton及chroot
crouton是chrome os下通用的chroot環境
chroot則是unix系統下的一種操作環境

將 crouton 下載到 Downloads 預設資料夾
下載crouton

GitHub也可以找到Crouton
crouton on GitHub

3.安裝Ubuntu LTS with Xfce

  • 打開一個 terminal (Ctrl + Alt + T )
  • 輸入 shell 按下 enter
  • 安裝xfce,安裝結束後輸入使用者名稱跟密碼
    1
    $ sudo sh~/Downloads/crouton -t xfce
    有任何做錯的可以直接用這兩個指令 在從這一步重新開始

1.顯示所有安裝的chroot
2.刪除指定的chroot( chrootname 換成要刪除的那個,預設安裝名稱是 xenial )

1
2
$ sudo edit-chroot -a
$ sudo edit-chroot -d chrootname

到這裡已經完成了大部分的步驟

4.成為ubuntu大神

  • 進入chroot

    1
    $ sudo enter-chroot
  • 開始安裝任何東西

    1
    2
    $ sudo apt-get install git
    $ sudo apt-get install curl

    Example

  • 在桌面開啟xfce

    • 打開 terminal (Ctrl + Alt + T )
    • 輸入 shell 按下 enter
    • 開啟xfce
      1
      $ sudo enter-chroot startxfce4
      1
      $ sudo startxfce4
      用 Ctrl + Alt + Shift + Back 和 Ctrl + Alt + Shift + Forward 在 xfce 和 chrome os 的桌面切換
  • 在 chrome tab 或一個新的視窗中開啟 xfce

    • 在 chrome 中加入 crouton integration
    • 安裝 xiwi 然後設置為預設的開啟方式
      xenail 換成 你 chroot 的名稱,xenial 是預設名稱
      1
      $ sudo sh ~/Downloads/crouton -t xiwi -u -n xenial
    • 在新視窗開啟 xfce
      1
      $ xiwi startxfce4
      在 chrome tab 開啟 xfce
      1
      $ xiwi -t startxfce4
      也可以獨立開啟應用程式
      像我使用 vscode
      1
      $ xiwi -t code

這篇文章也是在 vscode 下完成的
剩下其他的設定下次在發篇文章

先簡單介紹一下四叉樹QuadTree,四叉樹是一個樹狀的資料結構,經常運用在畫面處理或是2D的碰撞檢測。
從根節點root出發,當節點內達到一個條件的時候會再分裂成四個子節點。
詳細的介紹可以看Quadtree - Wikipedia
樹可能會長這樣(圖片取自wiki)

一般狀況下圖片會有RGB三原色,值是0~255,這次我設定四叉樹節點分裂的條件是區域內的RGB顏色離散程度到某個值就分裂。 `離散程度0到1,越接近0離散程度越低,mu則是區域內RGB的平均值`
接下來進入正題,要做壓縮的圖片有兩張。



把圖片讀進來後在compress這個method裡面做處理。如果有tiff檔無法讀取的狀況,請加入jai-imageio-core這個lib

1
2
3
4
5
6
7
8
9
10
11
12
13
public static BufferedImage compress(BufferedImage image, double threshold) {
Color[][] colors = makeColorArray(image);
int width = image.getWidth();
int height = image.getHeight();
QuadTree quadTree = new QuadTree(colors, new ImageMeasure(), threshold);
BufferedImage outImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
outImage.setRGB(i, j, quadTree.get(i, j).getRGB());
}
}
return outImage;
}

threshold是設定離散程度到多少要分裂
這裡寫個一個ImageMeasure類別來對圖像讀進來的資料作運算
approximate運算區域內像素的色彩近似值
measureDetail運算區域內色彩的離散程度

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
public Color approximate(Color[][] data, int x, int y, int width, int height) {
int redSum = 0;
int greenSum = 0;
int blueSum = 0;

for (int i = x; i < x + width; i++) {
for (int j = y; j < y + height; j++) {
redSum += data[i][j].getRed();
greenSum += data[i][j].getGreen();
blueSum += data[i][j].getBlue();
}
}

int pixelCount = width * height;

return new Color(redSum / pixelCount, greenSum / pixelCount, blueSum / pixelCount);
}

public double measureDetail(Color[][] data, int x, int y, int width, int height) {
int redSum = 0;
int greenSum = 0;
int blueSum = 0;

for (int i = x; i < x + width; i++) {
for (int j = y; j < y + height; j++) {
redSum += data[i][j].getRed();
greenSum += data[i][j].getGreen();
blueSum += data[i][j].getBlue();
}
}

double pixelCount = width * height;

double redAvg = redSum / pixelCount;
double greenAvg = greenSum / pixelCount;
double blueAvg = blueSum / pixelCount;

redSum = 0;
greenSum = 0;
blueSum = 0;

for (int i = x; i < x + width; i++) {
for (int j = y; j < y + height; j++) {
int red = data[i][j].getRed();
int green = data[i][j].getGreen();
int blue = data[i][j].getBlue();

redSum += Math.pow(red - redAvg, 2);
greenSum += Math.pow(green - greenAvg, 2);
blueSum += Math.pow(blue - blueAvg, 2);
}
}
return redSum / (pixelCount * 255 * 255) + greenSum / (pixelCount * 255 * 255) + blueSum / (pixelCount * 255 * 255);
}

quadtree中新增節點的時候則看運算的結果來決定要不要分裂以及節點的顏色近似值

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public Node(Color data[][], int x, int y, int width, int height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
if ((width == 1) || (height == 1) || (measure.measureDetail(data, x, y, width, height) <= threshold)) {
value = measure.approximate(data, x, y, width, height);
} else {
children = new Node[4];

children[0] = new Node(data, x, y, width / 2, height / 2);
children[1] = new Node(data, x + width / 2, y, width - width / 2, height / 2);
children[2] = new Node(data, x, y + height / 2, width / 2, height - height / 2);
children[3] = new Node(data, x + width / 2, y + height / 2, width - width / 2, height - height / 2);
}

}

這是運算之後的結果


完整程式碼在這裡
Quadtree Compression