Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added mongodb / kubernetes / jupyter (shortcut) cheatsheet #2108

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
104 changes: 104 additions & 0 deletions jupyter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
---
title: Jupyter Notebook Keyboard Shortcuts
category: Shortcuts
layout: 2017/sheet
updated: 2024-02-15
intro: |
[Jupyter Notebook](https://jupyter.org/) is an interactive computing environment that enables users to create notebook. This cheatsheet is a quick reference for Jupyter commands and shortcuts.
---

Getting started
---------------
{: .-three-column}

### Cell Types
{: .-prime}

| Shortcut | Description |
|----------|----------------------------|
| `y` | Change to Code cell |
| `m` | Change to Markdown cell |
{: .-shortcuts}

### Keyboard Input Modes
{: .-prime}

| Shortcut | Description |
|----------|---------------------|
| `Enter` | Edit mode |
| `Esc` | Enter Command mode |
{: .-shortcuts}

### Add/Delete Cells
{: .-prime}

| Shortcut | Description |
|----------|---------------------|
| `a` | Insert cell above |
| `b` | Insert cell below |
| `dd` | Delete cell |
{: .-shortcuts}

### Run Cells
{: .-prime}

| Shortcut | Description |
|--------------|-----------------------------|
| `Ctrl+Enter` | Run selected cells |
| `Shift+Enter`| Run cell and select below |
| `Alt+Enter` | Run cell and insert below |
| `Ctrl+A` & `Shift+Enter` | Run All cell |
{: .-shortcuts}

### Move Cells
{: .-prime}

| Shortcut | Description |
|----------------------|------------------------|
| `Ctrl+Shift+Up` | Move cell up |
| `Ctrl+Shift+Down` | Move cell down |
{: .-shortcuts}

### Editing Shortcuts
{: .-prime}

| Shortcut | Description |
|----------|------------------------------------|
| `Ctrl+/` | Comment/uncomment the current line |
| `Tab` | Indent selected line(s) |
| `Shift+Tab`| Dedent selected line(s) |
| `Ctrl+d` | Delete whole line |
{: .-shortcuts}

### Basic things
{: .-prime}

| Shortcut | Description |
|------------|------------------------------------|
| `x` | Cut cell |
| `c` | Copy cell |
| `v` | Paste cell below |
| `Shift+v` | Paste cell above |
| `Shift+m` | Merge selected cells, or with the cell below |
| `h` | Open the command palette |
{: .-shortcuts}

### Viewing All Shortcuts
{: .-prime}

| Shortcut | Description |
|----------|------------------------------------|
| `h` | Open keyboard shortcut help |
{: .-shortcuts}

For Mac users
| Win | Macos |
|----------|-------------|
| `Ctrl` | `⌘ Command` |
| `Shift` | `⇧ Shift` |
| `Alt` | `⌥ Option` |

Also see
--------

- [Jupyter Notebook Tips And Shortcuts](https://digitalhumanities.hkust.edu.hk/tutorials/jupyter-notebook-tips-and-shortcuts/)
92 changes: 92 additions & 0 deletions kubernetes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
---
title: Kubernetes CLI Cheatsheet
category: Devops
layout: 2017/sheet
updated: 2024-02-15
intro: |
[Kubernetes](https://kubernetes.io/docs/home/) is an open-source container orchestration system for automating software deployment, scaling, and management. Originally designed by Google, the project is now maintained by the Cloud Native Computing Foundation. But if your only using the CLI I recommend [K9S](https://k9scli.io/).
---

# Kubernetes Cheatsheet

## Cluster Management

### Get Resources
```bash
kubectl get <resource> # List resources (nodes, pods, svc, deploy, etc.)
kubectl get all # List all resources in a namespace
kubectl get all --all-namespaces # List all resources in all namespaces
kubectl get <resource> -o wide # Display extended information
```

### Describe Resources
```bash
kubectl describe <resource> <name> # Describe a resource (node, pod, svc, etc.)
```

### Create and Apply Resources
```bash
kubectl apply -f <file.yaml> # Apply a configuration to a resource from a file
# or via terminal
kubectl apply -f - <<EOF
apiVersion: v1
kind: Pod
...
EOF
```

### Delete Resources
```bash
kubectl delete <resource> <name> # Delete a resource by name
kubectl delete -f <file.bash> # Delete a resource using the configuration file
```

## Workload Management

### Managing Pods
```bash
kubectl run <name> --image=<image> # Start a single instance of a specified image
kubectl logs <pod_name> # Fetch logs of a pod
kubectl exec <pod_name> -- <cmd> # Execute a command in a pod
```

### Managing Deployments
```bash
kubectl set image deployment/<name> <container_name>=<new_image> # Update image of a deployment
kubectl rollout status deployment/<name> # Check the rollout status of a deployment
kubectl rollout undo deployment/<name> # Rollback to the previous deployment
```

### ConfigMaps and Secrets
```bash
kubectl create configmap <name> --from-literal=key=value # Create a new configmap
kubectl create secret generic <name> --from-literal=key=value # Create a new secret
```

## Debugging and Diagnostics

### Logs and Monitoring
```bash
kubectl logs <pod_name> --tail=100 # Get the last 100 lines of a pod's logs
kubectl top pod <pod_name> # Display the CPU and memory usage of a pod
```

### Events and Status
```bash
kubectl get events # Get events for namespace
kubectl rollout history deployment/<name> # Check the history of deployments
```

## Node and Storage Management

### Node Operations
```bash
kubectl cordon <node_name> # Mark node as unschedulable
kubectl drain <node_name> # Drain node for maintenance
```

### Storage
```bash
kubectl get pv # List all Persistent Volumes
kubectl get pvc # List all Persistent Volume Claims
```
147 changes: 147 additions & 0 deletions mongodb.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
---
title: mongodb
updated: 2024-02-15
layout: 2017/sheet
category: Databases
---

## Connect to MongoDB
mongosh connects to mongodb://127.0.0.1:27017 by default
```js
mongosh "mongodb://user:password@host:port/dbname"
```

## Databases and Collections
### Show Databases
```js
show dbs
```

### Use Database
```js
use <database_name>
```

### Show Collections
```js
show collections
```

## CRUD Operations
### Create
```js
db.collection.insertOne({ key: "value" }) // Insert a single document
db.collection.insertMany([{ key: "value" }, ...]) // Insert multiple documents
```

### Read
```js
db.collection.find({}) // Find all documents
db.collection.findOne({ key: "value" }) // Find one document by key
```

### Complex Queries
```js
db.collection.find({ age: { $gt: 18, $lt: 65 }}) // Find documents with age between 18 and 65 (gt = greater than, lt = less than)
db.collection.find({ status: { $in: ["A", "B"] }}) // Find documents with status A or B
```

### Update
```js
// Upsert example
db.collection.updateOne(
{ key: "unique_value" },
{ $set: { key: "new value" } },
{ upsert: true }
)
```

### Delete
```js
db.collection.deleteOne({ key: "value" }) // Delete a single document
db.collection.deleteMany({ key: "value" }) // Delete multiple documents
```

## Indexes
### Create Index
```js
db.collection.createIndex({ key: 1 }) // Create an ascending index (1 = ascending, -1 = descending)
db.collection.createIndex({ email: 1 }, { unique: true }) // Create a unique index useful for email, username, etc. You can't have two documents with the same email
```

### List Indexes
```js
db.collection.getIndexes()
```

### Aggregation
```js
db.collection.aggregate([
{ $match: { key: "value" } },
{ $group: { _id: "$key", count: { $sum: 1 } } }
])
```

### Expanded Aggregation
```js
db.collection.aggregate([
{ $match: { status: "A" } },
{ $group: { _id: "$cust_id", total: { $sum: "$amount" } } },
{ $sort: { total: -1 } },
{ $limit: 5 }
])
```

## Replication and Sharding
### Replica Sets
```js
rs.initiate()
rs.status()
```

### Sharding
```js
sh.addShard("shard0000/mongodb0.example.net:27017")
sh.status()
```

## Administration
### Create User
```js
db.createUser({ user: "username", pwd: "password", roles: ["readWrite", "dbAdmin"]})
```

### Backup and Restore
MongoDB uses `mongodump` and `mongorestore` for backup and restoration.
```bash
mongodump --db <database_name> # Backup a database
mongorestore --db <database_name> <path_to_backup> # Restore a database
```

### Performance Monitoring
```js
db.currentOp() # Show current operations
db.stats() # Database statistics
```

## Security
### Enable Authentication
```js
mongod --auth
```

## Miscellaneous
### Run JavaScript File
```js
load("/path/to/script.js")
```

### Set Profiling Level
```js
db.setProfilingLevel(level, slowms) // level = 0 (off), 1 (slow operations), 2 (all operations)
```

### Change Streams
```js
db.collection.watch() // Watch for changes in a collection
```
Loading
Loading