Skip to content

2020

Setting Up Auto-Formatting for Python in Visual Studio Code

I was writing Python code and encountered issues with formatting. These formatting problems can complicate code reviews and the use of automated tools to detect such issues. Fortunately, life becomes much easier when you integrate a formatter into your code editor to automatically fix those issues upon saving. Here's how to do it:

  1. First, install Google's yapf formatter:

pip install yapf

  1. Next, open your Visual Studio Code editor. Press “Command + Shift + P” if you're using a Mac, or “Ctrl + Shift + P” if you're on Linux. Type "Open settings (JSON)" in the search bar and add the following line:

"python.formatting.provider": "yapf"

  1. If you want your code to auto-format upon saving, rather than merely receiving tips within the editor, add this setting as well:

"editor.formatOnSave": true

  1. Optionally, if you wish to use your project's .style.yapf instead of the global styles, add the following line:

"python.formatting.yapfArgs": ["--style", ".style.yapf"]

Now you can test the auto-formatting feature. For example, if you don't have a new line at the end of your Python file and then you save it, the formatter will automatically correct this issue for you.

Setting Up Auto-Formatting for Python in Visual Studio Code

Welcome back to another episode of Continuous Improvement! I'm your host, Victor. Today, we'll be talking about a common problem many Python developers face – formatting issues. We'll explore how integrating a code formatter into your editor can make your life easier. So, let's dive in!

Have you ever found yourself struggling with formatting problems while writing Python code? They can be quite troublesome, especially during code reviews and when using automated tools that detect such issues. But fear not, because I have a solution for you!

The first step is to install Google's yapf formatter. Simply open your command line or terminal and type in:

pip install yapf

Once you have yapf installed, it's time to configure your code editor – in this case, we'll be focusing on Visual Studio Code. Open VS Code and press "Command + Shift + P" if you're on a Mac, or "Ctrl + Shift + P" if you're on Linux. In the search bar, type "Open settings (JSON)" and add this line:

"python.formatting.provider": "yapf"

This step tells VS Code to use yapf as the Python code formatting provider. But we can take it a step further! If you want your code to automatically format upon saving, rather than just receiving tips within the editor, add this line as well:

"editor.formatOnSave": true

By enabling this setting, each time you save your Python file, it will be automatically formatted. This can save you a lot of time and effort.

Now, here's an optional step. If you wish to use your project's .style.yapf file instead of the global styles, add the following line to your VS Code settings:

"python.formatting.yapfArgs": ["--style", ".style.yapf"]

Including this setting allows you to customize the formatting rules according to your project's requirements. It provides even more flexibility when it comes to code formatting!

And that's it! With yapf installed and configured in Visual Studio Code, you can now enjoy the benefits of automatic code formatting. Just imagine, no more worries about missing new lines or incorrect indentation – the formatter will take care of it for you!

I encourage you to give it a try. Test the auto-formatting feature by intentionally leaving out a new line at the end of your Python file. When you save it, yapf will automatically correct this issue for you.

That brings us to the end of today's episode. I hope you found this information helpful in improving your workflow as a Python developer. Remember, continuous improvement is key to becoming better at what we do.

Thanks for tuning in to Continuous Improvement! I'm Victor, your host. Stay curious, stay dedicated, and keep striving for excellence. Until next time!

在Visual Studio Code中設定Python的自動格式化

我正在寫Python代碼,並遇到了格式化問題。這些格式問題可能會使代碼審查變得複雜,並對使用自動工具來檢測這些問題產生影響。幸運的是,當你將格式化工具集成到您的代碼編輯器中以在保存時自動修復這些問題時,生活會變得容易許多。這就是如何做的:

  1. 首先,安裝Google的yapf格式化工具:

pip install yapf

  1. 接著,打開你的Visual Studio Code編輯器。如果你使用的是Mac,按“Command + Shift + P”,如果你在Linux上,按“Ctrl + Shift + P”。在搜索欄中輸入"Open settings (JSON)"並添加以下行:

