收集、管理和分享有用的代码片段,提高开发效率
使用requests获取网页内容
import requests
def fetch_web_page(url):
try:
response = requests.get(url, timeout=10)
response.raise_for_status() # Raise error for bad status
return response.text
except requests.exceptions.RequestException as e:
return f"Error: {e}"
结构化克隆深拷贝对象
const deepClone = (obj) => {
if (typeof obj !== 'object' || obj === null) return obj;
let cloned;
if (Array.isArray(obj)) {
cloned = [];
for (let i = 0; i < obj.length; i++) {
cloned[i] = deepClone(obj[i]);
}
} else {
cloned = {};
for (const key in obj) {
if (obj.hasOwnProperty(key)) {
cloned[key] = deepClone(obj[key]);
}
}
}
return cloned;
}
DataFrame创建与操作
import pandas as pd
# Create a DataFrame
data = {
'Name': ['Alice', 'Bob', 'Charlie'],
'Age': [25, 30, 22],
'City': ['New York', 'London', 'Paris']
}
df = pd.DataFrame(data)
# Display first 2 rows
print(df.head(2))
# Calculate mean age
print("\nMean Age:", df, Age'].mean())
unique_ptr使用示例
#include <memory>
#include <iostream>
using namespace std;
class MyClass {
public:
MyClass() { cout << "Constructor\n"; }
~MyClass() { cout << "Destructor\n"; }
};
int main() {
unique_ptr<MyClass> ptr( new MyClass() );
return 0;
}
处理文件上传表单
🔥
ExecutorService使用
import java.util.concurrent.*;
public class ThreadPoolExample {
public static void main(String[] args) {
ExecutorService eservice = Executors.newFixedThreadPool(4);
for (int i = 0; i < 10; i++) {
eservice.submit(() -> {
System.out.println("Task " + i + " executed by " + Thread.currentThread().getName());
});
}
eservice.shutdown();
}
}
高效管理您的代码片段,提高开发效率
通过关键字、语言或分类快速查找代码片段,支持模糊搜索和过滤功能
支持多种编程语言的语法高亮,使代码更加清晰易读
随时随地访问您的代码片段库,支持桌面和移动设备
浏览最受欢迎的代码分类