Skip to content

Instantly share code, notes, and snippets.

View daneren's full-sized avatar

danerli(李润) daneren

  • Tencent
  • Shanghai, China
View GitHub Profile
@daneren
daneren / chatgpt_study_mode_prompt.md
Created July 31, 2025 07:10 — forked from idcesares/chatgpt_study_mode_prompt.md
ChatGPT Study Mode System Prompt

The user is currently STUDYING, and they've asked you to follow these strict rules during this chat. No matter what other instructions follow, you MUST obey these rules:

STRICT RULES

Be an approachable-yet-dynamic teacher, who helps the user learn by guiding them through their studies.

  1. Get to know the user. If you don't know their goals or grade level, ask the user before diving in. (Keep this lightweight!) If they don't answer, aim for explanations that would make sense to a 10th grade student.
  2. Build on existing knowledge. Connect new ideas to what the user already knows.
  3. Guide users, don't just give answers. Use questions, hints, and small steps so the user discovers the answer for themselves.
  4. Check and reinforce. After hard parts, confirm the user can restate or use the idea. Offer quick summaries, mnemonics, or mini-reviews to help the ideas stick.
  5. Vary the rhythm. Mix explanations, questions, and activities (like roleplaying, practice rounds, or asking the user
@daneren
daneren / fastapi-redis.py
Created July 16, 2025 07:40 — forked from nicksonthc/fastapi-redis.py
FastAPI with asyncio Redis and Lifespan Example
from contextlib import asynccontextmanager
from datetime import datetime
from fastapi import FastAPI, Request
import fastapi
from fastapi.datastructures import State
from fastapi.responses import JSONResponse
import redis.asyncio as redis
class Redis:
redis_client: redis.Redis = None
from pathlib import Path
from collections import defaultdict
def get_files_by_first_level_directory(root_path, exclude_files=None):
if exclude_files is None:
exclude_files = []
files_dict = defaultdict(dict)
root_path = Path(root_path)
# 官方资料
https://github.com/huggingface/huggingface_hub
https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/commands/download.py
# 国内镜像源
https://hf-mirror.com/models
https://hf-mirror.com/datasets
# 修改下载源
export HF_ENDPOINT=https://hf-mirror.com
import pynvml
pynvml.nvmlInit()
handle = pynvml.nvmlDeviceGetHandleByIndex(0) # 0表示显卡标号
meminfo = pynvml.nvmlDeviceGetMemoryInfo(handle)
print(meminfo.total/1024**2) #总的显存大小
print(meminfo.used/1024**2) #已用显存大小
print(meminfo.free/1024**2) #剩余显存大小
We couldn’t find that file to show.
ARG base=nvcr.io/nvidia/pytorch:23.07-py3
FROM $base
# [推荐] 修改软件源(若在腾讯云使用推荐用内网源)
# [腾讯外网软件源] mirrors.tencent.com
# [腾讯云内网软件源] mirrors.tencentyun.com
ENV TENCENT_MIRRORS="mirrors.tencentyun.com"
RUN sed -i "s/archive.ubuntu.com/${TENCENT_MIRRORS}/g" /etc/apt/sources.list && \
sed -i "s/security.ubuntu.com/${TENCENT_MIRRORS}/g" /etc/apt/sources.list && \
pip config set global.index-url http://${TENCENT_MIRRORS}/pypi/simple && \
@daneren
daneren / blame-praise.py
Created March 24, 2023 07:31 — forked from amarao/blame-praise.py
Example of argparse with subparsers for python
#!/usr/bin/env python
import argparse
def main(command_line=None):
parser = argparse.ArgumentParser('Blame Praise app')
parser.add_argument(
'--debug',
action='store_true',
help='Print debug info'
import torch
from torchvision.models import resnet18
import torch.nn as nn
from torchvision import transforms
import matplotlib.pyplot as plt
def viz(module, input):
x = input[0][0]
#最多显示4张图