import matplotlib.pyplot as plt
import numpy as np
# Generate sample data
x = np.linspace(0, 10, 100)
y1 = np.sin(x)
y2 = np.cos(x)
# Create the plot
plt.figure(figsize=(10, 6))
plt.plot(x, y1, label='sin(x)', color='#3b82f6', linewidth=2)
plt.plot(x, y2, label='cos(x)', color='#8b5cf6', linewidth=2)
plt.title('Trigonometric Functions', fontsize=16)
plt.xlabel('x')
plt.ylabel('y')
plt.legend()
plt.grid(True, alpha=0.3)
plt.show()
Interactive sine and cosine wave visualization
Clean way to visualize trigonometric functions! 📊 Perfect for math tutorials or data science presentations.
import { useState, useEffect } from 'react';
function useLocalStorage(key, initialValue) {
const [storedValue, setStoredValue] = useState(() => {
try {
const item = window.localStorage.getItem(key);
return item ? JSON.parse(item) : initialValue;
} catch (error) {
return initialValue;
}
});
const setValue = (value) => {
try {
setStoredValue(value);
window.localStorage.setItem(key, JSON.stringify(value));
} catch (error) {
console.error(error);
}
};
return [storedValue, setValue];
}
// Usage example
function App() {
const [name, setName] = useLocalStorage('name', '');
return (
<input
value={name}
onChange={(e) => setName(e.target.value)}
placeholder="Your name persists!"
/>
);
}
Your input persists across page reloads!
Live input that persists data in localStorage
Custom hook for localStorage persistence! 🚀 Never lose form data again. Super useful for user preferences.
.glass-card {
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
border-radius: 20px;
border: 1px solid rgba(255, 255, 255, 0.2);
padding: 2rem;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
transition: all 0.3s ease;
}
.glass-card:hover {
transform: translateY(-5px);
box-shadow: 0 15px 45px rgba(0, 0, 0, 0.2);
background: rgba(255, 255, 255, 0.15);
}
.glass-card::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
height: 1px;
background: linear-gradient(
90deg,
transparent,
rgba(255, 255, 255, 0.4),
transparent
);
}
Beautiful translucent effect with backdrop blur
Beautiful glassmorphism card with hover effects
Trendy glassmorphism effect! ✨ Perfect for modern UI designs. Works great with dark backgrounds.
import pandas as pd
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
# Load and prepare data
data = pd.read_csv('iris.csv')
X = data.drop('species', axis=1)
y = data['species']
# Split the data
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.2, random_state=42
)
# Train the model
model = RandomForestClassifier(n_estimators=100, random_state=42)
model.fit(X_train, y_train)
# Make predictions
predictions = model.predict(X_test)
accuracy = accuracy_score(y_test, predictions)
print(f"Model Accuracy: {accuracy:.2%}")
print(f"Predictions: {predictions[:5]}")
Model Accuracy: 96.67% Predictions: ['setosa' 'versicolor' 'virginica' 'setosa' 'versicolor']
Machine learning model results
Quick iris classification with Random Forest! 🤖 96.67% accuracy in just a few lines. Perfect for ML beginners.
use std::collections::HashMap;
fn fibonacci_memo(n: u64, memo: &mut HashMap<u64, u64>) -> u64 {
match n {
0 => 0,
1 => 1,
_ => {
if let Some(&result) = memo.get(&n) {
result
} else {
let result = fibonacci_memo(n - 1, memo) +
fibonacci_memo(n - 2, memo);
memo.insert(n, result);
result
}
}
}
}
fn main() {
let mut memo = HashMap::new();
for i in 0..=20 {
println!("fib({}) = {}", i, fibonacci_memo(i, &mut memo));
}
// Calculate large fibonacci number efficiently
println!("fib(50) = {}", fibonacci_memo(50, &mut memo));
}
fib(0) = 0 fib(1) = 1 fib(2) = 1 ... fib(50) = 12586269025
Fibonacci sequence with memoization
Blazingly fast Fibonacci with memoization! 🦀 Rust's HashMap makes this super efficient. Try it with large numbers!