first commit

This commit is contained in:
2024-03-12 00:26:54 -04:00
commit 3d476f095c
222 changed files with 26485 additions and 0 deletions

View File

@@ -0,0 +1,312 @@
---
title: Claude 3 Opus's Performance in C Language Exam
subtitle:
date: 2024-03-11T20:17:44-04:00
slug: claude-3-opus-c-exam
draft: false
author:
name: James
link: https://www.jamesflare.com
email:
avatar: /site-logo.avif
description: This blog post presents a simulated C language programming exam, featuring question types such as fill-in-the-blanks, short answer questions, and application problems. The objective is to comprehensively assess students' mastery of C language knowledge, problem-solving abilities, and skills in writing efficient and elegant code. Through such a mock test, students can identify their weaknesses and make thorough preparations for the actual exam. At the same time, it provides readers with an intuitive understanding of the key points in C language assessment.
keywords: ["C Language", "Exam", "Programming Questions"]
license:
comment: true
weight: 0
tags:
- C
- Exam
- Claude
- LLM
- Benchmark
categories:
- Review
- Programming
- LLM
hiddenFromHomePage: false
hiddenFromSearch: false
hiddenFromRss: false
hiddenFromRelated: false
summary: This blog post presents a simulated C language programming exam, featuring question types such as fill-in-the-blanks, short answer questions, and application problems. The objective is to comprehensively assess students' mastery of C language knowledge, problem-solving abilities, and skills in writing efficient and elegant code. Through such a mock test, students can identify their weaknesses and make thorough preparations for the actual exam. At the same time, it provides readers with an intuitive understanding of the key points in C language assessment.
resources:
- name: featured-image
src: featured-image.jpg
- name: featured-image-preview
src: featured-image-preview.jpg
toc: true
math: true
lightgallery: false
password:
message:
repost:
enable: true
url:
# See details front matter: https://fixit.lruihao.cn/documentation/content-management/introduction/#front-matter
---
<!--more-->
{{< admonition type=note title="System Prompt" open=true >}}
You are playing the role of a student learning C language. Your current task is to take an exam on C language. In this exam, you need to perform your best and answer in as much detail as possible to obtain a high score. All examinees, good luck!
{{< /admonition >}}
## Fill-in-the-Blank Questions
1. The working principle of computers is (**A**).
**A** = stored program and program control
2. Integers are represented in memory using binary (**B**) code.
**B** = two's complement
3. There are (**C**) types of relational operators.
**C** = 6 (<, <=, >, >=, ==, !=)
4. There are (**D**) forms of loop statements.
**D** = 3 (while, do-while, for)
5. Using functions requires three steps: (**E**), definition, and calling.
**E** = declaration
6. Array elements are stored (**F**) in memory.
**F** = contiguously
7. The two elements of a pointer are address and (**G**).
**G** = data type
8. To use math library functions, the header file to be included is (**H**).
**H** = <math.h>
9. Variables defined outside of functions are called (**I**) variables.
**I** = global
10. The keyword for defining structure types is (**J**).
**J** = struct
## Short Answer Questions
1. **The roles of break and continue statements**:
The break statement is used to jump out of the current loop body and terminate the loop execution. When the break statement is encountered, the program immediately exits the loop it is in and starts executing the statement following the loop.
The continue statement is used to skip the remaining statements of the current iteration and directly proceed to the next iteration. When the continue statement is encountered, the program immediately jumps to the loop control expression and begins the next iteration.
2. **Solution for returning multiple values from a function**:
Pointers can be used as function parameters to pass the addresses of multiple variables. By modifying the values of these variables inside the function, the effect of returning multiple values can be achieved.
For example, write a function to calculate the sum and difference of two integers and return the results through pointers:
```c
void calc(int a, int b, int *sum, int *diff) {
*sum = a + b;
*diff = a - b;
}
```
Calling the function in main:
```c
int main() {
int x = 10, y = 5, sum, diff;
calc(x, y, &sum, &diff);
printf("Sum: %d, Diff: %d\n", sum, diff);
return 0;
}
```
3. **Situations that require dynamic memory allocation**:
When the required memory size can only be determined at runtime, or when memory needs to be frequently allocated and released, dynamic memory allocation should be used.
For example, reading a file and storing its content in memory. Since the file size is unknown in advance, memory needs to be dynamically allocated based on the actual number of bytes read:
```c
FILE *fp = fopen("data.txt", "r");
char *buffer = NULL;
int size = 0;
int capacity = 0;
char ch;
while ((ch = fgetc(fp)) != EOF) {
if (size + 1 > capacity) {
capacity = (capacity == 0) ? 1 : capacity * 2;
buffer = (char *)realloc(buffer, capacity);
}
buffer[size++] = ch;
}
buffer[size] = '\0';
fclose(fp);
```
4. **The basic idea of the exhaustive method**:
The exhaustive method is a fundamental algorithmic approach. Its basic idea is to enumerate all possible cases, check each case one by one to determine if it satisfies the problem requirements, and thus obtain the solution to the problem.
For example, to find all prime numbers between 1 and 100. The exhaustive method can be used to traverse each number from 1 to 100 and determine whether it is a prime number:
```c
for (int i = 2; i <= 100; i++) {
int isPrime = 1;
for (int j = 2; j < i; j++) {
if (i % j == 0) {
isPrime = 0;
break;
}
}
if (isPrime) {
printf("%d ", i);
}
}
```
5. **Practical problems suitable for storing data using arrays**:
(1) Student grade management system: Arrays can be used to store each student's scores in various subjects, which is convenient for score input, query, and statistics.
(2) Image processing: An image can be regarded as a two-dimensional array, where each element represents the pixel value at the corresponding position. Using arrays facilitates image reading, modification, and display operations.
## Application Questions
1. **A three-digit decimal integer is called a "narcissistic number" if the sum of the cubes of its three digits equals the number itself (for example, $153 = 1^3 + 5^3 + 3^3$). Please define a function to determine whether an integer is a narcissistic number, and use this function to print out all narcissistic numbers.**
```c
#include <stdio.h>
#include <math.h>
int isNarcissistic(int num) {
int sum = 0;
int temp = num;
while (temp > 0) {
int digit = temp % 10;
sum += pow(digit, 3);
temp /= 10;
}
return (sum == num);
}
int main() {
printf("All narcissistic numbers:\n");
for (int i = 100; i <= 999; i++) {
if (isNarcissistic(i)) {
printf("%d ", i);
}
}
return 0;
}
```
2. **Given the iterative relation $x_{k+1} = \frac{4}{3}x_{k} - \frac{a}{3x^{2}_{k}}$, where $a \in \mathbb{R}$, and $\\{ x_k \\}$ converges. Write a program to estimate the limit value of $x_k$.**
```c
#include <stdio.h>
#include <math.h>
#define EPSILON 1e-6
double iterate(double x, double a) {
return (4.0 / 3.0) * x - a / (3 * x * x);
}
int main() {
double a;
printf("Please enter the value of parameter a: ");
scanf("%lf", &a);
double x0 = 1.0; // Initial value
double x1 = iterate(x0, a);
while (fabs(x1 - x0) > EPSILON) {
x0 = x1;
x1 = iterate(x0, a);
}
printf("The estimated limit value of the iterative sequence is: %.6f\n", x1);
return 0;
}
```
3. **There are n students, and the information of each student includes name and score. Use dynamic memory allocation to store the data and complete the following operations:**
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_NAME 20
typedef struct {
char name[MAX_NAME];
int score;
} Student;
void inputStudents(Student *students, int n) {
for (int i = 0; i < n; i++) {
printf("Please enter the name and score of student %d: ", i + 1);
scanf("%s %d", students[i].name, &students[i].score);
}
}
void printStudents(Student *students, int n) {
printf("Student information:\n");
for (int i = 0; i < n; i++) {
printf("Name: %s\tScore: %d\n", students[i].name, students[i].score);
}
}
void sortStudents(Student *students, int n) {
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < n - i - 1; j++) {
if (students[j].score < students[j + 1].score) {
Student temp = students[j];
students[j] = students[j + 1];
students[j + 1] = temp;
}
}
}
}
int main() {
int n;
printf("Please enter the number of students: ");
scanf("%d", &n);
Student *students = (Student *)malloc(n * sizeof(Student));
inputStudents(students, n);
printStudents(students, n);
sortStudents(students, n);
printf("Student information sorted by score in descending order:\n");
printStudents(students, n);
free(students);
return 0;
}
```
The above program implements the following functions:
1. Defined a student structure that includes name and score fields.
2. Created a student structure array of size n using dynamic memory allocation.
3. Provided functions for inputting student information, printing student information, and sorting student information by score in descending order.
4. In the main function, first input the number of students, then dynamically allocate memory to create a student array.
5. Call the corresponding functions to input student information, print student information, sort students by score in descending order, and print the sorted results.
6. Finally, free the dynamically allocated memory.

View File

@@ -0,0 +1,662 @@
---
title: Create MCQs with ChatGPT in Scales
subtitle:
date: 2023-03-04T16:45:19+08:00
slug: create-mcq-chatgpt-scales
draft: false
author:
name: James
link: https://www.jamesflare.com
email:
avatar: /site-logo.avif
description: This blog post demonstrates how to create multiple-choice question (MCQ) papers using ChatGPT, Python, and JSON files, covering the process from generating a question bank to formatting and building the final test papers, answer sheets, and marking schemes.
keywords: ["MCQ","ChatGPT","Python","JSON"]
license:
comment: true
weight: 0
tags:
- ChatGPT
- Python
categories:
- Tutorials
- LLM
hiddenFromHomePage: false
hiddenFromSearch: false
hiddenFromRss: false
hiddenFromRelated: false
summary: This blog post demonstrates how to create multiple-choice question (MCQ) papers using ChatGPT, Python, and JSON files, covering the process from generating a question bank to formatting and building the final test papers, answer sheets, and marking schemes.
resources:
- name: featured-image
src: featured-image.jpg
- name: featured-image-preview
src: featured-image-preview.jpg
toc: true
math: false
lightgallery: false
password:
message:
repost:
enable: true
url:
# See details front matter: https://fixit.lruihao.cn/documentation/content-management/introduction/#front-matter
---
<!--more-->
## Introduction
Hi, dear teachers!
Did you have difficulty on creating test paper for students?
In this post, I am going to show you how to create MCQs in scales and randomly pick a selected number of questions out, then make it into three formatted editable Word documents, includes test paper, answer sheet and marking scheme.
### Steps
1. Ask ChatGPT to make a .json format question bank.
2. Format the .json question bank through a Python Program.
3. Make another Python Program to create papers from the .json question bank.
## Prompt Engineering
Here is the first step. We want the MCQs fit for the topic. To do that, we need tell the ChatGPT what is should do, and where to do.
You may do your prompt like this format
> \[Instruction\] +
>
> \[Templates\] +
>
> \[Learning Objects\] +
>
> \[Topic Concepts\] +
>
> \[Additional Points\] +
>
> \[MCQ Command Words\] +
>
> \[Rules for ChatGPT\]
I made a non-perfect example on Astrophysics, which means not all objects were covered. So, the MCQs can be a bit boring under mass generation. But they will not repeat, at least in options.
Therefore, students who memorize options will be ended.
### Example
{{< admonition type=warning title="This is not The Raw Input" open=true >}}
To make it easier to read, I made the Raw Markdown input into this Web Page.
If you want check out the Raw input, check the end of this section. There is a dropdown box.
{{< /admonition >}}
> You are an AI-powered json file generator that never make mistakes, and you are going to imagine 1000 MCQs about Astrophysics first in mind, then randomly give me 15 of them in this json form:
>
> ```json
> [
> {
> "order_number": "[Order Number]",
> "question": "[Question]",
> "type": "mcq",
> "option_a": "[Option A]",
> "option_b": "[Option B]",
> "option_c": "[Option C]",
> "option_d": "[Option D]",
> "answer": "[Correct Option in ABCD]",
> "explanation": "[Explanation of Why This Answer]"
> },
> {
> "order_number": "[Order Number]",
> "question": "[Question]",
> "type": "mcq",
> "option_a": "[Option A]",
> "option_b": "[Option B]",
> "option_c": "[Option C]",
> "option_d": "[Option D]",
> "answer": "[Correct Option in ABCD]",
> "explanation": "[Explanation of Why This Answer]"
> }
> ]
> ```
>
> Please check the understanding of these Learning objectives in your generated MCQs:
>
> 1. Describe the main objects comprising the universe.
>
> 2. Describe the nature of stars.
>
> 3. Understand astronomical distances.
>
> 4. Work with the method of parallax.
>
> 5. Define luminosity and apparent brightness and solve problems with these quantities and distance.
>
> And these key concepts as well:
> |Term|Definition|
> |:----|:----|
> |Binary star|Two stars orbiting a common centre|
> |Black dwarf|The remnant of a white dwarf after it has cooled down. It has very low luminosity|
> |Black hole|A singularity in space time; the end result of the evolution of a very massive star|
> |Brown dwarf|Gas and dust that did not reach a high enough temperature to initiate fusion. These objects continue to compact and cool down|
> |Cepheid variable|A star of variable luminosity. The luminosity increases sharply and falls off gently with a well-defined period. The period is related to the absolute luminosity of the star and so can be used to estimate the distance to the star|
> |Cluster of galaxies|Galaxies close to one another and affecting one another gravitationally, behaving as one unit|
> |Comet|A small body (mainly ice and dust) orbiting the Sun in an elliptical orbit|
> |Constellation|A group of stars in a recognizable pattern that appear to be near each other in space|
> |Dark matter|Generic name for matter in galaxies and clusters of galaxies that is too cold to radiate. Its existence is inferred from techniques other than direct visual observation|
> |Galaxy|A collection of a very large number of stars mutually attracting one another through the gravitational force and staying together. The number of stars in a galaxy varies from a few million in dwarf galaxies to hundreds of billions in large galaxies. It is estimated that 100 billion galaxies exist in the observable universe|
> |Interstellar medium|Gases (mainly hydrogen and helium) and dust grains (silicates, carbon and iron) filling the space between stars. The density of the interstellar medium is very low. There is about one atom of gas for every cubic centimeter of space. The density of dust is a trillion times smaller. The temperature of the gas is about 100 K|
> |Main-sequence star|A normal star that is undergoing nuclear fusion of hydrogen into helium. Our Sun is a typical main-sequence star|
> |Nebula|Clouds of 'dust', i.e. compounds of carbon, oxygen, silicon and metals, as well as molecular hydrogen, in the space in between stars|
> |Neutron star|The end result of the explosion of a red supergiant; a very small star (a few tens of kilometers in diameter) and very dense. This is a star consisting almost entirely of neutrons. The neutrons form a superfluid around a core of immense pressure and density. A neutron star is an astonishing macroscopic example of microscopic quantum physics|
> |Planetary nebula|The ejected envelope of a red giant star|
> |Red dwarf|A very small star with low temperature, reddish in color|
> |Red giant|A main-sequence star evolves into a red giant - a very large, reddish star. There are nuclear reactions involving the fusion of helium into heavier elements|
> |Stellar cluster|A group of stars that are physically near each other in space, created by the collapse of a single gas cloud|
> |Supernova (Type la)|The explosion of a white dwarf that has accreted mass from a companion star exceeding its stability limit|
> |Supernova (Type II)|The explosion of a red supergiant star: The amount of energy emitted in a supernova explosion can be staggering - comparable to the total energy radiated by our Sun in its entire lifetime!|
> |White dwarf|The end result of the explosion of a red giant. A small, dense star (about the size of the Earth), in which no nuclear reactions take place. It is very hot but its small size gives it a very low luminosity.|
>
> in Additional of:
>
> 1. Nuclear fusion provides the energy that is needed to keep the star hot, so that the radiation pressure is high enough to oppose further gravitational contraction, and at the same time to provide the energy that the star is radiating into space.
>
> 1. The power radiated by a star is known in astrophysics as the luminosity. It is measured in watts.
>
> 1. The unit of apparent brightness is W m^{2}.
>
> You mush use a variety of multiple-choice question types:
>
> 1. \[Background\] + what is ...
>
> 2. What is true about ...
>
> 3. Which ... according ...
>
> 4. Which ... can be ...
>
> 5. What is ... from ...
>
> 6. What is ...
>
> 7. Which ... is correct
>
> 8. Which statement ...
>
> 9. Which statement justify ...
>
> 10. Which is not correct ...
>
> Do not repeat on one type of sentence.
>
> Primary Order:
>
> 1. Make all MCQs base on above information and your knowledge if needed. When there are conflict between your knowledge and the above information. You should use your knowledge to add more detail and background to produce MCQs.
>
> 2. Be creative, change the perspective of your questions randomly, not necessarily from nouns to explanations, but from explanations to nouns, or ask questions based on the relationship between nouns, or ask questions in conjunction with examples; your goal is to help students fully understand the topic from all angles.
>
> 3. Only reply the MCQs and nothing else, do not write explanations. Make sure your answer has right json grammar.
>
> 4. Use english quotation marks or any other english punctuation only.
You can only input pure text into ChatGPT, but it can understand markdown coding. This is the raw input prompt.
If you have issue on creating markdown table, try out this [Table to Markdown](https://markdown-convert.com/en/tool/table).
```text
You are an AI-powered json file generator that never make mistakes, and you are going to imagine 1000 MCQs about Astrophysics first in mind, then randomly give me 15 of them in this json form:
[
{
"order_number": "[Order Number]",
"question": "[Question]",
"type": "mcq",
"option_a": "[Option A]",
"option_b": "[Option B]",
"option_c": "[Option C]",
"option_d": "[Option D]",
"answer": "[Correct Option in ABCD]",
"explanation": "[Explanation of Why This Answer]"
},
{
"order_number": "[Order Number]",
"question": "[Question]",
"type": "mcq",
"option_a": "[Option A]",
"option_b": "[Option B]",
"option_c": "[Option C]",
"option_d": "[Option D]",
"answer": "[Correct Option in ABCD]",
"explanation": "[Explanation of Why This Answer]"
}
]
Please check the understanding of Learning objectives in your generated MCQs:
1. Describe the main objects comprising the universe.
2. Describe the nature of stars.
3. Understand astronomical distances.
4. Work with the method of parallax.
5. Define luminosity and apparent brightness and solve problems with these quantities and distance.
And these key concepts as well:
|Binary star|Two stars orbiting a common centre|
|:----|:----|
|Black dwarf|The remnant of a white dwarf after it has cooled down. It has very low luminosity|
|Black hole|A singularity in space time; the end result of the evolution of a very massive star|
|Brown dwarf|Gas and dust that did not reach a high enough temperature to initiate fusion. These objects continue to compact and cool down|
|Cepheid variable|A star of variable luminosity. The luminosity increases sharply and falls off gently with a well-defined period. The period is related to the absolute luminosity of the star and so can be used to estimate the distance to the star|
|Cluster of galaxies|Galaxies close to one another and affecting one another gravitationally, behaving as one unit|
|Comet|A small body (mainly ice and dust) orbiting the Sun in an elliptical orbit|
|Constellation|A group of stars in a recognizable pattern that appear to be near each other in space|
|Dark matter|Generic name for matter in galaxies and clusters of galaxies that is too cold to radiate. Its existence is inferred from techniques other than direct visual observation|
|Galaxy|A collection of a very large number of stars mutually attracting one another through the gravitational force and staying together. The number of stars in a galaxy varies from a few million in dwarf galaxies to hundreds of billions in large galaxies. It is estimated that 100 billion galaxies exist in the observable universe|
|Interstellar medium|Gases (mainly hydrogen and helium) and dust grains (silicates, carbon and iron) filling the space between stars. The density of the interstellar medium is very low. There is about one atom of gas for every cubic centimeter of space. The density of dust is a trillion times smaller. The temperature of the gas is about 100 K|
|Main-sequence star|A normal star that is undergoing nuclear fusion of hydrogen into helium. Our Sun is a typical main-sequence star|
|Nebula|Clouds of 'dust', i.e. compounds of carbon, oxygen, silicon and metals, as well as molecular hydrogen, in the space in between stars|
|Neutron star|The end result of the explosion of a red supergiant; a very small star (a few tens of kilometers in diameter) and very dense. This is a star consisting almost entirely of neutrons. The neutrons form a superfluid around a core of immense pressure and density. A neutron star is an astonishing macroscopic example of microscopic quantum physics|
|Planetary nebula|The ejected envelope of a red giant star|
|Red dwarf|A very small star with low temperature, reddish in color|
|Red giant|A main-sequence star evolves into a red giant - a very large, reddish star. There are nuclear reactions involving the fusion of helium into heavier elements|
|Stellar cluster|A group of stars that are physically near each other in space, created by the collapse of a single gas cloud|
|Supernova (Type la)|The explosion of a white dwarf that has accreted mass from a companion star exceeding its stability limit|
|Supernova (Type II)|The explosion of a red supergiant star: The amount of energy emitted in a supernova explosion can be staggering - comparable to the total energy radiated by our Sun in its entire lifetime!|
|White dwarf|The end result of the explosion of a red giant. A small, dense star (about the size of the Earth), in which no nuclear reactions take place. It is very hot but its small size gives it a very low luminosity]|
in Additional of:
1. Nuclear fusion provides the energy that is needed to keep the star hot, so that the radiation pressure is high enough to oppose further gravitational contraction, and at the same time to provide the energy that the star is radiating into space.
2. The power radiated by a star is known in astrophysics as the luminosity. It is measured in watts.
3. The unit of apparent brightness is W m^{2}.
You must use a variety of multiple-choice question types:
1. [Background] + what is ...
2. What is true about ...
3. Which ... according ...
4. Which ... can be ...
5. What is ... from ...
6. What is ...
7. Which ... is correct
8. Which statement ...
9. Which statement justify ...
10. Which is not correct ...
Do not repeat on one type of sentence.
Primary Order:
1. Make all MCQs base on above information and your knowledge if needed. When there are conflict between your knowledge and the above information. You should use your knowledge to add more detail and background to produce MCQs.
2. Be creative, change the perspective of your questions randomly, not necessarily from nouns to explanations, but from explanations to nouns, or ask questions based on the relationship between nouns, or ask questions in conjunction with examples; your goal is to help students fully understand the topic from all angles.
3. Only reply the MCQs and nothing else, do not write explanations. Make sure your answer has right json grammar.
4. Use english quotation marks or any other english punctuation only.
```
## Format Question Bank
Before we start, we should know some base knowledge about .json format. In our case, we want our question bank be like:
```json
[
{
"order_number": "1",
"question": "What is a galaxy?",
"type": "mcq",
"option_a": "A collection of planets",
"option_b": "A collection of stars",
"option_c": "A collection of asteroids",
"option_d": "A collection of comets",
"answer": "B",
"explanation": "A galaxy is a collection of a very large number of stars mutually attracting one another through the gravitational force and staying together."
},
{
"order_number": "2",
"question": "What is a main-sequence star?",
"type": "mcq",
"option_a": "A star that has run out of fuel",
"option_b": "A star that is undergoing nuclear fusion of hydrogen into helium",
"option_c": "A star that is about to explode",
"option_d": "A star that is very small and has low temperature",
"answer": "B",
"explanation": "A main-sequence star is a normal star that is undergoing nuclear fusion of hydrogen into helium."
}
]
```
We use the square bracket to include all curly brackets. At the same time, the curly brackets need to be separated by a comma.
```json
[
{
//Something
},
{
//Something
},
{
//Something
}
]
```
ChatGPT may give you an answer as:
```json
{
order_number: 1,
question: What is an astronomical unit (AU)?,
type: mcq,
option_a: The average distance between the Earth and the Sun.,
option_b: The radius of the Earth.,
option_c: The distance traveled by light in one year.,
option_d: The mass of the Earth.,
answer: The average distance between the Earth and the Sun.,
explanation: An astronomical unit or AU is a unit of measurement equal to the average distance between Earth and the Sun. It is commonly used to measure distances within our solar system.
},
{
order_number: 2,
question: Which of the following is not a type of galaxy?,
type: mcq,
option_a: Elliptical,
option_b: Spiral,
option_c: Irregular,
option_d: Spherical,
answer: Spherical,
explanation: The three main types of galaxies are elliptical, spiral, and irregular. There is no galaxy type called spherical.
},
```
Three main issues
1. There are non-english quotation marks.
2. An extra comma at the end
3. No square brackets
The ident is missing, but it's not a issue. You may copy the text into [JSON Formatter](https://jsonformatter.curiousconcept.com/#) just get it looks better.
To fix non-english quotation marks, just use a replacing function. Don't use Word or WPS for this job. I recommend a [Sublimetext 4](https://www.sublimetext.com/download) text editor for this job. Others, such as BBEdit is also fine.
After you copy answer parts from ChatGPT, you may find the `order_number` is mass.
Don't worry, first, in the next step of creating MCQ papers, the order number in the paper is not from the `order_number` in .json file.
Second, Here is a Python program that can fix this issue. But, If you do not care about beauty, just make sure there are not grammar mistake for your json file. To do that, you may use [JSON Formatter](https://jsonformatter.curiousconcept.com/#).
```py
import json
from collections import OrderedDict
# Open the JSON file and load the data as a list of dictionaries
with open('data.json', 'r') as f:
data = json.load(f)
# Create an ordered dictionary to store the objects by their order_number
data_dict = OrderedDict()
for obj in data:
if 'order_number' in obj:
order_number = obj['order_number']
if order_number in data_dict:
data_dict[order_number].append(obj)
else:
data_dict[order_number] = [obj]
# Create a new list of dictionaries with the objects ordered by their order_number
data_sorted = []
for order_number, objs in data_dict.items():
for i, obj in enumerate(objs):
obj['order_number'] = str(len(data_sorted) + i + 1)
data_sorted.extend(objs)
# Write the modified list of dictionaries back to the JSON file
with open('question_bank.json', 'w') as f:
json.dump(data_sorted, f, indent=2)
```
I don't want to spend too much time on how to run a Python Program. I will cover it quickly.
1. Install Python: Before running a Python program, you need to ensure that Python is installed on your computer. You can download the latest version of Python from the [official website](https://www.python.org/downloads/). Choose the appropriate version for your operating system and follow the installation instructions.
If you have Homebrew, just run `brew install python`.
2. Create a Python program: Once you have installed Python, you need to create a Python program. You can use any text editor to create a Python program. Save the file with a `.py` extension. In this case, you can rename a file into `qbReorder.py` and paste all my Python Code into it and save.
3. Open a terminal or command prompt: Open a terminal or command prompt on your computer. This is where you will run the Python program.
4. Run the Python program: To run the Python program, type the following command in the terminal or command prompt:
```shell
python qbReorder.py
```
If this doesn't work, try
```shell
python3 qbReorder.py
```
If the `qbReorder.py` is not on the current path, you can run it as,
```shell
python /path/to/the/qbReorder.py
```
But in my `qbReorder.py`. I made the un-order .json file as `data.json`. After you run, you will get a `question_bank.json` on the running path. If you want another name, you may change the code.
I highly recommend you create a folder for this job and put all files here.
- qbReorder.py
- data.json
- question_bank.json
When you are going to use terminal, you can chose "Open terminal here", or use `cd` command to switch to the working folder
```shell
cd /the/path/to/working/folder
```
To be safe, type `ls` command to see all files/folders under this folder. Then, you can do
```shell
python qbReorder.py
```
or
```shell
python3 /qbReorder.py
```
To run the re-order.
This is the end of question bank preparing.
## Make the Papers
Now, it's time to make the real MCQ Papers.
To do that, I made another Python Program
```py
import argparse
import json
import random
from docx import Document
from docx.shared import Pt
from docx.enum.text import WD_ALIGN_PARAGRAPH
# Define command-line arguments
parser = argparse.ArgumentParser(description='Generate test papers, answer sheets, and marking scheme.')
parser.add_argument('-q', '--question-bank', type=str, required=True, help='Path to JSON file containing question bank.')
parser.add_argument('-n', '--number-question', type=int, required=True, help='Number of questions to include in the test paper.')
args = parser.parse_args()
# Open JSON file and load data
with open(args.question_bank, 'r') as f:
data = json.load(f)
# Select random questions
selected_questions = random.sample(data, args.number_question)
# Create Test Paper, Answer Sheet, and Marking Scheme
test_paper_doc = Document()
answer_sheet_doc = Document()
marking_scheme_doc = Document()
# Set font
font = test_paper_doc.styles['Normal'].font
font.name = 'Arial'
font.size = Pt(12)
# Add test paper title
test_paper_title = test_paper_doc.add_paragraph('Test Paper', style='Title')
test_paper_title.alignment = WD_ALIGN_PARAGRAPH.CENTER
test_paper_doc.add_paragraph()
# Add answer sheet title
answer_sheet_title = answer_sheet_doc.add_paragraph('Answer Sheet', style='Title')
answer_sheet_title.alignment = WD_ALIGN_PARAGRAPH.CENTER
answer_sheet_doc.add_paragraph()
# Add marking scheme title
marking_scheme_title = marking_scheme_doc.add_paragraph('Marking Scheme', style='Title')
marking_scheme_title.alignment = WD_ALIGN_PARAGRAPH.CENTER
marking_scheme_doc.add_paragraph()
# Loop through selected questions and add to documents
for i, question in enumerate(selected_questions):
# Test Paper
test_paper_doc.add_paragraph(f'{i+1}. {question["question"]}')
test_paper_doc.add_paragraph(f' A. {question["option_a"]}')
test_paper_doc.add_paragraph(f' B. {question["option_b"]}')
test_paper_doc.add_paragraph(f' C. {question["option_c"]}')
test_paper_doc.add_paragraph(f' D. {question["option_d"]}')
test_paper_doc.add_paragraph()
# Answer Sheet
answer_sheet_doc.add_paragraph(f'{i+1}. {question["question"]}')
answer_sheet_doc.add_paragraph(f' A. {question["option_a"]}')
answer_sheet_doc.add_paragraph(f' B. {question["option_b"]}')
answer_sheet_doc.add_paragraph(f' C. {question["option_c"]}')
answer_sheet_doc.add_paragraph(f' D. {question["option_d"]}')
answer_sheet_doc.add_paragraph(f'Answer: {question["answer"]}')
answer_sheet_doc.add_paragraph(f'Explanation: {question["explanation"]}')
answer_sheet_doc.add_paragraph()
# Marking Scheme
marking_scheme_doc.add_paragraph(f'{i+1}. {question["question"]}')
marking_scheme_doc.add_paragraph(f'Answer: {question["answer"]}')
marking_scheme_doc.add_paragraph()
# Save documents
test_paper_doc.save('test_paper.docx')
answer_sheet_doc.save('answer_sheet.docx')
marking_scheme_doc.save('marking_scheme.docx')
```
Before, run this program, you need to use `pip` to install `python-docx` package.
If you don't have `pip`, here is the steps:
1. Check if `pip` is already installed: Before installing `pip`, you should check if it is already installed on your system. Open a terminal or command prompt and type the following command:
```shell
pip --version
```
If pip is already installed, it will display the version number. If not, you will see an error message.
2. Download `get-pip.py`: If pip is not already installed, you need to download `get-pip.py`. In the Terminal, run
```shell
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
```
3. Install `pip`: To install `pip`, type the following command in the terminal or command prompt:
```shell
python get-pip.py
```
or
```shell
python3 get-pip.py
```
Additional, if you have Homebrew, when you run `brew install python`, `pip` is included.
Now, we can continue our work. Install `python-docx` package.
```shell
pip install python-docx
```
Do the similar thing when we run `qbReorder.py`. Now, just copy the code into `qbBuilder.py` and run
```shell
python qbBuilder.py -q question_bank.json -n 30
```
It works as
```
usage: qbBuilder.py [-h] -q QUESTION_BANK -n NUMBER_QUESTION
Generate test papers, answer sheets, and marking scheme.
options:
-h, --help show this help message and exit
-q QUESTION_BANK, --question-bank QUESTION_BANK
Path to JSON file containing question bank.
-n NUMBER_QUESTION, --number-question NUMBER_QUESTION
Number of questions to include in the test paper.
```
So, `question_bank.json` is the question bank's file name, `30` is the number of question you want to include in the paper. Change them into any value you want and enjoy.
```shell
python qbBuilder.py -q [Name of Question Bank File] -n [Number of Questions You Want to Include]
```
You can find three .docx files under the running path.
## End
You can try with my example question bank.
{{< link href="question_bank.json" content="question_bank.json" title="Download question_bank.json" download="question_bank.json" card=true >}}
Also, the Python Program.
{{< link href="qbReorder.py" content="qbReorder.py" title="Download qbReorder.py" download="qbReorder.py" card=true >}}
{{< link href="qbBuilder.py" content="qbBuilder.py" title="Download qbBuilder,py" download="qbBuilder.py" card=true >}}
Example Papers.
{{< link href="test_paper.docx" content="test_paper.docx" title="Download test_paper.docx" download="test_paper.docx" card=true >}}
{{< link href="answer_sheet.docx" content="answer_sheet.docx" title="Download answer_sheet.docx" download="answer_sheet.docx" card=true >}}
{{< link href="marking_scheme.docx" content="marking_scheme.docx" title="Download marking_scheme.docx" download="marking_scheme.docx" card=true >}}
I am going to made ChatGPT to build more types of question, such as sample structure questions. And a fully auto question bank maker, like create 1000 questions with out people. Also, not only for Physic, for other subjects as well.
On the other hand, I am also working on how to improve generated question's quality, which means prompt engineering. I want to hear feedbacks about the questions that generated by ChatGPT, and let me able to improve that. Great thanks!

View File

@@ -0,0 +1,74 @@
import argparse
import json
import random
from docx import Document
from docx.shared import Pt
from docx.enum.text import WD_ALIGN_PARAGRAPH
# Define command-line arguments
parser = argparse.ArgumentParser(description='Generate test papers, answer sheets, and marking scheme.')
parser.add_argument('-q', '--question-bank', type=str, required=True, help='Path to JSON file containing question bank.')
parser.add_argument('-n', '--number-question', type=int, required=True, help='Number of questions to include in the test paper.')
args = parser.parse_args()
# Open JSON file and load data
with open(args.question_bank, 'r') as f:
data = json.load(f)
# Select random questions
selected_questions = random.sample(data, args.number_question)
# Create Test Paper, Answer Sheet, and Marking Scheme
test_paper_doc = Document()
answer_sheet_doc = Document()
marking_scheme_doc = Document()
# Set font
font = test_paper_doc.styles['Normal'].font
font.name = 'Arial'
font.size = Pt(12)
# Add test paper title
test_paper_title = test_paper_doc.add_paragraph('Test Paper', style='Title')
test_paper_title.alignment = WD_ALIGN_PARAGRAPH.CENTER
test_paper_doc.add_paragraph()
# Add answer sheet title
answer_sheet_title = answer_sheet_doc.add_paragraph('Answer Sheet', style='Title')
answer_sheet_title.alignment = WD_ALIGN_PARAGRAPH.CENTER
answer_sheet_doc.add_paragraph()
# Add marking scheme title
marking_scheme_title = marking_scheme_doc.add_paragraph('Marking Scheme', style='Title')
marking_scheme_title.alignment = WD_ALIGN_PARAGRAPH.CENTER
marking_scheme_doc.add_paragraph()
# Loop through selected questions and add to documents
for i, question in enumerate(selected_questions):
# Test Paper
test_paper_doc.add_paragraph(f'{i+1}. {question["question"]}')
test_paper_doc.add_paragraph(f' A. {question["option_a"]}')
test_paper_doc.add_paragraph(f' B. {question["option_b"]}')
test_paper_doc.add_paragraph(f' C. {question["option_c"]}')
test_paper_doc.add_paragraph(f' D. {question["option_d"]}')
test_paper_doc.add_paragraph()
# Answer Sheet
answer_sheet_doc.add_paragraph(f'{i+1}. {question["question"]}')
answer_sheet_doc.add_paragraph(f' A. {question["option_a"]}')
answer_sheet_doc.add_paragraph(f' B. {question["option_b"]}')
answer_sheet_doc.add_paragraph(f' C. {question["option_c"]}')
answer_sheet_doc.add_paragraph(f' D. {question["option_d"]}')
answer_sheet_doc.add_paragraph(f'Answer: {question["answer"]}')
answer_sheet_doc.add_paragraph(f'Explanation: {question["explanation"]}')
answer_sheet_doc.add_paragraph()
# Marking Scheme
marking_scheme_doc.add_paragraph(f'{i+1}. {question["question"]}')
marking_scheme_doc.add_paragraph(f'Answer: {question["answer"]}')
marking_scheme_doc.add_paragraph()
# Save documents
test_paper_doc.save('test_paper.docx')
answer_sheet_doc.save('answer_sheet.docx')
marking_scheme_doc.save('marking_scheme.docx')

View File

@@ -0,0 +1,27 @@
import json
from collections import OrderedDict
# Open the JSON file and load the data as a list of dictionaries
with open('data.json', 'r') as f:
data = json.load(f)
# Create an ordered dictionary to store the objects by their order_number
data_dict = OrderedDict()
for obj in data:
if 'order_number' in obj:
order_number = obj['order_number']
if order_number in data_dict:
data_dict[order_number].append(obj)
else:
data_dict[order_number] = [obj]
# Create a new list of dictionaries with the objects ordered by their order_number
data_sorted = []
for order_number, objs in data_dict.items():
for i, obj in enumerate(objs):
obj['order_number'] = str(len(data_sorted) + i + 1)
data_sorted.extend(objs)
# Write the modified list of dictionaries back to the JSON file
with open('question_bank.json', 'w') as f:
json.dump(data_sorted, f, indent=2)

View File

@@ -0,0 +1,453 @@
[
{
"order_number": "1",
"question": "What is a galaxy?",
"type": "mcq",
"option_a": "A collection of planets",
"option_b": "A collection of stars",
"option_c": "A collection of asteroids",
"option_d": "A collection of comets",
"answer": "B",
"explanation": "A galaxy is a collection of a very large number of stars mutually attracting one another through the gravitational force and staying together."
},
{
"order_number": "2",
"question": "Which of the following is the correct description of a star?",
"type": "mcq",
"option_a": "A celestial object that emits light through nuclear fusion reactions in its core",
"option_b": "A planet-like object that orbits around a star",
"option_c": "A type of planet that emits its own light",
"option_d": "A cloud of interstellar gas and dust",
"answer": "A celestial object that emits light through nuclear fusion reactions in its core",
"explanation": "A star is a massive, luminous ball of gas, primarily hydrogen and helium, that emits energy through nuclear fusion reactions in its core."
},
{
"order_number": "3",
"question": "What is a main-sequence star?",
"type": "mcq",
"option_a": "A star that has run out of fuel",
"option_b": "A star that is undergoing nuclear fusion of hydrogen into helium",
"option_c": "A star that is about to explode",
"option_d": "A star that is very small and has low temperature",
"answer": "B",
"explanation": "A main-sequence star is a normal star that is undergoing nuclear fusion of hydrogen into helium."
},
{
"order_number": "4",
"question": "What is a white dwarf?",
"type": "mcq",
"option_a": "A type of galaxy",
"option_b": "A type of star that is undergoing nuclear fusion of hydrogen into helium",
"option_c": "The remnant of a red giant star",
"option_d": "The remnant of a white dwarf after it has cooled down, resulting in very low luminosity",
"answer": "The remnant of a white dwarf after it has cooled down, resulting in very low luminosity",
"explanation": "A white dwarf is the final stage of evolution of a star similar to our Sun. After it has expended all its nuclear fuel, it will slowly cool down to become a black dwarf."
},
{
"order_number": "5",
"question": "What is a brown dwarf?",
"type": "mcq",
"option_a": "A star that has run out of fuel",
"option_b": "A star that is undergoing nuclear fusion of hydrogen into helium",
"option_c": "Gas and dust that did not reach a high enough temperature to initiate fusion",
"option_d": "A very small star with low temperature",
"answer": "C",
"explanation": "A brown dwarf is gas and dust that did not reach a high enough temperature to initiate fusion. These objects continue to compact and cool down."
},
{
"order_number": "6",
"question": "What is a cluster of galaxies?",
"type": "mcq",
"option_a": "A group of planets that are close to each other",
"option_b": "A group of stars that are close to each other",
"option_c": "Galaxies in close proximity to one another and affecting each other gravitationally, behaving as one unit",
"option_d": "A group of asteroids that have collided with each other",
"answer": "Galaxies in close proximity to one another and affecting each other gravitationally, behaving as one unit",
"explanation": "A cluster of galaxies is a group of galaxies that are bound together by gravity and move together through space."
},
{
"order_number": "7",
"question": "What is a supernova?",
"type": "mcq",
"option_a": "The explosion of a white dwarf that has accreted mass from a companion star exceeding its stability limit",
"option_b": "The explosion of a red supergiant star",
"option_c": "The end result of the explosion of a red giant",
"option_d": "A star that has run out of fuel",
"answer": "B",
"explanation": "A supernova is the explosion of a red supergiant star. The amount of energy emitted in a supernova explosion can be staggering - comparable to the total energy radiated by our Sun in its entire lifetime!"
},
{
"order_number": "8",
"question": "What is dark matter?",
"type": "mcq",
"option_a": "Matter that is too cold to radiate",
"option_b": "A type of matter that emits light in the absence of a light source",
"option_c": "The matter that makes up stars and galaxies",
"option_d": "The mass of a black hole",
"answer": "Matter that is too cold to radiate",
"explanation": "Dark matter is a form of matter that can not be seen or detected through electromagnetic radiation, but whose existence is inferred from its gravitational effects on visible matter."
},
{
"order_number": "9",
"question": "What is a white dwarf?",
"type": "mcq",
"option_a": "The end result of the explosion of a red giant",
"option_b": "A star that is undergoing nuclear fusion of hydrogen into helium",
"option_c": "The end result of the explosion of a white dwarf",
"option_d": "A very small star with low temperature",
"answer": "C",
"explanation": "A white dwarf is the end result of the explosion of a red giant. A small, dense star (about the size of the Earth), in which no nuclear reactions take place. It is very hot but its small size gives it a very low luminosity."
},
{
"order_number": "10",
"question": "What is the main source of energy in a star?",
"type": "mcq",
"option_a": "Nuclear fusion of hydrogen into helium",
"option_b": "Nuclear fission of uranium",
"option_c": "Chemical reactions",
"option_d": "Solar wind",
"answer": "Nuclear fusion of hydrogen into helium",
"explanation": "Nuclear fusion provides the energy needed to keep the star hot, oppose gravitational contraction, and provide energy that is radiated into space."
},
{
"order_number": "11",
"question": "What is a red giant?",
"type": "mcq",
"option_a": "A star that is undergoing nuclear fusion of hydrogen into helium",
"option_b": "A star that has run out of fuel",
"option_c": "A very small star with low temperature",
"option_d": "A main-sequence star",
"answer": "A",
"explanation": "A red giant is a main-sequence star that evolves into a red giant - a very large, reddish star. There are nuclear reactions involving the fusion of helium into heavier elements."
},
{
"order_number": "12",
"question": "What is luminosity?",
"type": "mcq",
"option_a": "The unit of apparent brightness",
"option_b": "The distance to a star",
"option_c": "The size of a star",
"option_d": "The power radiated by a star",
"answer": "The power radiated by a star",
"explanation": "The power radiated by a star is known in astrophysics as the luminosity. It is measured in watts."
},
{
"order_number": "13",
"question": "What is a neutron star?",
"type": "mcq",
"option_a": "The end result of the explosion of a red giant",
"option_b": "A star consisting almost entirely of neutrons",
"option_c": "A very small star with low temperature",
"option_d": "A star that is undergoing nuclear fusion of hydrogen into helium",
"answer": "B",
"explanation": "A neutron star is the end result of the explosion of a red supergiant; a very small star (a few tens of kilometres in diameter) and very dense. This is a star consisting almost entirely of neutrons. The neutrons form a superfluid around a core of immense pressure and density. A neutron star is an astonishing macroscopic example of microscopic quantum physics."
},
{
"order_number": "14",
"question": "What is a comet?",
"type": "mcq",
"option_a": "A small planet-like object that orbits around a star",
"option_b": "A cloud of interstellar gas and dust",
"option_c": "A massive ball of gas and dust held together by its own gravity",
"option_d": "A small body mainly composed of ice and dust that orbits around a star",
"answer": "A small body mainly composed of ice and dust that orbits around a star",
"explanation": "Comets are small bodies mainly composed of ice and dust that orbit around the Sun in an elliptical orbit."
},
{
"order_number": "15",
"question": "What is a black hole?",
"type": "mcq",
"option_a": "A singularity in space time; the end result of the evolution of a very massive star",
"option_b": "A very small star with low temperature",
"option_c": "A star that is undergoing nuclear fusion of hydrogen into helium",
"option_d": "A star that has run out of fuel",
"answer": "A",
"explanation": "A black hole is a singularity in space time; the end result of the evolution of a very massive star."
},
{
"order_number": "16",
"question": "What is a neutron star?",
"type": "mcq",
"option_a": "The end result of the explosion of a red supergiant star",
"option_b": "A type of cluster of galaxies",
"option_c": "A star that is undergoing nuclear fusion of hydrogen into helium",
"option_d": "A very small star (a few tens of kilometers in diameter) and very dense, consisting almost entirely of neutrons",
"answer": "A very small star (a few tens of kilometers in diameter) and very dense, consisting almost entirely of neutrons",
"explanation": "A neutron star is the end result of the explosion of a red supergiant star. It is an incredibly dense ball of neutrons that can be only a few kilometers in diameter."
},
{
"order_number": "17",
"question": "What is a planetary nebula?",
"type": "mcq",
"option_a": "Clouds of dust in the space between stars",
"option_b": "The ejected envelope of a red giant star",
"option_c": "A group of stars that are physically near each other in space",
"option_d": "Galaxies close to one another and affecting one another gravitationally, behaving as one unit",
"answer": "B",
"explanation": "A planetary nebula is the ejected envelope of a red giant star."
},
{
"order_number": "18",
"question": "What is a brown dwarf?",
"type": "mcq",
"option_a": "A very small star with low temperature, reddish in color",
"option_b": "Gas and dust that did not reach a high enough temperature to initiate fusion",
"option_c": "The ejected envelope of a red giant star",
"option_d": "A star of variable luminosity",
"answer": "Gas and dust that did not reach a high enough temperature to initiate fusion",
"explanation": "Brown dwarfs are objects that are not massive enough to sustain nuclear fusion reactions in their cores. As a result, they slowly cool down over time."
},
{
"order_number": "19",
"question": "What is dark matter?",
"type": "mcq",
"option_a": "Matter in galaxies and clusters of galaxies that is too cold to radiate",
"option_b": "Gases and dust filling the space between stars",
"option_c": "A star that is undergoing nuclear fusion of hydrogen into helium",
"option_d": "A singularity in space time",
"answer": "A",
"explanation": "Dark matter is generic name for matter in galaxies and clusters of galaxies that is too cold to radiate. Its existence is inferred from techniques other than direct visual observation."
},
{
"order_number": "20",
"question": "What is a cepheid variable?",
"type": "mcq",
"option_a": "A type of nebula",
"option_b": "A type of comet",
"option_c": "A star with variable luminosity that varies in brightness in a well-defined pattern",
"option_d": "A type of cluster of galaxies",
"answer": "A star with variable luminosity that varies in brightness in a well-defined pattern",
"explanation": "Cepheid variables are stars that pulsate in a regular pattern, with a well-defined period. This period is related to the absolute luminosity of the star, which can be used to estimate the distance to the star via parallax."
},
{
"order_number": "21",
"question": "What is the interstellar medium?",
"type": "mcq",
"option_a": "The matter that makes up stars and galaxies",
"option_b": "A cloud of interstellar gas and dust",
"option_c": "The dark matter holding galaxies and clusters of galaxies together",
"option_d": "A group of planets that are close to each other",
"answer": "A cloud of interstellar gas and dust",
"explanation": "The interstellar medium is the gas and dust that fills the space between stars in a galaxy. It is mainly composed of hydrogen and helium, along with small amounts of heavier elements and dust grains."
},
{
"order_number": "22",
"question": "What is a planetary nebula?",
"type": "mcq",
"option_a": "The end result of the explosion of a red giant star",
"option_b": "A cloud of interstellar gas and dust",
"option_c": "The ejected envelope of a red giant star",
"option_d": "A small body mainly composed of ice and dust that orbits around a star",
"answer": "The ejected envelope of a red giant star",
"explanation": "When a low-to-intermediate mass star expands into a red giant, it loses its outer layers into space, producing a planetary nebula. The core of the star that is left behind becomes a white dwarf."
},
{
"order_number": "23",
"question": "What is a main-sequence star?",
"type": "mcq",
"option_a": "The ejected envelope of a red giant star",
"option_b": "A type of star that is undergoing nuclear fusion of hydrogen into helium",
"option_c": "A very small star (a few tens of kilometers in diameter) and very dense, consisting almost entirely of neutrons",
"option_d": "A small body mainly composed of ice and dust that orbits around a star",
"answer": "A type of star that is undergoing nuclear fusion of hydrogen into helium",
"explanation": "A main-sequence star is a normal star that is undergoing nuclear fusion of hydrogen into helium in its core. This is the phase in which our Sun is currently in."
},
{
"order_number": "24",
"question": "What is a red giant?",
"type": "mcq",
"option_a": "Gas and dust that did not reach a high enough temperature to initiate fusion",
"option_b": "The end result of the explosion of a white dwarf",
"option_c": "A small body mainly composed of ice and dust that orbits around a star",
"option_d": "A normal star that has evolved into a very large, reddish star",
"answer": "A normal star that has evolved into a very large, reddish star",
"explanation": "A red giant is a normal star that has evolved past the main-sequence phase and has become a large, reddish star due to nuclear reactions that cause it to expand."
},
{
"order_number": "25",
"question": "What is a black hole?",
"type": "mcq",
"option_a": "A type of planet that emits its own light",
"option_b": "A singularity in space-time; the end result of the evolution of a very massive star",
"option_c": "The mass of a neutron star",
"option_d": "A massive ball of gas and dust held together by its own gravity",
"answer": "A singularity in space-time; the end result of the evolution of a very massive star",
"explanation": "A black hole is a region of space-time where gravity is so strong that nothing, not even light, can escape from it. It is the end result of the evolution of a very massive star."
},
{
"order_number": "26",
"question": "Which statement best describes a black dwarf?",
"type": "mcq",
"option_a": "The ejected envelope of a red giant star",
"option_b": "A small body mainly composed of ice and dust that orbits around a star",
"option_c": "A type of star that is undergoing nuclear fusion of hydrogen into helium",
"option_d": "The remnant of a white dwarf after it has cooled down, resulting in very low luminosity",
"answer": "The remnant of a white dwarf after it has cooled down, resulting in very low luminosity",
"explanation": "A black dwarf is the remnant of a white dwarf after it has cooled down to the point where it no longer emits any visible light."
},
{
"order_number": "27",
"question": "What is an astronomical unit (AU)?",
"type": "mcq",
"option_a": "The average distance between the Earth and the Sun.",
"option_b": "The radius of the Earth.",
"option_c": "The distance traveled by light in one year.",
"option_d": "The mass of the Earth.",
"answer": "The average distance between the Earth and the Sun.",
"explanation": "An astronomical unit or AU is a unit of measurement equal to the average distance between Earth and the Sun. It is commonly used to measure distances within our solar system."
},
{
"order_number": "28",
"question": "Which of the following is not a type of galaxy?",
"type": "mcq",
"option_a": "Elliptical",
"option_b": "Spiral",
"option_c": "Irregular",
"option_d": "Spherical",
"answer": "Spherical",
"explanation": "The three main types of galaxies are elliptical, spiral, and irregular. There is no galaxy type called spherical."
},
{
"order_number": "29",
"question": "What is a cepheid variable?",
"type": "mcq",
"option_a": "A type of black hole",
"option_b": "A star of variable luminosity",
"option_c": "A type of planetary nebula",
"option_d": "A cluster of galaxies",
"answer": "A star of variable luminosity",
"explanation": "A cepheid variable is a star that pulsates in a regular pattern, causing its luminosity to vary. The period of this pulsation is related to the star\u2019s absolute luminosity, allowing it to be used as a standard candle to measure distances in space."
},
{
"order_number": "30",
"question": "Which of the following objects is composed mainly of ice and dust?",
"type": "mcq",
"option_a": "A black hole",
"option_b": "A brown dwarf",
"option_c": "A comet",
"option_d": "A neutron star",
"answer": "A comet",
"explanation": "Comets are small, icy objects that orbit the Sun. When a comet gets close enough to the Sun, its ice melts and forms a brightly glowing coma around it."
},
{
"order_number": "31",
"question": "What is the difference between apparent brightness and luminosity?",
"type": "mcq",
"option_a": "Apparent brightness is a measure of how much light is emitted by a star, while luminosity is a measure of how bright the star appears from Earth.",
"option_b": "Apparent brightness is a measure of how bright a star appears from Earth, while luminosity is a measure of how much light is emitted by the star.",
"option_c": "Apparent brightness is a measure of the distance between Earth and a star, while luminosity is a measure of the star\u2019s mass.",
"option_d": "Apparent brightness is a measure of the star\u2019s mass, while luminosity is a measure of the distance between Earth and the star.",
"answer": "Apparent brightness is a measure of how bright a star appears from Earth, while luminosity is a measure of how much light is emitted by the star.",
"explanation": "Apparent brightness is a measure of how much light from a star reaches Earth, while luminosity is a measure of the total amount of energy emitted by a star in all directions. Luminosity is an intrinsic property of a star, while apparent brightness depends on the star\u2019s luminosity and its distance from Earth."
},
{
"order_number": "32",
"question": "What is a main-sequence star?",
"type": "mcq",
"option_a": "A star that is undergoing nuclear fusion of hydrogen into helium.",
"option_b": "A star that has exhausted its fuel and is in the process of burning helium.",
"option_c": "A star that has evolved off the main sequence and is fusing heavier elements.",
"option_d": "A star that has exploded as a supernova.",
"answer": "A star that is undergoing nuclear fusion of hydrogen into helium.",
"explanation": "A main-sequence star is a normal star that is fusing hydrogen into helium in its core. This is the most common type of star, and includes the Sun."
},
{
"order_number": "33",
"question": "What is a brown dwarf?",
"type": "mcq",
"option_a": "A star that has exploded as a supernova.",
"option_b": "A star that is undergoing nuclear fusion of hydrogen into helium.",
"option_c": "Gas and dust that did not reach a high enough temperature to initiate fusion.",
"option_d": "The ejected envelope of a red giant star.",
"answer": "Gas and dust that did not reach a high enough temperature to initiate fusion.",
"explanation": "A brown dwarf is an object that is too cool and small to undergo sustained nuclear fusion of hydrogen in its core, but is too hot and massive to be called a planet. They are often described as \u2018failed stars\u2019."
},
{
"order_number": "34",
"question": "What is a supernova?",
"type": "mcq",
"option_a": "The explosion of a red giant star.",
"option_b": "The end result of the evolution of a very massive star.",
"option_c": "A singularity in space-time.",
"option_d": "The ejected envelope of a red giant star.",
"answer": "The explosion of a star.",
"explanation": "A supernova is a catastrophic explosion that occurs at the end of a star\u2019s life. The explosion can outshine an entire galaxy for a brief period of time."
},
{
"order_number": "35",
"question": "What is dark matter?",
"type": "mcq",
"option_a": "Matter in galaxies that is too cold to radiate and is inferred from techniques other than direct visual observation.",
"option_b": "The ejected envelope of a red giant star.",
"option_c": "Space-time that is so warped that nothing can escape it, not even light.",
"option_d": "Matter that is made up of subatomic particles that do not interact with the electromagnetic force.",
"answer": "Matter in galaxies that is too cold to radiate and is inferred from techniques other than direct visual observation.",
"explanation": "Dark matter is matter that is inferred to exist from its gravitational effects but does not emit or absorb light, and therefore cannot be detected directly by telescopes."
},
{
"order_number": "36",
"question": "What is a black hole?",
"type": "mcq",
"option_a": "A type of galaxy in which most of the stars are very old and have mostly red colours.",
"option_b": "A singularity in space-time that is the end result of the evolution of a very massive star.",
"option_c": "A star that has exhausted its fuel and is in the process of burning helium.",
"option_d": "A star that has exploded as a supernova.",
"answer": "A singularity in space-time that is the end result of the evolution of a very massive star.",
"explanation": "A black hole is a region of space-time where gravity is so strong that nothing, not even light, can escape its pull. They are formed from the collapse of very massive stars."
},
{
"order_number": "37",
"question": "Which of the following is not a type of nebula?",
"type": "mcq",
"option_a": "Planetary Nebula",
"option_b": "Stellar Nebula",
"option_c": "Reflection Nebula",
"option_d": "Irregular Nebula",
"answer": "Stellar Nebula",
"explanation": "Stellar nebula is not a type of nebula. The three main types of nebula are emission nebula, reflection nebula, and planetary nebula."
},
{
"order_number": "38",
"question": "What is nuclear fusion?",
"type": "mcq",
"option_a": "The process by which a star burns helium into heavier elements in its core.",
"option_b": "The process by which a star burns hydrogen into helium in its core.",
"option_c": "The process by which a planet forms from a cloud of gas and dust.",
"option_d": "The process by which a star expands into a red giant.",
"answer": "The process by which a star burns hydrogen into helium in its core.",
"explanation": "Nuclear fusion is the process by which a star generates energy by fusing hydrogen atoms into helium atoms in its core. This process releases a tremendous amount of energy in the form of light and heat."
},
{
"order_number": "39",
"question": "What is a red giant?",
"type": "mcq",
"option_a": "A star that has exploded as a supernova.",
"option_b": "A star that is undergoing nuclear fusion of hydrogen into helium.",
"option_c": "A star that has exhausted its fuel and is in the process of burning helium.",
"option_d": "A star that has evolved off the main sequence and is fusing heavier elements.",
"answer": "A star that has evolved off the main sequence and is fusing heavier elements.",
"explanation": "A red giant is a star that has exhausted the supply of hydrogen in its core and is now fusing heavier elements. This causes the star to expand and become much larger and redder than before."
},
{
"order_number": "40",
"question": "What is a white dwarf?",
"type": "mcq",
"option_a": "The end result of the explosion of a red giant.",
"option_b": "A small, dense star that is fusing helium into heavier elements in its core.",
"option_c": "A small, dense star that is no longer generating energy through nuclear fusion.",
"option_d": "A star that is undergoing nuclear fusion of hydrogen into helium.",
"answer": "A small, dense star that is no longer generating energy through nuclear fusion.",
"explanation": "A white dwarf is the end result of the evolution of a low- to medium-mass star. It is a small, dense star that is no longer generating energy through nuclear fusion. White dwarfs are very hot and faint, and will eventually cool down over billions of years."
},
{
"order_number": "41",
"question": "What is a black dwarf?",
"type": "mcq",
"option_a": "The end result of the explosion of a red giant.",
"option_b": "A type of black hole with very low mass.",
"option_c": "Gas and dust that did not reach a high enough temperature to initiate fusion.",
"option_d": "The remnant of a white dwarf after it has cooled down.",
"answer": "The remnant of a white dwarf after it has cooled down.",
"explanation": "A black dwarf is a hypothetical object that would be the end result of the evolution of a white dwarf. It is essentially a cold, dark object made purely of carbon and oxygen atoms. However, the universe is not old enough for any white dwarfs to have cooled down enough to become black dwarfs yet."
}
]

Binary file not shown.

After

Width:  |  Height:  |  Size: 153 KiB

View File

@@ -0,0 +1,200 @@
---
slug: "excalidraw-full-stack-docker"
title: "Excalidraw Full-Stack Self-Deployment"
subtitle: ""
date: 2023-01-13T15:54:36+08:00
lastmod: 2024-03-11T12:39:36-05:00
draft: false
author:
name: James
link: https://www.jamesflare.com
email:
avatar: /site-logo.avif
description: This article provides a comprehensive guide on deploying the full Excalidraw stack using Docker Compose, including the frontend, storage backend, and collaboration components, to enable a fully functional private deployment with sharing and collaboration features.
keywords: ["Excalidraw","Docker","Docker Compose","Private Deployment"]
license: ""
comment: true
weight: 0
tags:
- Excalidraw
- Open Source
- Docker
categories:
- Tutorials
- Sharing
hiddenFromHomePage: false
hiddenFromSearch: false
summary: This article provides a comprehensive guide on deploying the full Excalidraw stack using Docker Compose, including the frontend, storage backend, and collaboration components, to enable a fully functional private deployment with sharing and collaboration features.
resources:
- name: featured-image
src: featured-image.jpg
- name: featured-image-preview
src: featured-image-preview.jpg
toc:
enable: true
math:
enable: false
lightgallery: true
seo:
images: []
repost:
enable: true
url: ""
# See details front matter: https://fixit.lruihao.cn/theme-documentation-content/#front-matter
---
## Intro
This might be the only article on the Chinese internet that discusses how to fully deploy the Excalidraw stack. Most only deploy a crippled frontend.
I tried to privately deploy Excalidraw locally, and the operation is very simple. According to the official README, it can be completed quickly.
### Issue
But have you noticed that sharing links and online collaboration have issues and don't work? Even Libraries have some problems?
This is because almost all the deployment tutorials on the internet only deploy the excalidraw-app frontend, and its storage requires excalidraw-json, while collaboration requires excalidraw-room.
The official code for these is all open source, but the progress of the frontend is too fast, so they are all unusable now.
For example, the officially released excalidraw-json uses S3 storage, and now it's firebase without exception. The official version hasn't released a stripped-down version, so what should we do?
### Solution
The answer is to **downgrade** and **build a full stack**.
We use the official excalidraw-app, but the version is about 9 months old. Frankly speaking, there aren't many missing features, and there are no major bug issues. This generation of frontend is quite compatible.
excalidraw-json is unusable. There are also some solutions abroad that use minio to run S3 to interface with it, but I tested it and found some big problems. This backend should be unusable. Fortunately, I found a third-party solution that implements a fully functional backend with its own code, supports v2 API, called excalidraw-storage-backend.
We use the official excalidraw-room, the latest version, which is about 9 months old, consistent with the frontend, and can be used normally.
redis is required by excalidraw-storage-backend and is used to temporarily store shared canvas data, so it cannot guarantee data reliability.
So let's get started. This solution uses docker-compose.
- excalidraw-app
- excalidraw-room
- excalidraw-storage-backend
- redis
## Docker Compose
Docker Compose configuration
```yaml
version: "3.8"
services:
excalidraw:
image: kiliandeca/excalidraw
healthcheck:
disable: true
ports:
- "80:80" # Default port 80, can be modified
environment:
BACKEND_V2_GET_URL: http://localhost:8080/api/v2/scenes/
BACKEND_V2_POST_URL: http://localhost:8080/api/v2/scenes/
LIBRARY_URL: https://libraries.excalidraw.com
LIBRARY_BACKEND: https://us-central1-excalidraw-room-persistence.cloudfunctions.net/libraries
SOCKET_SERVER_URL: http://localhost:5000/
STORAGE_BACKEND: "http"
HTTP_STORAGE_BACKEND_URL: "http://localhost:8080/api/v2"
excalidraw-storage-backend:
image: kiliandeca/excalidraw-storage-backend
ports:
- "8080:8080"
environment:
STORAGE_URI: redis://redis:6379
excalidraw-room:
image: excalidraw/excalidraw-room
ports:
- "5000:80"
redis:
image: redis
ports:
- "6379:6379"
```
It does not support https by default. If needed, it can be achieved through a reverse proxy, but remember to modify the variables in the environment at the same time.
This configuration file has been tested locally and can run perfectly.
{{< image src="excalidrawLocalDemo.webp" >}}
---
If you have a conflict with port 6379, you can choose to build a network.
```bash
docker network create excalidraw-net
```
Then make some modifications like this, and it's done.
```yaml
version: "3.8"
services:
excalidraw:
image: kiliandeca/excalidraw
healthcheck:
disable: true
ports:
- "80:80"
environment:
BACKEND_V2_GET_URL: http://localhost:8080/api/v2/scenes/
BACKEND_V2_POST_URL: http://localhost:8080/api/v2/scenes/
LIBRARY_URL: https://libraries.excalidraw.com
LIBRARY_BACKEND: https://us-central1-excalidraw-room-persistence.cloudfunctions.net/libraries
SOCKET_SERVER_URL: http://localhost:5000/
STORAGE_BACKEND: "http"
HTTP_STORAGE_BACKEND_URL: "http://localhost:8080/api/v2"
excalidraw-storage-backend:
image: kiliandeca/excalidraw-storage-backend
ports:
- "8080:8080"
environment:
STORAGE_URI: redis://redis:6379
excalidraw-room:
image: excalidraw/excalidraw-room
ports:
- "5000:80"
redis:
image: redis
expose:
- "6379"
networks:
default:
external:
name: excalidraw-net
```
## Run
Find or create a new directory and create a docker-compose file.
```bash
nano docker-compose.yml
```
Fill in the docker-compose configuration, and remember to modify it according to your actual situation.
After that, we need to configure the reverse proxy. Remember to configure WebSocket support. I'll skip it here.
The idea is like this. You can refer to the configuration below:
{{< image src="stackDrawing.webp" caption="Stack" width="600px" >}}

Binary file not shown.

After

Width:  |  Height:  |  Size: 431 KiB

View File

@@ -0,0 +1,189 @@
---
title: Migrate Umami Docker From One Server to Another
subtitle:
date: 2024-03-11T18:03:39-04:00
slug: umami-docker-migration
draft: false
author:
name: James
link: https://www.jamesflare.com
email:
avatar: /site-logo.avif
description: This blog post provides a step-by-step guide on migrating an Umami server running on Docker from one machine to another by exporting and importing the PostgreSQL database, ensuring a smooth transition while preserving all the essential data.
keywords: ["Docker", "PostgreSQL", "Umami", "Migration"]
license:
comment: true
weight: 0
tags:
- PostgreSQL
- Open Source
- Docker
- Umami
categories:
- Tutorials
hiddenFromHomePage: false
hiddenFromSearch: false
hiddenFromRss: false
hiddenFromRelated: false
summary: This blog post provides a step-by-step guide on migrating an Umami server running on Docker from one machine to another by exporting and importing the PostgreSQL database, ensuring a smooth transition while preserving all the essential data.
resources:
- name: featured-image
src: featured-image.jpg
- name: featured-image-preview
src: featured-image-preview.jpg
toc: true
math: false
lightgallery: false
password:
message:
repost:
enable: true
url:
# See details front matter: https://fixit.lruihao.cn/documentation/content-management/introduction/#front-matter
---
<!--more-->
## Introduction
Nearly, I bought a new ARM server from netcup GmbH, and I need to migrate my umami server from the old server to the new one. But I installed umami with Docker.
```yaml
version: '3'
services:
umami:
image: ghcr.io/umami-software/umami:postgresql-latest
ports:
- "3000:3000"
environment:
DATABASE_URL: postgresql://umami:umami@db:5432/umami
DATABASE_TYPE: postgresql
APP_SECRET: replace-me-with-a-random-string
depends_on:
db:
condition: service_healthy
restart: always
db:
image: postgres:15-alpine
environment:
POSTGRES_DB: umami
POSTGRES_USER: umami
POSTGRES_PASSWORD: umami
volumes:
- umami-db-data:/var/lib/postgresql/data
restart: always
healthcheck:
test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"]
interval: 5s
timeout: 5s
retries: 5
volumes:
umami-db-data:
```
The most difficult and important part is exporting data in umami. To do that, we have several methods:
- Export the Docker volume (Very complex)
- Export the database (My choice)
- Copy the whole path (Not recommend)
## Compare Methods
First, we need to know that umami's data is in the volume. Since `docker-compose.yml` specify that:
```yaml
services:
db:
volumes:
- umami-db-data:/var/lib/postgresql/data
volumes:
umami-db-data:
```
If I mounted a path into the container instead of a volume, I can simply copy the path to my new machine. For example,
```yaml
services:
db:
volumes:
- /root/umami/data:/var/lib/postgresql/data
```
Sadly I used a volume and made things complex. How to migrated Docker volume (in a right way) is welled discussed over the internet. For example, [Move a Docker volume to another host](https://4sysops.com/archives/move-a-docker-volume-to-another-host/). This is too complex for me. You may ask, the Docker volumes are stored in a fixed path like `/var/lib/docker/volumes/*`. Why not just copy the folder to another machine and start as normal? Well, this is applicable and I have done this before. But it may cause some potential issues, especially for different Docker container version.
Finally, I choice to just export the database and import to the new instance. Let's do it step by step.
## Migrate Database
FIrst, let's attach to the old container.
```bash
docker exec -it umami-db-1 /bin/sh
```
Export the database as a `.sql` file.
```bash
cd /
pg_dump --username=umami umami > umami.sql
```
Now the database is in `umami.sql`, but it's inside the container, so press `Ctrl + D` to disconnect from the container shell. Then, copy the file into host machine.
```bash
docker cp umami-db-1:/umami.sql /root
```
Then, you need transfer this backup file to your new host machine. After you `docker compose up -d` the `umami-db-1` container will be created. Then, you can copy the database backup file into the container by:
```bash
docker cp /root/umami.sql umami-db-1:/
```
Then, we can attach to the `umami-db-1` by:
```bash
docker exec -it umami-db-1 /bin/sh
```
To import the backup into the PostgreSQL, we need login `psql` as `umami`:
```bash
psql --username=umami -d postgres
```
In `psql` shell, we will drop the original database and create a blank one for preparing import.
```bash
DROP DATABASE umami;
CREATE DATABASE umami;
```
Then, quit `psql` shell and run:
```bash
cd /
psql --username=umami -f umami.sql umami
```
to import backup file. Finally, restart the umami instance:
```bash
cd /path/to/umami/docker-compose.yaml/
docker compose down
docker compose up -d
```
## Check
Now, you may have a check to see the database is migrated or not. Open the URL of your new umami location and try to login with your original credentials. If you can login, the database is very likely migrated (credentials is stored in database).
To further confirm, you can go to the dashboard and check if all data is displaying properly.
If not, which mean the database didn't migrated successfully. You may check the exported backup file (does it contain the right data?) and the way you import (see if the backup file is successfully imported to the new PostgreSQL).
## Reference
- [How To Migrate Umami From One Server To Another](https://www.programonaut.com/how-to-migrate-umami-from-one-server-to-another/)
- [How to Backup and Restore a PostgreSQL Database in Linux](https://www.tecmint.com/backup-and-restore-postgresql-database/)

View File

@@ -0,0 +1,270 @@
---
title: netcup vServer (ARM64) Benchmark and Review
subtitle:
date: 2024-03-09T22:33:19-05:00
slug: netcup-arm-review
draft: false
author:
name: James
link: https://www.jamesflare.com
email:
avatar: /site-logo.avif
description: This blog post reviews the performance of the netcup VPS 8000 ARM G11 server, featuring 18 vCore ARM64 CPUs based on Ampere Altra Max. It includes benchmark results from various testing scripts and compares the CPU performance with well-known processors.
keywords: ["netcup","VPS","ARM server","benchmark","Ampere Altra Max"]
license:
comment: true
weight: 0
tags:
- VPS
- Benchmark
- netcup
- ARM
categories:
- VPS
- Review
hiddenFromHomePage: false
hiddenFromSearch: false
hiddenFromRss: false
hiddenFromRelated: false
summary: This blog post reviews the performance of the netcup VPS 8000 ARM G11 server, featuring 18 vCore ARM64 CPUs based on Ampere Altra Max. It includes benchmark results from various testing scripts and compares the CPU performance with well-known processors.
resources:
- name: featured-image
src: featured-image.jpg
- name: featured-image-preview
src: featured-image-preview.jpg
toc: true
math: false
lightgallery: false
password:
message:
repost:
enable: true
url:
# See details front matter: https://fixit.lruihao.cn/documentation/content-management/introduction/#front-matter
---
<!--more-->
## Introduction
[netcup GmbH](https://www.netcup.eu) sells interesting ARM servers. I bought the [VPS 8000 ARM G11](https://www.netcup.eu/vserver/arm-server) version recently. It has 18 vCore (ARM64), offical website said it's based on Ampere Altra Max CPUs.
|Products|VPS 8000 ARM G11|
|---|---|
|Virtualisation technology|KVM|
|Processor|18 vCore (ARM64)|
|RAM|64GB DDR4 ECC|
|Storage space|2048 GB SSD|
|Network card|2500 Mbit/s|
|Traffic|inclusive|
## General Testing
Testing script from [Teddysun](https://teddysun.com/444.html) provides an idea of over all performance
```bash
wget -qO- bench.sh | bash
```
The result is here:
```text
-------------------- A Bench.sh Script By Teddysun -------------------
Version : v2023-10-15
Usage : wget -qO- bench.sh | bash
----------------------------------------------------------------------
CPU Model : CPU model not detected
CPU Cores : 18
AES-NI : ✓ Enabled
VM-x/AMD-V : ✗ Disabled
Total Disk : 2.0 TB (20.7 GB Used)
Total Mem : 62.7 GB (3.1 GB Used)
System uptime : 1 days, 14 hour 48 min
Load average : 0.25, 0.14, 0.10
OS : Debian GNU/Linux 12
Arch : aarch64 (64 Bit)
Kernel : 6.6.8
TCP CC : bbr
Virtualization : KVM
IPv4/IPv6 : ✓ Online / ✓ Online
Organization : AS197540 netcup GmbH
Location : Nürnberg / DE
Region : Bavaria
----------------------------------------------------------------------
I/O Speed(1st run) : 470 MB/s
I/O Speed(2nd run) : 673 MB/s
I/O Speed(3rd run) : 676 MB/s
I/O Speed(average) : 606.3 MB/s
----------------------------------------------------------------------
Node Name Upload Speed Download Speed Latency
Speedtest.net 174.35 Mbps 147.69 Mbps 0.29 ms
Los Angeles, US 626.82 Mbps 1950.34 Mbps 147.10 ms
Dallas, US 697.90 Mbps 2109.19 Mbps 133.37 ms
Montreal, CA 554.36 Mbps 904.78 Mbps 94.53 ms
Paris, FR 2108.91 Mbps 2321.03 Mbps 21.98 ms
Shanghai, CN 640.20 Mbps 1484.39 Mbps 255.22 ms
Hongkong, CN 5.00 Mbps 0.55 Mbps 301.56 ms
Mumbai, IN 1685.98 Mbps 2417.37 Mbps 116.27 ms
Singapore, SG 1592.12 Mbps 2572.71 Mbps 179.95 ms
Tokyo, JP 423.71 Mbps 1122.09 Mbps 217.83 ms
----------------------------------------------------------------------
Finished in : 5 min 15 sec
Timestamp : 2023-12-30 03:55:03 CET
----------------------------------------------------------------------
```
## Yet-Another-Bench-Script
```bash
curl -sL yabs.sh | bash
```
The result is very detailed and long, I split the result into parts. First, let's check the script information:
```text
# ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## #
# Yet-Another-Bench-Script #
# v2023-11-30 #
# https://github.com/masonr/yet-another-bench-script #
# ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## #
Sat Dec 30 04:16:48 AM CET 2023
ARM compatibility is considered *experimental*
```
Then, the basic OS information:
```text
Basic System Information:
---------------------------------
Uptime : 1 days, 15 hours, 15 minutes
Processor : Neoverse-N1
BIOS virt-5.2 CPU @ 2.0GHz
CPU cores : 18 @ ??? MHz
AES-NI : ✔ Enabled
VM-x/AMD-V : ❌ Disabled
RAM : 62.7 GiB
Swap : 0.0 KiB
Disk : 2.0 TiB
Distro : Debian GNU/Linux 12 (bookworm)
Kernel : 6.6.8
VM Type : KVM
IPv4/IPv6 : ✔ Online / ✔ Online
IPv6 Network Information:
---------------------------------
ISP : netcup GmbH
ASN : AS197540 netcup GmbH
Host : NETCUP-GMBH
Location : Karlsruhe, Baden-Wurttemberg (BW)
Country : Germany
```
Then, the Disk IO Test:
```text
fio Disk Speed Tests (Mixed R/W 50/50) (Partition /dev/vda4):
---------------------------------
Block Size | 4k (IOPS) | 64k (IOPS)
------ | --- ---- | ---- ----
Read | 138.63 MB/s (34.6k) | 261.70 MB/s (4.0k)
Write | 138.54 MB/s (34.6k) | 269.48 MB/s (4.2k)
Total | 277.18 MB/s (69.2k) | 531.19 MB/s (8.2k)
| |
Block Size | 512k (IOPS) | 1m (IOPS)
------ | --- ---- | ---- ----
Read | 298.21 MB/s (582) | 442.51 MB/s (432)
Write | 323.72 MB/s (632) | 493.71 MB/s (482)
Total | 621.93 MB/s (1.2k) | 936.22 MB/s (914)
```
Then, the Network Speed Test:
```text
iperf3 Network Speed Tests (IPv4):
---------------------------------
Provider | Location (Link) | Send Speed | Recv Speed | Ping
----- | ----- | ---- | ---- | ----
Clouvider | London, UK (10G) | 2.45 Gbits/sec | 2.37 Gbits/sec | 20.5 ms
Scaleway | Paris, FR (10G) | 2.46 Gbits/sec | busy | 20.1 ms
NovoServe | North Holland, NL (40G) | 2.47 Gbits/sec | 2.38 Gbits/sec | 9.96 ms
Uztelecom | Tashkent, UZ (10G) | 1.99 Gbits/sec | 996 Mbits/sec | 84.2 ms
Clouvider | NYC, NY, US (10G) | 2.00 Gbits/sec | 542 Mbits/sec | 91.6 ms
Clouvider | Dallas, TX, US (10G) | 1.44 Gbits/sec | 648 Mbits/sec | 128 ms
Clouvider | Los Angeles, CA, US (10G) | 1.16 Gbits/sec | 1.04 Gbits/sec | 147 ms
iperf3 Network Speed Tests (IPv6):
---------------------------------
Provider | Location (Link) | Send Speed | Recv Speed | Ping
----- | ----- | ---- | ---- | ----
Clouvider | London, UK (10G) | 2.44 Gbits/sec | 2.33 Gbits/sec | 20.5 ms
Scaleway | Paris, FR (10G) | busy | busy | 32.2 ms
NovoServe | North Holland, NL (40G) | 2.48 Gbits/sec | 2.35 Gbits/sec | 9.97 ms
Uztelecom | Tashkent, UZ (10G) | 2.10 Gbits/sec | 875 Mbits/sec | 84.4 ms
Clouvider | NYC, NY, US (10G) | 1.78 Gbits/sec | 893 Mbits/sec | 91.6 ms
Clouvider | Dallas, TX, US (10G) | 1.39 Gbits/sec | 852 Mbits/sec | 128 ms
Clouvider | Los Angeles, CA, US (10G) | 1.16 Gbits/sec | 549 Mbits/sec | 147 ms
```
Then, Geekbench 6 Result:
```text
Geekbench 6 Benchmark Test:
---------------------------------
Test | Value
|
Single Core | 1072
Multi Core | 8650
Full Test | https://browser.geekbench.com/v6/cpu/4192622
```
Finally, I tested Geekbench 5 only, with following script:
```bash
curl -sL yabs.sh | bash -s -- -i -f -n -5
```
Here is Geekbench 6 Result:
```text
Geekbench 5 Benchmark Test:
---------------------------------
Test | Value
|
Single Core | 798
Multi Core | 10975
Full Test | https://browser.geekbench.com/v5/cpu/22091599
```
## Review
Now, let's discuss the result.
### CPU Performance
VPS 8000 ARM G11's Geekbench 6 Multi-Core Score is around 8650, to help you get an idea od its level, I choiced some well known CPUs for comparing.
|CPU|Single-Core|Multi-Core Score|
|---|---|---|
|Intel Core i9-13900K|2970|20095|
|AMD Ryzen 9 7950X|2930|19224|
|Intel Core i9-12900K|2610|15428|
|AMD Ryzen 9 7940HS|2481|11741|
|AMD Ryzen 7 5800X3D|2085|10922|
|AMD Ryzen Z1 Extreme|2252|9689|
|AMD Ryzen 7 7840U|2099|8718|
|Intel Core i9-9900K|1664|7977|
My **Framework Laptop 13** with **AMD Ryzen 7 7840U** has a score of
|CPU|Single-Core|Multi-Core Score|
|---|---|---|
|AMD Ryzen 7 7840U|2256|12127|
This difference is because modern CPUs have dynamic booster mechanism, it can run above the base clock.
One more thing, I though a few records of Ampere [Altra Max 2800 MHz (96 cores)](https://browser.geekbench.com/v6/cpu/1590435) on the Geekbench 6 website. The Single-Core Score is 958 and Multi-Core Score is 11149.
This is odd, my 18 vCore server has a Multi-Core Score of 8650, the Altra Max 2800 MHz (96 cores) got only 11149. I guess the [Altra Max 2800 MHz (96 cores)](https://browser.geekbench.com/v6/cpu/1590435) records on the Geekbench 6 website is under performanced, since it's ADLINK Ampere Altra Developer Platform. It may be not tuned to optimized perfermance.

View File

@@ -0,0 +1,66 @@
---
title: Choice a Ideal Quantization Type for llama.cpp
subtitle:
date: 2024-03-09T20:59:27-05:00
slug: quantization-llama-cpp
draft: true
author:
name: James
link: https://www.jamesflare.com
email:
avatar: /site-logo.avif
description:
keywords:
license:
comment: true
weight: 0
tags:
- LLM
- Ollama
- llama.cpp
categories:
- AI
hiddenFromHomePage: false
hiddenFromSearch: false
hiddenFromRss: false
hiddenFromRelated: false
summary:
resources:
- name: featured-image
src: featured-image.jpg
- name: featured-image-preview
src: featured-image-preview.jpg
toc: true
math: false
lightgallery: false
password:
message:
repost:
enable: true
url:
# See details front matter: https://fixit.lruihao.cn/documentation/content-management/introduction/#front-matter
---
<!--more-->
| Q Type | Size | ppl Change | Note |
|:---:|:---:|:---:|:---:|
| Q2\_K\_S | 2.16G | +9.0634 | @ LLaMA-v1-7B |
| Q2\_K | 2.63G | +0.6717 | @ LLaMA-v1-7B |
| Q3\_K\_S | 2.75G | +0.5551 | @ LLaMA-v1-7B |
| Q3\_K | - | - | alias for Q3\_K\_M |
| Q3\_K\_M | 3.07G | +0.2496 | @ LLaMA-v1-7B |
| Q3\_K\_L | 3.35G | +0.1764 | @ LLaMA-v1-7B |
| Q4\_0 | 3.56G | +0.2166 | @ LLaMA-v1-7B |
| Q4\_K\_S | 3.59G | +0.0992 | @ LLaMA-v1-7B |
| Q4\_K | - | - | alias for Q4\_K\_M |
| Q4\_K\_M | 3.80G | +0.0532 | @ LLaMA-v1-7B |
| Q4\_1 | 3.90G | +0.1585 | @ LLaMA-v1-7B |
| Q5\_0 | 4.33G | +0.0683 | @ LLaMA-v1-7B |
| Q5\_K\_S | 4.33G | +0.0400 | @ LLaMA-v1-7B |
| Q5\_1 | 4.70G | +0.0349 | @ LLaMA-v1-7B |
| Q5\_K | - | - | alias for Q5\_K\_M |
| Q5\_K\_M | 4.45G | +0.0122 | @ LLaMA-v1-7B |
| Q6\_K | 5.15G | +0.0008 | @ LLaMA-v1-7B |
| Q8\_0 | 6.70G | +0.0004 | @ LLaMA-v1-7B |

View File

@@ -0,0 +1,372 @@
---
title: Config VLESS Protocol with Advance Feature in sing-box
subtitle:
date: 2024-03-09T22:44:42-05:00
slug: vless-tcp-reality-xtls-utls-xudp
draft: false
author:
name: James
link: https://www.jamesflare.com
email:
avatar: /site-logo.avif
description: This blog post provides a step-by-step guide on setting up a VLESS + TCP + REALITY + XTLS + uTLS + XUDP configuration using sing-box, covering server and client-side setup, installation, and running sing-box for a secure and efficient proxy solution.
license:
comment: true
weight: 0
tags:
- sing-box
- Proxy
- Security
- Networking
categories:
- Tutorials
- Proxy
hiddenFromHomePage: false
hiddenFromSearch: false
hiddenFromRss: false
hiddenFromRelated: false
summary: This blog post provides a step-by-step guide on setting up a VLESS + TCP + REALITY + XTLS + uTLS + XUDP configuration using sing-box, covering server and client-side setup, installation, and running sing-box for a secure and efficient proxy solution.
resources:
- name: featured-image
src: featured-image.jpg
- name: featured-image-preview
src: featured-image-preview.jpg
toc: true
math: false
lightgallery: false
password:
message:
repost:
enable: true
url:
# See details front matter: https://fixit.lruihao.cn/documentation/content-management/introduction/#front-matter
---
<!--more-->
## Introduction
VLESS + TCP + REALITY + XTLS + uTLS + XUDP is a very good combination. [XUDP](https://github.com/XTLS/Xray-core/discussions/252) let VLESS supports FullCone NAT. Using [REALITY](https://github.com/XTLS/REALITY#vless-xtls-utls-reality-example-for-xray-core-%E4%B8%AD%E6%96%87) instead of TLS can eliminate server-side TLS fingerprint characteristics, while still providing forward secrecy and rendering certificate chain attacks ineffective. Its security surpasses conventional TLS. It can point to other websites without the need to purchase a domain or configure a TLS server, making it more convenient. It achieves end-to-end genuine TLS presentation with a specified SNI to the middleman.
## Get sing-box
## sing-box Basic
sing-box uses JSON for configuration files.
```json
// Structure
{
"log": {},
"dns": {},
"ntp": {},
"inbounds": [],
"outbounds": [],
"route": {},
"experimental": {}
}
```
You can get detailed documents [here](https://sing-box.sagernet.org/configuration). I will not go through too much of them.
## Server Side
Before start we need to generate a x25519 key pair for REALITY. To do that in sing-box just run:
```bash
sing-box generate reality-keypair
```
You should get something like this:
```text
PrivateKey: 0H5tYLhpDT_r675UC93iWAS2LqN6mPZoDcVDqsff018
PublicKey: SeIw41mp1LFEd6CEGArmnSoaIXzNlwnkIbduoEY-OXk
```
Optionally, you can generate a short id for REALITY as well. By running this, you should get a 8 digit hex number:
```bash
sing-box generate rand 8 --hex
```
You should get something like this:
```text
26079ba8291ff0fc
```
Finally, you need to generate a UUID:
```bash
sing-box generate uuid
```
You should get something like this:
```text
11391936-7544-4af5-ad02-e9f3970b1f64
```
Now, let's fill them into the right place and finish the config. If you want to save some time and do not want to dive too deep, you can refer this config:
```json
{
"log":{
"level":"info"
},
"inbounds":[
{
"type":"vless",
"tag":"vless-in",
"listen":"0.0.0.0",
"listen_port":443,
"users":[
{
"name":"jamesflare",
"uuid":"11391936-7544-4af5-ad02-e9f3970b1f64",
"flow":"xtls-rprx-vision"
}
],
"tls":{
"enabled":true,
"server_name":"www.rpi.edu",
"reality":{
"enabled":true,
"handshake":{
"server":"www.rpi.edu",
"server_port":443
},
"private_key":"0H5tYLhpDT_r675UC93iWAS2LqN6mPZoDcVDqsff018",
"short_id":[
"26079ba8291ff0fc"
]
}
},
"multiplex":{
"enabled":false
}
}
],
"outbounds":[
{
"type":"direct",
"tag":"direct"
}
]
}
```
I highly recommand you change:
- `name`
- `uuid`
- `server_name`
- `server`
- `server_port`
- `private_key`
- `short_id`
to your own value, base on your own case.
## Client Side
I want sing-box use `TUN` as inbound, so we can archive global proxy. But you may run it as http/socks proxy as well. Anyhow, I will use `TUN` as example.
You need to change these following filed into your own value:
- `server`
- `server_port`
- `uuid`
- `server_name`
- `public_key`
- `short_id`
make sure your value match the server-side information. Here is an example:
```json
{
"log":{
"level":"info",
"timestamp":true
},
"dns":{
"servers":[
{
"tag":"cloudflare",
"address":"1.1.1.1"
}
],
"rules":[
{
"outbound":"any",
"server":"cloudflare"
}
],
"strategy":"ipv4_only"
},
"inbounds":[
{
"type":"tun",
"tag":"tun-in",
"interface_name":"tun0",
"inet4_address":"172.28.0.1/30",
"auto_route":true,
"strict_route":true,
"stack":"system",
"sniff":true
}
],
"outbounds":[
{
"type":"vless",
"tag":"vless-out",
"server":"your.server.ip.or.domain",
"server_port":443,
"uuid":"11391936-7544-4af5-ad02-e9f3970b1f64",
"flow":"xtls-rprx-vision",
"tls":{
"enabled":true,
"server_name":"www.rpi.edu",
"utls":{
"enabled":true,
"fingerprint":"chrome"
},
"reality":{
"enabled":true,
"public_key":"SeIw41mp1LFEd6CEGArmnSoaIXzNlwnkIbduoEY-OXk",
"short_id":"26079ba8291ff0fc"
}
},
"packet_encoding":"xudp",
"multiplex":{
"enabled":false
}
},
{
"type":"direct",
"tag":"direct"
},
{
"type":"dns",
"tag":"dns"
}
],
"route":{
"geoip":{
"download_url":"https://github.com/SagerNet/sing-geoip/releases/latest/download/geoip.db",
"download_detour":"vless-out"
},
"geosite":{
"download_url":"https://github.com/SagerNet/sing-geosite/releases/latest/download/geosite.db",
"download_detour":"vless-out"
},
"rules":[
{
"protocol":"dns",
"outbound":"dns"
},
{
"geoip":[
"private"
],
"outbound":"direct"
}
],
"auto_detect_interface":true
}
}
```
## Install sing-box
You may ask "how can I run sing-box with aboving config?". Well, you need install sing-box at first. You can find more information in the [offical document](https://sing-box.sagernet.org/installation/package-manager/).
### In Debian 12
I run sing-box server side on a Linux server, the OS is Debian 12. I this way, I used the offical installing script for debian:
```bash
bash <(curl -fsSL https://sing-box.app/deb-install.sh)
```
You can check installation by running:
```bash
sing-box help
```
It should return something like:
```text
Usage:
sing-box [command]
Available Commands:
check Check configuration
completion Generate the autocompletion script for the specified shell
format Format configuration
generate Generate things
help Help about any command
merge Merge configurations
run Run service
tools Experimental tools
version Print current version of sing-box
Flags:
-c, --config stringArray set configuration file path
-C, --config-directory stringArray set configuration directory path
-D, --directory string set working directory
--disable-color disable color output
-h, --help help for sing-box
Use "sing-box [command] --help" for more information about a command.
```
For Linux systems with systemd, usually the installation already includes a sing-box service, you can manage the service using the following command:
### In Windows 11
My client is Windows 11, I choice managed installation with [Chocolatey](https://chocolatey.org/install#individual). To install Chocolatey, you need run an Administrator PowerShell with:
```bash
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
```
If you don't see any errors, you are ready to use Chocolatey! Type `choco` or `choco -?` to check installation. Remember, this is a very simple instraction of Chocolatey, there are many other installation methods and options, please check offical site for more information.
Now, we can use Chocolatey to install sing-box:
```bash
choco install sing-box
```
You can check installation by running:
```bash
sing-box help
```
## Run sing-box
There are no different between server-side and client-side sing-box program. Only different is the config file.
Before start, you should save your config into a JSON file. I will name them like: `client.json`, `server.json`. Then specify the config in your command, like:
```bash
sing-box run -c client.json
```
You need to run sing-box both in client and server side. The output should be like:
```text
C:\Users\James\Desktop\Softwares\sing-box>sing-box run -c xray-ny-a-client.json
-0500 2023-12-27 23:23:32 INFO router: updated default interface Wi-Fi, index 18
-0500 2023-12-27 23:23:32 INFO inbound/tun[tun-in]: started at tun0
-0500 2023-12-27 23:23:32 INFO sing-box started (0.288s)
-0500 2023-12-27 23:23:32 INFO [832064929 0ms] inbound/tun[tun-in]: inbound packet connection from 172.28.0.1:55770
-0500 2023-12-27 23:23:32 INFO [1067986987 0ms] inbound/tun[tun-in]: inbound packet connection from 172.28.0.1:58423
-0500 2023-12-27 23:23:32 INFO [2253360887 0ms] inbound/tun[tun-in]: inbound connection from 172.28.0.1:60610
-0500 2023-12-27 23:23:32 INFO outbound/vless[vless-out]: outbound packet connection to 1.1.1.1:53
```