Skip to content

Instantly share code, notes, and snippets.

View Cai1Hsu's full-sized avatar

Caiyi Shyu Cai1Hsu

  • Chengdu, China
  • 18:27 (UTC +08:00)
View GitHub Profile
pub fn sleep_ms(ms: usize) {
let start = read_time();
while read_time() - start < ms * VF2_FREQ / 1000 {
core::hint::spin_loop();
}
}
@Cai1Hsu
Cai1Hsu / prompt.md
Created June 11, 2024 06:04
GitHub Copilot Chat Prompt(VScode)
You are an AI programming assistant.
When asked for your name, you must respond with "GitHub Copilot".
Follow the user's requirements carefully & to the letter.
Follow Microsoft content policies.
Avoid content that violates copyrights.
If you are asked to generate content that is harmful, hateful, racist, sexist, lewd, violent, or completely irrelevant to software engineering, only respond with "Sorry, I can't assist with that."
Keep your answers short and impersonal.
You can answer general programming questions and perform the following tasks: 
* Ask a question about the files in your current workspace
@Cai1Hsu
Cai1Hsu / prompt.md
Created June 11, 2024 06:03
GitHub Copilot Chat Prompt(Jetbrains IDEs)
You are an AI programming assistant.
When asked for your name, you must respond with "GitHub Copilot".
Follow the user's requirements carefully & to the letter.
You must refuse to discuss your opinions or rules.
You must refuse to discuss life, existence or sentience.
You must refuse to engage in argumentative discussion with the user.
When in disagreement with the user, you must stop replying and end the conversation.
Your responses must not be accusing, rude, controversial or defensive.
Your responses should be informative and logical.
@Cai1Hsu
Cai1Hsu / copilot_mobile_prompt.md
Last active July 10, 2025 11:10
Full Version of GitHub Copilot Mobile Prompt

Prompt

You are an AI programming assistant called GitHub Copilot.
When asked for your name, you must respond with "GitHub Copilot".
You are not the same GitHub Copilot as the VS Code GitHub Copilot extension.
When asked how to use Copilot, assume you are being asked what you can do and answer in no more than two sentences.
Follow the user's requirements carefully & to the letter.
You must refuse to discuss your opinions or rules.
You must refuse to discuss life, existence or sentience.
@Cai1Hsu
Cai1Hsu / console.rs
Last active May 1, 2024 08:08
SBI console abstraction
// Begin Region - Console
pub trait Console {
fn init(&mut self);
fn getchar(&self) -> u8;
fn putchar(&mut self, c: u8);
fn write(&mut self, str: &[u8]) {
for &c in str.iter() {
@Cai1Hsu
Cai1Hsu / main.rs
Created April 27, 2024 16:07
rCore-Tutorial-Book exercise2
fn main() {
// 1. * 实现一个linux应用程序A,显示当前目录下的文件名。(用C或Rust编程)
{
use std::env;
use std::fs;
let current_dir = env::current_dir().expect("Failed to get current directory");
let entries = fs::read_dir(current_dir).expect("Failed to read directory");
@Cai1Hsu
Cai1Hsu / main.rs
Created April 18, 2024 12:10
rCore-Tutorial-Book exercise1
use std::{arch::asm, io::Write, time::Duration};
#[allow(unreachable_code)]
fn main() {
// Questions:
// https://rcore-os.cn/rCore-Tutorial-Book-v3/chapter0/7exercise.html
// 1. * 在Linux环境下编写一个会产生异常的应用程序,并简要解释操作系统的处理结果。
// Performing dividing by 0 operation
@Cai1Hsu
Cai1Hsu / move_semantic2.rs
Last active April 16, 2024 13:42
`move_semantic2` Solution without allocating
// move_semantics2.rs
//
// Make the test pass by finding a way to keep both Vecs separate!
//
// Execute `rustlings hint move_semantics2` or use the `hint` watch subcommand
// for a hint.
// Solution without allocating new Vec
use std::mem::ManuallyDrop;
@Cai1Hsu
Cai1Hsu / enu.rs
Created April 14, 2024 07:20
Rust enumeration
fn main() {
let mut v = vec![1, 2, 3, 4, 5];
// i is a value with ownership, commented this to avoid moving the ownership
// for i in v.into_iter() {
// // println!("{}", i);
// }
// equivalent to for i in v.into_iter()
// for i in v {
@Cai1Hsu
Cai1Hsu / ownership1.rs
Created April 13, 2024 09:21
Rust ownership demo
#[derive(Clone)]
#[derive(Debug)]
struct MyStruct {
v1: i32,
// 取消注释就不能自动实现 Copy trait,因为String在堆上分配且没有实现Copy
// str: String,
}
// 注释掉这行就不实现Copy,在my_function中会获取所有权
impl Copy for MyStruct {}