Explore

Explore snippets

Discover reusable code snippets, examples, fixes, and ideas shared by developers, students, and teams.

Public snippets by CodShot user
Clear
26 public snippets
Open
HTML / Markup
Public

FAQ Section Markup

A simple FAQ section using semantic HTML and details/summary elements.

HTML / Markup Preview
<section class="faq-section" aria-labelledby="faq-title">
  <h2 id="faq-title">Frequently asked questions</h2>

  <details>
    <summary>Can I use CodShot for free?</summary>
    <p>Yes. The free plan is a good way to try the platform.</p>
  </details>
#html #faq #semantic #beginner
CodShot user
CodShot user
Updated: 2026-09-05 16:52
Public snippets
0 #58
Open
JavaScript
Public

Toggle Class on Click

Toggle a CSS class on an element when a button is clicked.

JavaScript Preview
const button = document.querySelector('#menuButton');
const menu = document.querySelector('#menu');

button.addEventListener('click', () => {
    menu.classList.toggle('is-open');
});
#javascript #dom #ui #beginner
CodShot user
CodShot user
Updated: 2026-06-08 14:33
Public snippets
0 #114
Open
C#
Public

Simple Class with Property

Create a small class with properties and instantiate it.

C# Preview
using System;

Product product = new()
{
    Name = "Keyboard",
    Price = 49.99m
};

Console.WriteLine($"{product.Name}: {product.Price:C}");

class Product
{
    public string Name { get; set; } = "";
    public decimal Price { get; set; }
}
#csharp #class #oop #beginner
CodShot user
CodShot user
Updated: 2026-06-08 14:33
Public snippets
0 #108
Open
C#
Public

Read All Lines from File

Read a text file into lines and print each line with its index.

C# Preview
using System;
using System.IO;

string path = "notes.txt";

if (!File.Exists(path))
{
    Console.WriteLine("File not found.");
    return;
}

string[] lines = File.ReadAllLines(path);

