2024年9月3日 星期二

iframe 的用法

 利用 iframe 這個 html 的 tag,就可以在網頁中顯示其它網頁的內容

<iframe src="https://yourhost.com/path/to/notebook.html" width="100%" height="600px"></iframe>


2024年9月2日 星期一

如何用 git 更新檔案

git add .

git commit -m "Update website content"

git push origin main


2024年9月1日 星期日

如何用 RStudio 做 quarto 網站,並放到 github

To deploy a Quarto website to GitHub using the usethis package in RStudio on Ubuntu 20.04, follow these steps:

  1. Install Required Packages: Ensure you have the usethis, quarto, and gitcreds packages installed. You can install them using the following commands in RStudio:

    install.packages("usethis")
    install.packages("quarto")
    install.packages("gitcreds")
    
  2. Create a New Quarto Project: Create a new Quarto project in RStudio. You can do this by navigating to File > New Project > New Directory > Quarto Website.

  3. Set git username and password (token) if you first use git:

    usethis::use_git_config(user.name = "Your Name", user.email = "your.email@example.com")
    
  4. Set git token (password), you have to get the token from github.com before use:

    gitcreds::gitcreds_set()
    
  5. Configure Quarto for GitHub Pages: Modify your _quarto.yml file to specify the output directory as docs:

    project:
      type: website
      output-dir: docs
    
  6. Build the website files:

    system("quarto render")
    
  7. Initialize Git: Initialize a Git repository in your project directory:

    usethis::use_git()
    
  8. Create a GitHub Repository: Use usethis to create a GitHub repository and link it to your local project:

    usethis::use_github()
    
  9. Configure GitHub Pages: Go to your GitHub repository settings and configure GitHub Pages to publish from the docs directory of the main branch.

如何用 RStudio 發表 Quarto 網站到 github

To deploy a Quarto website to GitHub using the usethis package in RStudio on Ubuntu 20.04, follow these steps:

  1. Install Required Packages: Ensure you have the usethis and quarto packages installed. You can install them using the following commands in RStudio:

    install.packages("usethis")
    install.packages("quarto")
    
  2. Create a New Quarto Project: Create a new Quarto project in RStudio. You can do this by navigating to File > New Project > New Directory > Quarto Website.

  3. Initialize Git: Initialize a Git repository in your project directory:

    usethis::use_git()
    
  4. Create a GitHub Repository: Use usethis to create a GitHub repository and link it to your local project:

    usethis::use_github()
    
  5. Configure Quarto for GitHub Pages: Modify your _quarto.yml file to specify the output directory as docs:

    project:
      type: website
      output-dir: docs
    
  6. Add .nojekyll File: Add a .nojekyll file to the root of your repository to prevent GitHub Pages from processing your site with Jekyll:

    touch .nojekyll
    
  7. Render and Deploy Your Site: Render your Quarto site and push the changes to GitHub:

    quarto render
    git add docs
    git commit -m "Publish site to docs/"
    git push
    
  8. Configure GitHub Pages: Go to your GitHub repository settings and configure GitHub Pages to publish from the docs directory of the main branch.

2024年8月20日 星期二

用 vacuum 指令把 sqlite3 資料庫變小

 import sqlite3


# Connect to your SQLite3 database

conn = sqlite3.connect('your_database_file.db')

cursor = conn.cursor()


# Execute the VACUUM command

cursor.execute('VACUUM')


# Close the connection

conn.close()


2024年6月29日 星期六

In Ubuntu 20.04, how to install gnuplot from the source code

gnuplot 安裝後若需要 png 類型的輸出,可以依以下步驟安裝:

sudo apt-get update

sudo apt-get install build-essential

sudo apt-get build-dep gnuplot

sudo apt-get install libgd-dev libpng-dev


wget https://sourceforge.net/projects/gnuplot/files/gnuplot/5.2.8/gnuplot-5.2.8.tar.gz

tar -xzf gnuplot-5.2.8.tar.gz

cd gnuplot-5.2.8


./configure --with-gd --with-png

make

mack check

sudo make install


說明:
在使用 wxMaxima 時,inline plot 需要 gnuplot 的 png 類型輸出,所以安裝 gnuplot 時,必需要有安裝 png 類型的 terminal。

可以在 gnuplot> 輸入 set terminal 查看安裝的 terminal 類型。

2024年6月28日 星期五

2024年6月23日 星期日

