Built with Bolt.new

Code Snippet Library

Discover, save, and share beautiful code snippets. Build your personal collection of reusable code.

Total Snippets

4

Languages

4

Categories

4

React useState Hook

Basic state management in React functional components

javascript
React
import { useState } from 'react';

function Counter() {
  const [count, setCount] = useState(0);

  return (
    <div>
      <p>Count: {count}</p>
      <button onClick={() => setCount(count + 1)}>
        Increment
      </button>
    </div>
  );
}
react
hooks
state
John Doe
2024-01-15

CSS Flexbox Center

Perfect centering with flexbox

css
CSS
.container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
}

.centered-content {
  text-align: center;
  padding: 2rem;
  background: white;
  border-radius: 8px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
css
flexbox
centering
Jane Smith
2024-01-14

Python List Comprehension

Elegant way to create lists in Python

python
Python
# Basic list comprehension
squares = [x**2 for x in range(10)]
print(squares)  # [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]

# With condition
even_squares = [x**2 for x in range(10) if x % 2 == 0]
print(even_squares)  # [0, 4, 16, 36, 64]

# Nested comprehension
matrix = [[i*j for j in range(3)] for i in range(3)]
print(matrix)  # [[0, 0, 0], [0, 1, 2], [0, 2, 4]]
python
list-comprehension
functional
Alice Johnson
2024-01-13

TypeScript Interface

Defining object shapes with TypeScript interfaces

typescript
TypeScript
interface User {
  id: number;
  name: string;
  email: string;
  isActive?: boolean;
  roles: string[];
}

interface ApiResponse<T> {
  data: T;
  status: 'success' | 'error';
  message?: string;
}

// Usage
const user: User = {
  id: 1,
  name: 'John Doe',
  email: 'john@example.com',
  roles: ['admin', 'user']
};

const response: ApiResponse<User> = {
  data: user,
  status: 'success'
};
typescript
interface
types
Bob Wilson
2024-01-12