"python.formatting.provider": "yapf"

  1. 如果你希望你的代碼在保存時自動格式化,而不僅僅是在編輯器內部接收提示,也可以添加這個設置:

"editor.formatOnSave": true

  1. 如果你希望使用你的項目的.style.yapf而不是全局樣式,則添加以下行:

"python.formatting.yapfArgs": ["--style", ".style.yapf"]

現在你可以測試自動格式化功能。例如,如果你的Python文件末尾沒有新行,然後你保存它,格式化工具將自動為你修正這個問題。

How to Install Ubuntu Desktop on an AWS Instance Using Chrome Remote Desktop

In today's cloud-centric world, many resources have been moved to the cloud—photos, files, and servers among them. So why not your desktop environment? Imagine not needing to carry a heavy laptop. You could access your computing power from any thin client, such as a tablet with a keyboard, from anywhere. This is achievable using an AWS instance combined with Ubuntu Desktop and Chrome Remote Desktop. While there are other solutions like AWS Workspace or VNC connection, Chrome Remote Desktop offers the lowest latency and performance closest to a native desktop. Here's how to set it up:

  1. Log in to the AWS console and launch an instance using the Ubuntu Server AMI.

  1. Once the instance is launched, SSH into your Ubuntu server. Update the package manager and install wget:

sudo apt update sudo apt-get install --assume-yes wget

  1. Download the Chrome Remote Desktop package and install it:

wget https://dl.google.com/linux/direct/chrome-remote-desktop_current_amd64.deb sudo dpkg --install chrome-remote-desktop_current_amd64.deb sudo apt install --assume-yes --fix-broken

  1. Install the desktop GUI environment.

After testing various distributions, I found that Xfce performs best, especially over slow networks:

sudo DEBIAN_FRONTEND=noninteractive apt install --assume-yes xfce4 desktop-base

  1. Configure Chrome Remote Desktop to use Xfce by default:

sudo bash -c 'echo "exec /etc/X11/Xsession /usr/bin/xfce4-session" > /etc/chrome-remote-desktop-session'

  1. Install xscreensaver as an alternative to the default Xfce locker, which is not compatible with remote desktop:

sudo apt install --assume-yes xscreensaver

  1. Disable the display manager, as there is no display connected:

sudo systemctl disable lightdm.service

  1. Add your user account to the Linux group and then log out:

sudo usermod -a -G chrome-remote-desktop $USER logout

  1. On your local laptop browser, open Chrome Remote Desktop's Headless Mode. Follow the steps to set up another computer. You will probably copy a command similar to this into your AWS instance:

DISPLAY= /opt/google/chrome-remote-desktop/start-host --code="4/xxxxxxxxxxxxxxxxxxxxxxxx" --redirect-url="https://remotedesktop.google.com/_/oauthredirect" --name=

  1. Finally, you can remotely connect to your Ubuntu desktop.

    Extra tip: You can display a screensaver, although it's not necessary.

You can now access your desktop environment from anywhere, using any device. This setup is especially useful for software engineers who want access to a full set of development tools at all times.

How to Install Ubuntu Desktop on an AWS Instance Using Chrome Remote Desktop

Hello everyone and welcome back to another episode of Continuous Improvement. I'm your host, Victor, and today we're going to talk about an innovative way to access your desktop environment from anywhere using the power of the cloud.

In today's cloud-centric world, we've moved many resources to the cloud - photos, files, and even servers. So why not your desktop environment? Imagine not needing to carry a heavy laptop and being able to access your computing power from any thin client, such as a tablet with a keyboard, from anywhere. Well, today I'm going to introduce you to a solution that combines AWS, Ubuntu Desktop, and Chrome Remote Desktop to achieve just that.

