精选高频实用代码片段,覆盖 Python、JavaScript、Shell、SQL 等主流语言,提升开发效率,一键复制即用。
import json
def load_config(path):
with open(path, 'r', encoding='utf-8') as f:
return json.load(f)
config = load_config('config.json')
function debounce(func, delay) {
let timer;
return function (...args) {
clearTimeout(timer);
timer = setTimeout(() => func.apply(this, args), delay);
};
}
// 使用示例
const handleInput = debounce(search, 300);
#!/bin/bash for file in *.jpg; do mv "" "prefix_$file" done
SELECT * FROM users ORDER BY id LIMIT 10 OFFSET 10;
.card-grid {
display: flex;
flex-wrap: wrap;
gap: 20px;
}
.card {
flex: 1 1 300px;
background: #2a2a4a;
padding: 16px;
border-radius: 12px;
}
import requests
response = requests.post(
'https://api.example.com/data',
json={'key': 'value'},
headers={'Authorization': 'Bearer token'}
)
print(response.json())