MSNCodeSNIPPETS← msncode.dev
Code Snippets

Copy-paste kepake.

Snippet kode singkat yang beneran dipake. Git, Docker, PostgreSQL, JS, Python, Vim. Cari, copy, paste.

css(10)

Center with Flexbox

Center any element horizontally and vertically

css

CSS Grid Two Columns

Simple two-column layout with CSS Grid

css

Custom Scrollbar Styling

Style your scrollbar for WebKit browsers

css

Custom Text Selection Color

Change the highlight color when selecting text

css

Fixed Aspect Ratio Box

Create a box with a fixed aspect ratio

css

Fluid Typography with clamp

Responsive font size that scales with viewport

css

Hide Scrollbar but Keep Scroll

Hide the scrollbar while keeping scroll functionality

css

Object Fit Cover Image

Make images fill a container without distortion

css

Smooth Scroll Behavior

Enable smooth scrolling for the entire page

css

Truncate Text with Ellipsis

Cut off long text with three dots

css

curl(5)

Download File with Progress

Download a file and show progress bar

bash

Follow Redirects

Automatically follow HTTP redirects

bash

POST JSON with curl

Send a POST request with JSON body

bash

Save Response Headers

Dump response headers to a file

bash

Set Custom Headers

Add authorization or custom headers

bash

docker(8)

Build Image with Tag

Build a Docker image with a custom name

bash

Clean Everything (Dangling + Stopped)

Remove stopped containers, dangling images, and unused networks

bash

Copy File to Container

Copy a file from host into a running container

bash

Enter a Running Container

Get a shell inside a running Docker container

bash

List Running Containers

Show all currently running Docker containers

bash

Remove All Docker Images

Delete every Docker image to free up disk space

bash

Run Container with Volume

Mount a local directory into a container

bash

View Container Logs (Follow)

Stream logs from a container in real-time

bash

git(12)

Amend Last Commit Message

Change the message of your most recent commit

bash

Cherry-Pick a Commit

Apply a specific commit from another branch

bash

Create and Switch Branch

Create a new branch and switch to it in one command

bash

Delete All Merged Branches

Clean up local branches that have been merged into main

bash

Force Push Safely

Force push only if no one else has pushed in the meantime

bash

Rebase onto Main

Rebase current branch onto latest main

bash

Restore Deleted Tracked File

Recover a file you deleted but was tracked by git

bash

Revert Last Commit (Keep Changes)

Undo the last commit but keep your changes in the staging area

bash

Show What Changed in a Commit

View the diff of a specific commit

bash

Stash Changes Temporarily

Save uncommitted changes and restore them later

bash

Undo git add (Unstage Files)

Remove a file from staging without losing changes

bash

View a File from Another Branch

See a file's content from a different branch without switching

bash

javascript(10)

Capitalize First Letter

Capitalize the first character of a string

javascript

Copy to Clipboard

Copy text to the user's clipboard using the Clipboard API

javascript

Debounce a Function

Delay function execution until user stops typing

javascript

Deep Clone an Object

Deep copy an object (works for JSON-serializable data)

javascript

Flatten Nested Array

Flatten a deeply nested array

javascript

Format Number as Currency

Format a number as a localized currency string

javascript

Get Unique Array Values

Remove duplicates from an array

javascript

Group Array by Property

Group array items by a property value

javascript

Parse Query Params to Object

Convert URL query string to an object

javascript

Sleep / Pause Execution

Pause execution for a number of milliseconds using async/await

javascript

linux(8)

Count Lines in Files

Count total lines across all files in a directory

bash

Create tar.gz Archive

Compress a directory into tar.gz

bash

Disk Usage in Human Format

Show disk usage with readable sizes

bash

Extract tar.gz Archive

Extract a compressed tar.gz file

bash

Find Largest Files

Find the 10 largest files on disk

bash

Grep Recursively

Search for a string in all files recursively

bash

Kill Process on Port

Kill whatever is running on a specific port

bash

Make File Executable

Give execute permission to a file

bash

nginx(5)

Custom 404 Page

Serve a custom error page for 404s

nginx

Enable Gzip Compression

Compress responses to reduce bandwidth

nginx

Redirect HTTP to HTTPS

Force all traffic to use HTTPS

nginx

Reverse Proxy to Backend

Forward requests to a backend server

nginx

Serve Static Files

Serve static files from a directory

nginx

nodejs(8)

Check if Directory Exists

Check if a path exists and is a directory

javascript

Fetch with Timeout

Add a timeout to fetch requests using AbortController

javascript