for (int i = 0; i < lines.Length; i++)
{
#csharp #file #text #beginner
CodShot user
CodShot user
Updated: 2026-06-08 14:33
Public snippets
0 #107
Open
C#
Public

Read Console Input Safely

Read a number from the console without crashing on invalid input.

C# Preview
using System;

Console.Write("Enter your age: ");
string? input = Console.ReadLine();

if (int.TryParse(input, out int age))
{
    Console.WriteLine($"You are {age} years old.");
}
else
{
    Console.WriteLine("Please enter a valid number.");
}
#csharp #console #input #beginner
CodShot user
CodShot user
Updated: 2026-06-08 14:33
Public snippets
0 #104
Open
PowerShell
Public

Create Project Folders

Create a simple frontend project folder structure.

PowerShell Preview
$folders = @(
    "src",
    "public",
    "assets",
    "assets/css",
    "assets/js",
    "assets/img"
)

foreach ($folder in $folders) {
    New-Item -ItemType Directory -Path $folder -Force | Out-Null
}

Write-Host "Project folders created."
#powershell #folders #project #beginner
CodShot user
CodShot user
Updated: 2026-06-03 15:31
Public snippets
0 #101
Open
Regex
Public

Find HTML Tags

Find simple opening or closing HTML tags in text.

Regex Preview
<\/?[a-zA-Z][a-zA-Z0-9-]*(?:\s[^>]*)?>
#regex #html #search #beginner
CodShot user
CodShot user
Updated: 2026-06-03 15:31
Public snippets
0 #97
Open
Regex
Public

Match Email Address

A practical beginner regex for basic email-like text matching.

Regex Preview
^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$
#regex #email #validation #beginner
CodShot user
CodShot user
Updated: 2026-06-03 15:31
Public snippets
0 #94
Open
Bash
Public

Reset One File to Last Commit

Discard local changes from one file and restore the committed version.

Bash Preview
git restore path/to/file.php
#git #restore #file #undo
CodShot user
CodShot user
Updated: 2026-06-03 15:31
Public snippets
0 #93
Open
Bash
Public

Show Changed Files

Show which files changed before you commit.

Bash Preview
git status --short

git diff --name-only
#git #diff #status #files
CodShot user
CodShot user
Updated: 2026-06-03 15:31
Public snippets
0 #92
Open
Bash
Public

Stash Work in Progress

Temporarily save unfinished changes and restore them later.

Bash Preview
git stash push -m "work in progress"

git stash list

git stash pop
#git #stash #workflow #student
CodShot user
CodShot user
Updated: 2026-06-03 15:31
Public snippets
0 #91
Open
Bash
Public

Undo Last Commit Keep Changes

Undo the last commit but keep the changed files in your working directory.

Bash Preview
git reset --soft HEAD~1
#git #undo #commit #beginner
CodShot user
CodShot user
Updated: 2026-06-03 15:31
Public snippets
0 #90
Open
Bash
Public

Create and Switch Branch

Create a new Git branch and switch to it in one command.

Bash Preview
git switch -c feature/login-page
#git #branch #workflow #beginner
CodShot user
CodShot user
Updated: 2026-06-03 15:31
Public snippets
0 #89
Open
SQL
Public

Select Rows with Pagination

A basic SQL pagination query using LIMIT and OFFSET.

SQL Preview
SELECT id, title, created_at
FROM blog_posts
WHERE is_published = 1
ORDER BY created_at DESC
LIMIT 20 OFFSET 40;
#sql #pagination #query #beginner
CodShot user
CodShot user
Updated: 2026-06-03 15:31
Public snippets
0 #84
Open
Python
Public

Safe JSON Load

Load JSON data from a file and handle invalid JSON safely.

Python Preview
import json
from pathlib import Path

file_path = Path("settings.json")

try:
    data = json.loads(file_path.read_text(encoding="utf-8"))
    print(data)
except FileNotFoundError:
    print("settings.json was not found")
except json.JSONDecodeError:
#python #json #file #error-handling
CodShot user
CodShot user
Updated: 2026-06-03 15:31
Public snippets
0 #83
Open
Python
Public

Simple CSV Reader

Read a CSV file with headers and print selected columns.

Python Preview
import csv

with open("students.csv", newline="", encoding="utf-8") as file:
    reader = csv.DictReader(file)

    for row in reader:
        name = row.get("name", "")
        grade = row.get("grade", "")
        print(f"{name}: {grade}")
#python #csv #file #student
CodShot user
CodShot user
Updated: 2026-06-03 15:31
Public snippets
0 #82
Open
Python
Public

Count Word Frequency

Count how often each word appears in a short text.

Python Preview
text = "python is fun and python is useful"
words = text.lower().split()

counts = {}

for word in words:
    counts[word] = counts.get(word, 0) + 1

for word, count in counts.items():
    print(word, count)
#python #string #dictionary #beginner
CodShot user
CodShot user
Updated: 2026-06-03 15:31
Public snippets
0 #81
Open
Python
Public

Filter Even Numbers

Filter even numbers from a list using a simple list comprehension.

Python Preview
numbers = [3, 8, 12, 15, 20, 21, 30]

even_numbers = [number for number in numbers if number % 2 == 0]

print(even_numbers)
#python #list #beginner #filter
CodShot user
CodShot user
Updated: 2026-06-03 15:31
Public snippets
0 #80
Open
Python
Public

Read Text File Lines

Read a text file line by line and remove the newline characters.

Python Preview
from pathlib import Path

file_path = Path("notes.txt")

if not file_path.exists():
    print("File not found")
else:
    lines = file_path.read_text(encoding="utf-8").splitlines()

    for line_number, line in enumerate(lines, start=1):
#python #file #beginner #text
CodShot user
CodShot user
Updated: 2026-06-03 15:31
Public snippets
0 #79
Open
Batch
Public

List Files by Extension

A Windows CMD command that lists files with a selected extension into a text file.

Batch Preview
@echo off

dir /b *.png > png-files.txt

echo File list saved to png-files.txt
pause
#cmd #windows #files #beginner
CodShot user
CodShot user
Updated: 2026-06-03 14:05
Public snippets
0 #75
Open
PHP
Public

Group Array Items by Key

A useful PHP helper for grouping database rows by a selected key.

PHP Preview
<?php

function groupByKey(array $items, string $key): array
{
    $groups = [];

    foreach ($items as $item) {
        $groupKey = (string) ($item[$key] ?? '');

        if ($groupKey === '') {
            continue;
        }
#php #array #utility #beginner
CodShot user
CodShot user
Updated: 2026-06-03 14:05
Public snippets
0 #72
Open
JavaScript
Public

Filter an Array of Objects

A beginner-friendly JavaScript example for filtering objects by search text.

JavaScript Preview
const snippets = [
  { title: 'PHP Slug Generator', language: 'php' },
  { title: 'CSS Loading Spinner', language: 'css' },
  { title: 'JavaScript Debounce', language: 'javascript' }
];

function searchSnippets(items, query) {
#javascript #array #filter #beginner
CodShot user
CodShot user
Updated: 2026-06-03 14:05
Public snippets
0 #68
Open
JavaScript
Public

Copy Text to Clipboard

A vanilla JavaScript helper to copy text to the clipboard with a fallback message.

JavaScript Preview
async function copyText(text) {
  try {
    await navigator.clipboard.writeText(text);
    console.log('Copied to clipboard');
    return true;
  } catch (error) {
    console.error('Clipboard copy failed:', error);
    return false;
  }
}
#javascript #clipboard #utility #beginner
CodShot user
CodShot user
Updated: 2026-06-03 14:05
Public snippets
0 #64
Open
CSS
Public

Button Pulse Animation

A simple CSS pulse effect for call-to-action buttons.

CSS Preview
.button-pulse {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 1.25rem;
  border-radius: 999px;
  background: #4f46e5;
  color: #fff;
  text-decoration: none;
  animation: pulse 1.8s infinite;
}

@keyframes pulse {
#css #animation #button #beginner
CodShot user
CodShot user
Updated: 2026-06-03 14:05
Public snippets
0 #59
CodShot AI Help
Ask about CodShot features, plans, workspace, AI limits, referrals, and public help topics.
Hi! I can help you understand how CodShot works. What would you like to know?
For account-specific or sensitive issues, please open a support ticket. Open support