Skip to content

Code snippets

Copy-paste ready code for common programming tasks.

Language:

779 snippets found

Python

Sort Dictionary by Value

Sort a Python dictionary by its values in descending order.

#dict#sorting#intermediate
JavaScript

Array Map Filter Reduce

Chain map, filter, reduce, find, some, and every on arrays.

#array#functional#intermediate
Rust

Struct with Methods

Define a Rust struct and implement methods with self and Self.

#struct#method#intermediate
Java

String Operations and StringBuilder

Manipulate strings with split, join, substring, and StringBuilder in Java.

#string#beginner
SQL

SELECT with WHERE and ORDER BY

Filter, sort, and limit rows with SELECT, WHERE, and ORDER BY in SQL.

#select#query#beginner
HTML

Accessible Form with Inputs

Build an accessible HTML form with labels, inputs, select, and checkbox.

#form#input#beginner
HTML

Table with Thead Tbody Tfoot

Structure tabular data with thead, tbody, tfoot, and caption in HTML.

#table#beginner
HTML

Responsive Images and Video

Embed responsive images with srcset, video, audio, and figure in HTML.

#media#image#intermediate
HTML

Links Anchors and Download

Create internal, external, anchor, email, phone, and download links in HTML.

#link#navigation#beginner
CSS

Center a Div with Flexbox and Grid

Center elements horizontally and vertically using Flexbox, Grid, and absolute positioning.

#center#layout#beginner
CSS

CSS Selectors and Pseudo-classes

Target elements with pseudo-classes, pseudo-elements, and attribute selectors.

#selector#pseudo#intermediate
React

Controlled Form with Validation

Build a controlled React form with inline validation and error messages.

#form#validation#intermediate
React

Event Handling and List Rendering

Handle events and render dynamic lists with keys in React.

#event#list#intermediate
Git

Manage Remotes and Push Pull

Add, change, and interact with remote repositories in Git.

#remote#push#intermediate
Git

View Commit History with git log

Browse, filter, and format commit history with git log options.

#log#history#beginner
Bash

Variables and Arrays in Bash

Assign variables, use command substitution, and work with arrays in Bash.

#variable#array#beginner
PHP

Arrays and Array Functions in PHP

Create indexed, associative, and multidimensional arrays with map and filter.

#array#beginner
PHP

String Functions in PHP

Manipulate strings with substr, replace, explode, and sprintf in PHP.

#string#beginner
PHP

Read and Write Files in PHP

Read, write, append, and iterate files with PHP filesystem functions.

#file#io#intermediate
PHP

PDO Database Queries in PHP

Connect and run prepared statements safely with PDO in PHP.

#pdo#database#intermediate
PHP

Sessions and Cookies in PHP

Store user data across requests with sessions and cookies in PHP.

#session#cookie#intermediate
PHP

Classes and Inheritance in PHP

Define classes with constructors, visibility, and inheritance in PHP.

#class#oop#intermediate
JavaScript

Array Deduplication

Deduplicate an array using Set.

#array#set#dedup
JavaScript

Deep Clone

Deep clone objects, supporting common data types.

#object#clone#recursion
Page 1 of 33