Now, there are other solutions available, like AWS Workspace or VNC connection, but Chrome Remote Desktop offers the lowest latency and performance closest to a native desktop. So let's dive into the steps to set it up.

Step one, log in to the AWS console and launch an instance using the Ubuntu Server AMI. This will be the foundation of our remote desktop environment.

Once the instance is launched, we need to SSH into the Ubuntu server. Update the package manager and install wget, which we'll need for the next step.

In step three, we download the Chrome Remote Desktop package and install it on our Ubuntu server. This will allow us to connect to the desktop environment remotely.

Now, to make the desktop environment more user-friendly, in step four, we install the Xfce desktop GUI environment. This distribution has been found to perform best, especially over slow networks.

Step five is configuring Chrome Remote Desktop to use Xfce by default. This ensures a seamless experience when connecting remotely.

In step six, we install xscreensaver as an alternative to the default Xfce locker, which is not compatible with remote desktop.

Step seven is to disable the display manager, as there is no display connected to our AWS instance.

In step eight, we add our user account to the Linux group and then log out. This ensures the user has the necessary permissions and settings for remote desktop access.

Now that we have prepared our Ubuntu server, in step nine, we switch to our local laptop browser. We navigate to Chrome Remote Desktop's Headless Mode and follow the steps to set up another computer. This will generate a command that we need to copy into our AWS instance.

And finally, once everything is set up, in step ten, we can remotely connect to our Ubuntu desktop environment using Chrome Remote Desktop. Now you can access your desktop from anywhere, using any device.

That's it for today's episode of Continuous Improvement. I hope you found this innovative solution for accessing your desktop environment remotely helpful. Whether you're a software engineer or anyone who wants access to a full set of development tools at all times, this setup can be a game-changer.

As always, if you have any questions or want to share your own continuous improvement experiences, feel free to reach out to me on our website or social media. Until next time, keep improving and embracing innovation to achieve your goals.

如何使用Chrome遠程桌面在AWS實例上安裝Ubuntu桌面

在如今以雲端為中心的世界中,許多資源已被移至雲端,例如相片、檔案和伺服器等。那麼為何不將您的桌面環境也移到雲端呢?想像一下,不再需要帶著一台重型筆記本。您可以從任何薄型客戶端(例如帶有鍵盤的平板)在任何地方訪問您的計算能力。透過AWS實例,結合Ubuntu桌面和Chrome遠程桌面就可以實現這一點。雖然還有其他解決方法,如AWS工作區或VNC連接,但Chrome遠程桌面提供的延遲最低且性能最接近原生桌面。以下是如何設置的方法:

  1. 登錄AWS控制台,並使用Ubuntu Server AMI啟動一個實例。

  1. 實例啟動後,SSH登錄到您的Ubuntu服務器。更新包管理器並安裝wget:

sudo apt update sudo apt-get install --assume-yes wget

  1. 下載Chrome遠程桌面套裝軟體並安裝它:

wget https://dl.google.com/linux/direct/chrome-remote-desktop_current_amd64.deb sudo dpkg --install chrome-remote-desktop_current_amd64.deb sudo apt install --assume-yes --fix-broken

  1. 安裝桌面GUI環境。

在測試了各種不同的發行版本後,我發現Xfce在網路較慢的情況下表現最佳:

sudo DEBIAN_FRONTEND=noninteractive apt install --assume-yes xfce4 desktop-base

  1. 配置Chrome遠程桌面預設使用Xfce:

sudo bash -c 'echo "exec /etc/X11/Xsession /usr/bin/xfce4-session" > /etc/chrome-remote-desktop-session'

  1. 安裝xscreensaver作為預設的Xfce鎖屏程序的替代品,因為它不與遠程桌面兼容:

sudo apt install --assume-yes xscreensaver

  1. 禁用顯示管理器,因為沒有連接的顯示器:

sudo systemctl disable lightdm.service

  1. 將您的用戶賬戶添加到Linux群組,然後註銷:

