Snippets

devcodinglab.com · quick snippets

Code Snippets & Setup Commands

Copy-ready boilerplate, CLI commands, and small patterns I keep on hand for Quantum Python, Android, C++, and Git.

1. Quantum Python Venv & Statevector Check

Quick sanity test to confirm Qiskit Aer and PennyLane are working inside a fresh environment.

quantum_check.py Python 3.10+
import pennylane as qml
from qiskit import QuantumCircuit

qc = QuantumCircuit(1)
qc.h(0)
print(qc.draw(output="text"))
print("PennyLane:", qml.__version__)

2. Android & Kotlin

Room DAO with reactive Flow observation and ViewModel coroutine insertion. See full walkthroughs in Room CRUD and SharedPreferences (Java).

TaskViewModel.kt Android / Room
class TaskViewModel(private val dao: TaskDao) : ViewModel() {
    val tasks = dao.observeAll()

    fun insertTask(title: String) {
        viewModelScope.launch {
            dao.insert(TaskEntity(title = title))
        }
    }
}

3. C++ Graph & Fast I/O

Standard competitive / DSA boilerplate for fast stdin/stdout and iterative breadth-first search.

bfs_fastio.cpp C++17
#include <bits/stdc++.h>
using namespace std;

void bfs(int start, const vector<vector<int>>& adj) {
    vector<bool> vis(adj.size(), false);
    queue<int> q;
    vis[start] = true; q.push(start);
    while (!q.empty()) {
        int u = q.front(); q.pop();
        for (int v : adj[u]) if (!vis[v]) {
            vis[v] = true; q.push(v);
        }
    }
}

4. Git SSH & Troubleshooting

Dedicated SSH host alias for cloning private repositories cleanly. Full note: Can’t Clone a Private GitHub Repo?

~/.ssh/config Git / SSH
Host github-work
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_ed25519_work
  IdentitiesOnly yes
Dev Coding Lab — Snippets & Commands