代码片段仓库

收集、管理和分享有用的代码片段,提高开发效率

代码片段

PHP cURL PHP

调用REST API

🔥             
Spring Boot Java

启动类配置

package com.example;

import org.springframework.boot.*;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication
@ComponentScan("com.example")
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}
JS Web组件 JavaScript

自定义元素

class CustomButton extends HTMLButtonElement {
  constructor() {
    super();
    this.innerText = 'Click Me';
    this.style.backgroundColor = 'blue';
    this.style.color = 'white';
    this.addEventListener('click', () => {
      alert('Button clicked!');
    });
  }
}

customElements.define('custom-button', CustomButton);
Canvas绘图 JavaScript

绘制简单图形

const canvas = document.getElementById('myCanvas');
const ctx = canvas.getContext('2d');

// Draw rectangle
ctx.fillStyle = '#FF0000';
ctx.fillRect(10, 10, 150, 80);

// Draw circle
ctx.beginPath();
ctx.arc(250, 100, 50, 0, 2 * Math.PI);
ctx.fillStyle = '#0000FF';
ctx.fill();

// Draw text
ctx.font = '30px Arial';
ctx.fillStyle = '#000000';
ctx.fillText('Happy Coding', 150, 200);
PHP REST PHP

简单API端点

🔥             
JS Web Worker JavaScript

多线程计算

// main.js
const worker = new Worker('worker.js');

worker.onmessage = (e) => {
  console.log('Result:', e.data);
};

worker.postMessage(1000000);

// worker.js
self.onmessage = (e) => {
  let result = 0;
  for(let i = 0; i < e.data; i++) {
    result += i;
  }
  self.postMessage(result);
};

为什么选择CodeSnippets?

高效管理您的代码片段,提高开发效率

智能搜索

通过关键字、语言或分类快速查找代码片段,支持模糊搜索和过滤功能

语法高亮

支持多种编程语言的语法高亮,使代码更加清晰易读

多设备同步

随时随地访问您的代码片段库,支持桌面和移动设备

热门分类

浏览最受欢迎的代码分类