sudo usermod -a -G chrome-remote-desktop $USER logout

  1. 在您的本地筆記本瀏覽器上,打開Chrome遠程桌面的無頭模式。按照步驟設置另一部電腦。您可能會在您的AWS實例中複製此類命令:

DISPLAY= /opt/google/chrome-remote-desktop/start-host --code="4/xxxxxxxxxxxxxxxxxxxxxxxx" --redirect-url="https://remotedesktop.google.com/_/oauthredirect" --name=

  1. 最後,您可以遠程連接到您的Ubuntu桌面了。

    額外的提示:您可以顯示屏幕保護程序,儘管這並不必要。

您現在可以使用任何設備,從任何地方訪問您的桌面環境。這種設置對於隨時需要訪問完整開發工具集的軟體工程師特別有用。

How to Install Ubuntu on an External Drive Using macOS

If you're using Mac hardware but also want to run Ubuntu, you can install Ubuntu on an external hard drive without risking the removal of your macOS installation. Here's how to do it without messing up your bootloader:

  1. Plug in your external SSD/HDD. Open Disk Utility and format it to MS-DOS (FAT).

  2. Open a Terminal window and run: diskutil list

This will help you find your external hard drive's IDENTIFIER, e.g., disk2 in this example.

  1. Download and install VirtualBox: VirtualBox Website

  2. Run the two commands below and start VirtualBox with admin rights:

sudo VBoxManage internalcommands createrawvmdk -filename bootcamp.vmdk -rawdisk /dev/disk2 sudo /Applications/VirtualBox.app/Contents/MacOS/VirtualBox

  1. Select "New" and then click on "Expert Mode." Choose "Use an existing virtual hard disk file."

  1. In the "System" tab, check the box for "Enable EFI (special OSes only)."

  2. In the "Storage" tab, mount the Ubuntu ISO file to the virtual machine. You can download the Ubuntu ISO file from here.

  3. Start the virtual machine and proceed with the Ubuntu installation.

  4. Once the installation is complete, you'll be ready to boot from the drive. For Mac, you'll also need to reduce the Security level and allow booting from external media. To do this, press and hold Command-R immediately after you see the Apple logo to start macOS recovery.

  5. Restart your Mac again and press the Option key. You can now choose your drive with the EFI label.

Enjoy using Ubuntu on Apple hardware! Note that you might have to sort out some driver issues, but hopefully, this guide makes the process easier for you.

How to Install Ubuntu on an External Drive Using macOS

Hello and welcome back to another episode of Continuous Improvement. I'm your host, Victor, and today we're going to talk about a unique topic - how to install Ubuntu on an external hard drive without risking the removal of your macOS installation.

Now, we know that many of you may be using Mac hardware but also want to experience the wonders of Ubuntu. So, let's dive into the step-by-step process of achieving this without messing up your bootloader.

The first step is to plug in your external SSD or HDD and open Disk Utility. Format the drive to MS-DOS (FAT) to ensure compatibility.

Next, open a Terminal window and run the command diskutil list. This will help you find the IDENTIFIER of your external hard drive, such as disk2 in our example.

Now that we have identified the external drive, it's time to download and install VirtualBox from the official website. VirtualBox is a powerful tool that allows us to create virtual machines on our Mac.

After the installation, run two commands in the Terminal window to create a virtual machine using your external drive as the raw disk. Type in sudo VBoxManage internalcommands createrawvmdk -filename bootcamp.vmdk -rawdisk /dev/disk2 and then sudo /Applications/VirtualBox.app/Contents/MacOS/VirtualBox. This will start VirtualBox with admin rights.

Now, in VirtualBox, click on "New" and select "Expert Mode". Choose the option "Use an existing virtual hard disk file" and browse for the bootcamp.vmdk file that we created earlier.

In the "System" tab, make sure to check the box for "Enable EFI (special OSes only)" to ensure compatibility with macOS.