2024年6月22日 星期六

在 Ubuntu 24.04 中從 Mozilla Builds 安裝 Firefox

Ubuntu 24.04 中,Firefox 預設是從 snap 安裝,然而,從 snap 安裝的版本不能使用 gcin 中文輸入法。為了解決這個問題,我參考以下網頁,依照以下方法,成功安裝 Mozilla Builds Firefox,且可使用中文輸入法。

首先移除已安裝的 firefox:

$ sudo snap remove firefox

$ sudo apt remove firefox 


然後參考:

 Install Firefox from Mozilla builds

1. 從 Mozilla 官網下載 Firefox Linux 64-bit 版本,例如 firefox-127.0.1.tar.bz2

2. 按照以下步驟

$ tar xjf firefox-*.tar.bz2

$ sudo mv firefox /opt

$ sudo ln -s /opt/firefox/firefox /usr/local/bin/firefox

$ sudo wget https://raw.githubusercontent.com/mozilla/sumo-kb/main/install-firefox-linux/firefox.desktop -P /usr/local/share/applications

3. 在終端機執行

$ firefox

即可啟動,而且 gcin 可以正常使用。

2024年6月20日 星期四

在 Ubuntu 20.04 上安裝 cudnn

我的測試環境 

Ubuntu 20.04

NVIDIA-SMI 535.183.01             Driver Version: 535.183.01   CUDA Version: 12.2

用以下的方法,可以確保版本正確的問題

1. **Add NVIDIA package repositories**:
   Ensure you have the CUDA repository added to your system. Follow these steps:

   ```sh
   sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/3bf863cc.pub
   sudo sh -c 'echo "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64 /" > /etc/apt/sources.list.d/cuda.list'
   sudo sh -c 'echo "deb https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu2004/x86_64 /" > /etc/apt/sources.list.d/cuda_learn.list'
   ```

2. **Update the package list**:

   ```sh
   sudo apt update
   ```

3. **Install CUDA**:
   Ensure you have CUDA installed. You can install a specific version if needed.

   ```sh
   sudo apt install cuda-12-0
   ```

4. **Install cuDNN**:
   Install the cuDNN package for CUDA 12.

   ```sh
   sudo apt install libcudnn8=8.9.7.29-1+cuda12.2
   sudo apt install libcudnn8-dev=8.9.7.29-1+cuda12.2
   sudo apt install libcudnn8-samples=8.9.7.29-1+cuda12.2
   ```

   Replace `8.x.x.x-1+cuda12.0` with the actual version available in the repository. You can check for the available versions using:

   ```sh
   apt-cache policy libcudnn8
   ```

5. **Verify the installation**:
   Ensure CUDA and cuDNN are installed correctly.

   ```sh
   nvcc --version
   ```

   For cuDNN, you can check the version as follows:

   ```sh
   cat /usr/include/cudnn_version.h | grep CUDNN_MAJOR -A 2
   ```

參考:
https://chatgpt.com/share/cbe6f18b-d8af-4621-8355-874f205f6a86

https://medium.com/@scofield44165/ubuntu-20-04%E4%B8%AD%E5%AE%89%E8%A3%9Dnvidia-driver-cuda-11-4-2%E7%89%88-cudnn-install-nvidia-driver-460-cuda-11-4-2-cudnn-6569ab816cc5

install nvidia cuda in Ubuntu 20.04

 參考

https://medium.com/@scofield44165/ubuntu-20-04%E4%B8%AD%E5%AE%89%E8%A3%9Dnvidia-driver-cuda-11-4-2%E7%89%88-cudnn-install-nvidia-driver-460-cuda-11-4-2-cudnn-6569ab816cc5

2024年3月9日 星期六

由 sensitivity 和 specificity 計算 post-test probability

分別用三種不同的網站界面呈現

1. Google Colab

https://colab.research.google.com/drive/1Sgs3iz5MzLmH3PPEVOai3tLCj1PDdOSh?usp=sharing


2. R shiny

https://3g01q7-chi0pan-hsieh.shinyapps.io/mywork2/


3. Python flask

https://goodmed.pythonanywhere.com/


Using R shiny to publish in a website

In Ubuntu 20.04, How can I use R Shiny to view a math function plot on a web page? function: y = x^2

ChatGPT

ChatGPT

To view a math function plot, such as y=x^2, on a web page using R Shiny in Ubuntu 20.04, follow these steps. I'll guide you through installing R, the necessary packages, and creating a basic Shiny app to display the plot of y=x^2