Get Current Directory Path

Get the directory of the currently running script

javascript

Read Environment Variable

Access environment variables in Node.js

javascript

Read File Synchronously

Read a file with fs.readFileSync

javascript

Safe JSON Parse

Parse JSON without try-catch crashing your app

javascript

Stream to String

Convert a readable stream to a string

javascript

Write File Synchronously

Write content to a file with fs.writeFileSync

javascript

npm(5)

Clean npm Cache

Clear the npm cache to fix install issues

bash

Install Specific Version

Install a package at a specific version

bash

List Outdated Packages

Check which packages have newer versions

bash

Run npm Script

Execute a script defined in package.json

bash

Update All Packages

Update all dependencies to latest semver

bash

postgres(8)

Create User and Database

Create a new PostgreSQL user and database

sql

Describe Table Structure

Show columns, types, and constraints of a table

sql

Export Table to CSV

Export a PostgreSQL table to a CSV file

sql

Find Duplicate Rows

Find rows with duplicate values in a column

sql

Kill a Running Query

Cancel a long-running PostgreSQL query by PID

sql

List All Databases

Show all databases in your PostgreSQL server

sql

List Table Sizes

Show all tables and their sizes, largest first

sql

Reset Auto-Increment (Serial)

Reset the auto-increment counter to a specific value

sql

python(8)

Dictionary with Default Value

Auto-create keys with a default value

python

Enumerate with Index

Loop through a list with both index and value

python

F-String Formatting

Format strings with variables using f-strings

python

Filter List with Comprehension

Filter a list using a conditional list comprehension

python

Read File Line by Line

Read a file line by line without loading it all into memory

python

Sort List of Dicts by Key

Sort a list of dictionaries by a specific key

python

Virtual Environment Setup

Create and activate a Python virtual environment

bash

Zip Two Lists Together

Iterate over two lists in parallel

python

react(8)

Conditional Rendering (Short Circuit)

Render a component only if a condition is true

javascript

Forward Ref to Child Component

Pass a ref from parent to child component

javascript

Get Previous State Value

Access the previous state value in setState

javascript

Lazy Load a Component

Dynamically import a component to reduce bundle size

javascript

useCallback to Memoize Function

Prevent unnecessary re-renders by memoizing callbacks

javascript

useEffect Cleanup Function

Clean up subscriptions and timers on unmount

javascript

useMemo for Expensive Calculation

Cache the result of a computation between renders

javascript

useReducer for Complex State

Manage complex state transitions with reducer

javascript

redis(5)

Delete Keys by Pattern

Delete all keys matching a pattern

bash

Flush Current Database

Delete all keys in the current database

bash

Increment a Counter

Atomically increment a value in Redis

bash

List All Keys

Show all keys in the current Redis database

bash

Set Key with Expiry

Set a Redis key with a time-to-live in seconds

bash

regex(5)

Email Validation Regex

Basic email format validation pattern

text

Extract URLs from Text

Find all URLs in a string

text

Indonesian Phone Number

Match Indonesian phone numbers (08 or +62)

text

IPv4 Address Match

Match valid IPv4 addresses

text

Strong Password Pattern

At least 8 chars, 1 uppercase, 1 number, 1 special

text

typescript(10)

Make All Fields Optional

Make every property of a type optional

typescript

Omit Keys from Object Type

Create a type with specific keys removed

typescript

Pick Specific Keys from Type

Create a type with only selected keys

typescript

Readonly Array

Make an array immutable — no push, pop, or splice

typescript

Record Type for Key-Value

Create a typed dictionary/map object

typescript

Safe String to Number

Convert a string to number without NaN issues

typescript

Satisfies Operator (TS 4.9+)

Validate a type without widening it

typescript

Template Literal Types

Create types from string patterns

typescript

Type Async Function Return

Properly type the return of an async function

typescript

Type Guard Function

Check if a value is a specific type at runtime

typescript

vim(6)

Delete Entire Line

Delete the current line in vim

vim

Indent Multiple Lines

Indent or outdent several lines at once

vim

Jump to Line Number

Go to a specific line number in vim

vim

Save and Quit

Save changes and exit vim

vim

Search and Replace

Find and replace text across the entire file

vim

Split Window

Split the vim window vertically or horizontally

vim

vscode(5)

Find and Replace All

Replace across the entire file

text

Format Document

Auto-format the current file

text

Multi-Cursor Editing

Edit multiple lines at once

text

Open Command Palette

Access all VS Code commands

text

Toggle Integrated Terminal

Open or close the terminal panel

text