How to share code snippets online
You've got a chunk of code that needs to land in someone else's screen. Slack mangles indentation. Email strips formatting. Here's how to share code online properly.
Pick the right tool for the job
The right destination depends on three questions: how long does the snippet need to live, who can see it, and does it need syntax highlighting?
- Quick paste, one-time → Hastebin, dpaste, or our paste tool
- Save & embed in docs → GitHub Gist
- Sensitive code or config → PrivateBin (end-to-end encrypted)
- Chat with developers → Slack/Discord code block with triple backticks
- StackOverflow / Reddit → Indent 4 spaces, or wrap in triple backticks
Format code so it's actually readable
Most messaging platforms (Slack, Discord, GitHub, Reddit, Stack Overflow) accept Markdown-style fenced code blocks. Triple backticks, the language name, then your code, then triple backticks:
```python
def hello(name):
print(f"Hello, {name}")
```
The language hint enables syntax highlighting. Don't skip it.
What to strip before pasting anywhere public
This is where people get burned. Before you paste, scan for:
- API keys (look for
sk-,AKIA,ghp_,xoxb-) - Database connection strings with passwords
- JWT tokens (anything that looks like
eyJ...) - Internal hostnames, IPs, or customer data
- Comments that mention internal projects or people
Once a secret hits a public paste, assume it's compromised. Rotate it. There are bots scraping pastebin all day, every day.
How much context to include
If you're asking for help, paste enough that someone can reproduce or understand the problem — but not your entire codebase. A good help post has:
- What you're trying to do (one sentence)
- The relevant function or block (10-50 lines)
- The error message or unexpected output, in full
- What you've already tried
Stack traces: keep the top, drop the middle
A 500-line Java stack trace is unhelpful. Keep the first 20 lines (the cause) and the last few (where it bubbled up to). Strip framework noise in the middle.
Sharing between your own devices
If you just need to move code from a laptop to a phone or another machine you own, you don't need a public paste at all. Use:
- This site's paste tool with the same browser profile
- iCloud Universal Clipboard (Apple)
- KDE Connect / Microsoft Phone Link (Linux / Windows)
- A private GitHub gist if you want history
Sharing code in interviews
Don't use a pastebin. Use CoderPad, CodeSandbox, or a shared VS Code Live Share session. You want execution, not just display.
Related reading: pastebin alternatives compared · markdown editor