Step 1: Install R

Ubuntu 20.04 may not come with R pre-installed, so you'll need to install it. Open a terminal and run:

sudo apt update
sudo apt install r-base

Step 2: Install R Packages

Once R is installed, you need to install the Shiny package and ggplot2 for plotting. Start R in the terminal:

R

Then, install the packages by running:

install.packages("shiny")
install.packages("ggplot2")

Step 3: Create Your Shiny App

Shiny apps consist of a UI (User Interface) definition and a server function. You'll create a basic app to plot y=x^2. Create a new directory for your Shiny app and then create two files within that directory: ui.R and server.R.

  1. ui.R: This file defines the layout and appearance of your app.

library(shiny)

# Define UI for application
ui <- fluidPage(
   
   # Application title
   titlePanel("Plot of y = x^2"),
   
   # Sidebar with a slider input for the range of x
   sidebarLayout(
      sidebarPanel(
         sliderInput("range",
                     "X Range:",
                     min = -10,
                     max = 10,
                     value = c(-10, 10))
      ),
      
      # Show a plot of the generated distribution
      mainPanel(
         plotOutput("distPlot")
      )
   )
)
  1. server.R: This file contains the server logic to generate the plot based on the input range.

library(shiny)
library(ggplot2)

# Define server logic
server <- function(input, output) {
   
   output$distPlot <- renderPlot({
      x <- seq(input$range[1], input$range[2], by = 0.1)
      y <- x ^ 2
      ggplot(data.frame(x, y), aes(x = x, y = y)) +
         geom_line() +
         labs(title = "Plot of y = x^2",
              x = "x",
              y = "y")
   })
}
  1. Run Your App: Go back to your R session in the terminal. Set your working directory to the folder containing your app, then run:

library(shiny)
runApp()

Shiny will start a web server and give you a URL to access your app. Open this URL in a web browser to see the plot of y=x2 with the ability to adjust the range of xxx via a slider.

This is a simple example to get you started. Shiny is very flexible, allowing you to build highly interactive web applications. You can explore more features and capabilities of Shiny and ggplot2 to enhance your app.

Anonymous

how to show the above in a internet webpage?

ChatGPT

ChatGPT

To display a Shiny app on an internet webpage accessible to others, you would typically need to deploy the app to a server. There are a few common ways to do this:

1. ShinyApps.io

ShinyApps.io is a platform provided by RStudio for hosting Shiny applications. It's the easiest way to get started with deploying Shiny apps. Here's how you can do it:

  1. Install and Load the rsconnect Package: First, you need to install and load the rsconnect package in R, which is used for deploying applications to ShinyApps.io.

    install.packages("rsconnect")
    library(rsconnect)
  2. Set Up an Account on ShinyApps.io: If you haven't already, go to shinyapps.io and set up an account. After setting up your account, you'll find instructions to authorize your R session to deploy apps to your ShinyApps.io account.

  3. Deploy Your App: Use the deployApp function from the rsconnect package. Navigate to your app directory in R (using setwd) and then deploy your app.

    deployApp()

After deployment, you'll be given a URL where your app is hosted and can be accessed by anyone on the internet.

用 R shiny 發表動態圖在網站

用 Windows 下的 R 4.2.2 測試成功。

成品:

https://3g01q7-chi0pan-hsieh.shinyapps.io/mywork/

https://3g01q7-chi0pan-hsieh.shinyapps.io/mywork2/

2024年2月24日 星期六

如何讓 Blogger 文章裡的程式碼有 Syntax highlighting

到這個網站 https://highlightjs.org/

copy cdnjs 的幾行程式碼文字

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/default.min.css"></link>

<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>


<!-- and it's easy to individually load additional languages -->

<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/go.min.js"></script>


<script>hljs.highlightAll();</script>

把以上幾行文字放在 blogger 主題 html 的 <head> 下方即可。

如何在 Google Blogger 的文章中顯示 LaTeX 數學式

在 html 原始碼的 <head> 下方,加上這 2 行:

<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>

<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>

之後寫文章時,用以下的格式寫數學式。

寫在行間的數學式:
This is an inline equation: \(x^2 + y^2 = z^2\)

寫在行與行之間的數學式:
This is a display equation: \[x^2 + y^2 = z^2\]

補充:
LaTeX 碼的產生,可以用這個網站