Moving on to the "Storage" tab, we need to mount the Ubuntu ISO file to the virtual machine. You can download the Ubuntu ISO file from the official Ubuntu website.

Great! Now it's time to start the virtual machine and proceed with the Ubuntu installation. Follow the on-screen instructions and be patient as the installation process completes.

Once the installation is complete, you'll be ready to boot from the external drive. But before that, there's one more thing. For Mac users, you'll need to reduce the Security level and allow booting from external media.

To do this, restart your Mac and press and hold Command-R immediately after you see the Apple logo to start macOS recovery. From there, navigate to the Security options and allow booting from external media.

Fantastic! You're almost there. Restart your Mac again, but this time, press and hold the Option key. You'll now see a menu where you can choose your drive with the EFI label. That's your Ubuntu installation on the external drive.

And there you have it! You can now enjoy the wonders of Ubuntu on your Apple hardware without compromising your macOS installation. Just keep in mind that you might need to sort out some driver issues, but don't worry, the process we've discussed today will make it much easier for you.

That concludes today's episode of Continuous Improvement. I hope you found this guide helpful and that it encourages you to explore new possibilities in the world of technology. Remember, with continuous improvement, we can achieve great things.

Until next time, I'm Victor, signing off. Take care and stay curious!

如何使用macOS在外部驅動器上安裝Ubuntu

如果你在使用Mac硬體,但也想要運行Ubuntu,你可以在外部硬碟上安裝Ubuntu,而不會冒著刪除你的macOS安裝的風險。下面是如何在不搞砸你的引導裝載器的情況下進行操作:

  1. 將你的外部SSD/HDD插入。打開磁碟工具並將其格式化為MS-DOS(FAT)

  2. 打開終端窗口並運行: diskutil list

這將幫助你找到你的外部硬碟的標識符,例如,在這個示例中是disk2。

  1. 下載並安裝VirtualBox: VirtualBox網站

  2. 運行以下兩條命令並以管理員權限啟動VirtualBox:

sudo VBoxManage internalcommands createrawvmdk -filename bootcamp.vmdk -rawdisk /dev/disk2 sudo /Applications/VirtualBox.app/Contents/MacOS/VirtualBox

  1. 選擇“新建”然後點擊“專家模式”。選擇“使用現有的虛擬硬碟文件。”

  1. 在“系統”標籤中,勾選“啟用EFI(僅限特殊OS)”。

  2. 在“儲存”標籤中,將Ubuntu ISO文件掛載到虛擬機。 你可以從這裡下載Ubuntu ISO文件。

  3. 啟動虛擬機並進行Ubuntu安裝。

  4. 一旦安裝完成,你就可以從驅動器啟動了。 對於Mac,你也需要降低安全級別並允許從外部媒體啟動。要做到這一點,在你看到蘋果標誌後立即按住Command-R以啟動macOS恢復。

  5. 重新啟動你的Mac並按住選項鍵。你現在可以選擇你的驅動器擁有EFI標籤。

享受在Apple硬體上使用Ubuntu!請注意,你可能需要解決一些驅動問題,但希望這個指南能讓你的過程更容易。

How to Fix the "Access Denied" Error in an AWS Amplify Angular App

When you deploy your Angular app on AWS Amplify, the first landing page loads without any issues. However, if you have defined a path in your router and attempt to access it, you may encounter an "Access Denied" error:

To resolve this issue, navigate to the AWS Console and select "Rewrites and Redirects." Next, add a new rewrite and redirect rule. Click on "Open Text Editor" and insert the following rule:

[
  {
    "source": "</^[^.]+$|\\.(?!(css|gif|ico|jpg|js|png|txt|svg|woff|ttf)$)([^.]+$)/>",
    "target": "/index.html",
    "status": "200",
    "condition": null
  }
]

After adding this rule, try accessing your URL again. It should work as expected now.