Discover, share, and learn from thousands of code snippets and projects across all programming languages
890 snippets
756 snippets
432 snippets
321 snippets
245 snippets
198 snippets
156 snippets
124 snippets
def quicksort(arr):
if len(arr) <= 1:
return arr
pivot = arr[len(arr) // 2]
left = [x for x in arr if x < pivot]
middle = [x for x in arr if x == pivot]
right = [x for x in arr if x > pivot]
return quicksort(left) + middle + quicksort(right)
# Example
numbers = [3, 6, 8, 10, 1, 2, 1]
print(quicksort(numbers)) # [1, 1, 2, 3, 6, 8, 10]
function debounce(func, wait, immediate) {
let timeout;
return function executedFunction() {
const context = this;
const args = arguments;
const later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
};
const callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) func.apply(context, args);
};
}
// Usage
const handleSearch = debounce((query) => {
console.log('Searching:', query);
}, 300);
// Levish AI Data Analyzer
func analyzeData(dataset) {
let prediction = ai.predict("trend", dataset)
let sentiment = ai.classify(dataset)
let summary = ai.summarize(dataset)
print("Prediction: {prediction}")
print("Sentiment: {sentiment}")
print("Summary: {summary}")
return {
prediction: prediction,
sentiment: sentiment,
summary: summary
}
}
func main() {
let data = [45, 67, 23, 89, 12, 56, 78]
let results = analyzeData(data)
print("Analysis complete: {results}")
}
public class Singleton {
private static volatile Singleton instance;
private String data;
private Singleton(String data) {
this.data = data;
}
public static Singleton getInstance(String data) {
if (instance == null) {
synchronized (Singleton.class) {
if (instance == null) {
instance = new Singleton(data);
}
}
}
return instance;
}
public String getData() {
return data;
}
}
struct Node {
int data;
Node* left;
Node* right;
Node(int val) : data(val), left(nullptr), right(nullptr) {}
};
class BST {
public:
Node* root = nullptr;
Node* insert(Node* node, int val) {
if (!node) return new Node(val);
if (val < node->data)
node->left = insert(node->left, val);
else if (val > node->data)
node->right = insert(node->right, val);
return node;
}
void inorder(Node* node) {
if (!node) return;
inorder(node->left);
cout << node->data << " ";
inorder(node->right);
}
};
package main
import (
"fmt"
"net/http"
"sync"
)
var counter int
var mu sync.Mutex
func handler(w http.ResponseWriter, r *http.Request) {
mu.Lock()
counter++
mu.Unlock()
fmt.Fprintf(w, "Hello! You are visitor #%d", counter)
}
func main() {
http.HandleFunc("/", handler)
fmt.Println("Server running on :8080")
http.ListenAndServe(":8080", nil)
}
A fully functional AI chatbot built with Levish language, featuring natural language processing and context awareness.
Real-time cryptocurrency dashboard with live charts, portfolio tracking, and price alerts built with React.
Scalable ETL data pipeline for processing millions of records with Apache Kafka and Python.
Sign up for free to like, share, copy code, submit your own snippets, and access premium projects.
Help give street children in Uganda a brighter future through education, shelter, and care.
Donate Now →