diff --git a/jupyter.md b/jupyter.md new file mode 100644 index 0000000000..965c18e2a2 --- /dev/null +++ b/jupyter.md @@ -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/) diff --git a/kubernetes.md b/kubernetes.md new file mode 100644 index 0000000000..8137bbb769 --- /dev/null +++ b/kubernetes.md @@ -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 # 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 -o wide # Display extended information +``` + +### Describe Resources +```bash +kubectl describe # Describe a resource (node, pod, svc, etc.) +``` + +### Create and Apply Resources +```bash +kubectl apply -f # Apply a configuration to a resource from a file +# or via terminal +kubectl apply -f - < # Delete a resource by name +kubectl delete -f # Delete a resource using the configuration file +``` + +## Workload Management + +### Managing Pods +```bash +kubectl run --image= # Start a single instance of a specified image +kubectl logs # Fetch logs of a pod +kubectl exec -- # Execute a command in a pod +``` + +### Managing Deployments +```bash +kubectl set image deployment/ = # Update image of a deployment +kubectl rollout status deployment/ # Check the rollout status of a deployment +kubectl rollout undo deployment/ # Rollback to the previous deployment +``` + +### ConfigMaps and Secrets +```bash +kubectl create configmap --from-literal=key=value # Create a new configmap +kubectl create secret generic --from-literal=key=value # Create a new secret +``` + +## Debugging and Diagnostics + +### Logs and Monitoring +```bash +kubectl logs --tail=100 # Get the last 100 lines of a pod's logs +kubectl top pod # Display the CPU and memory usage of a pod +``` + +### Events and Status +```bash +kubectl get events # Get events for namespace +kubectl rollout history deployment/ # Check the history of deployments +``` + +## Node and Storage Management + +### Node Operations +```bash +kubectl cordon # Mark node as unschedulable +kubectl drain # Drain node for maintenance +``` + +### Storage +```bash +kubectl get pv # List all Persistent Volumes +kubectl get pvc # List all Persistent Volume Claims +``` \ No newline at end of file diff --git a/mongodb.md b/mongodb.md new file mode 100644 index 0000000000..6934205184 --- /dev/null +++ b/mongodb.md @@ -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 +``` + +### 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 # Backup a database +mongorestore --db # 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 +``` diff --git a/wireshark.md b/wireshark.md new file mode 100644 index 0000000000..d4179d1c93 --- /dev/null +++ b/wireshark.md @@ -0,0 +1,102 @@ +--- +title: WireShark +category: tools, network +layout: 2017/sheet +updated: 2024-03-03 +intro: | + [Wireshark](https://www.wireshark.org/) is a network analyzer. +--- + +### Capuring Modes +| Mode | Description | +|------|-------------| +| Promiscuous Mode | Capture all packets on the network segment | +| Non-Promiscuous Mode | Capture only packets addressed to the interface | + +Filtering packets +--------- +{: .-three-column} + +### Modes +| Mode | Description | +|------|-------------| +| Capture Filter | Used before or during the capture process. | +| Display Filter Syntax | Used after the capture has been completed | + +#### Syntax +- `protocol String1 String2 ComparisonOperator value` + +#### Example +- `http dest ip == 192.168.1.1 and tcp port` + +### Display Filter Syntax +| Operator | Description | Example | +|----------|-------------------------|-------------------------| +| eq or == | Equal | `ip.dest == 192.168.1.1`| +| ne or != | Not Equal | `ip.dest != 192.168.1.1`| +| gt or > | Greater than | `frame.len > 10` | +| lt or < | Less than | `frame.len < 10` | +| ge or >= | Greater than or Equal | `frame.len >= 10` | +| le or <= | Less than or Equal | `frame.len <= 10` | + +### Logical Operators +| Operator | Description | Example | +|----------|-------------------------------|----------------------------------| +| and or &&| Logical AND | `condition1 && condition2` | +| or or \|\|| Logical OR | `condition1 \|\| condition2` | +| xor or ^^| Logical XOR | `condition1 ^^ condition2` | +| not or ! | NOT (Negation) | `!condition1` | +| [n] [...]| Substring operator | `frame contains "example text"` | + +## Keyboard Shortcuts + +| Accelerator | Description | +|-------------|------------------------------------------------| +| Ctrl + E | Start/Stop Capturing | +| Tab or Shift + Tab | Move between screen elements | +| Alt + → or Option + → | Move to the next packet in the selection history | +| ↓ | Move to the next packet or detail item | +| → | In the packet detail, opens the selected tree item | +| ↑ | Move to the previous packet or detail item | +| Shift + → | In the packet detail, opens all subtrees | +| Ctrl / ⌘ + ↓ or F8 | Move to the next packet, even if the packet list isn’t focused | +| Ctrl + ↑ or F7 | Move to the previous packet, even if the packet list isn’t focused | +| Ctrl / ⌘ + → | In the packet detail, opens all tree items | +| Ctrl / ⌘ + ← | In the packet detail, closes all tree items | +| Ctrl + . | Move to the next packet of the conversation (TCP, UDP or IP) | +| Backspace | In the packet detail, jumps to the parent node | +| Ctrl + , | Move to the previous packet of the conversation (TCP, UDP or IP) | +| Return or Enter | In the packet detail, toggles the selected tree item | + +## Common Filtering Commands + +| Filter syntax | Description | +|-----------------------------|----------------------------------| +| `ip.addr == 10.10.50.1` | Wireshark Filter by IP | +| `ip.dest == 10.10.50.1` | Filter by Destination IP | +| `ip.src == 10.10.50.1` | Filter by Source | +| `ip.addr >= 10.10.50.1 and ip.addr <= 10.10.50.100` | Filter by IP range | +| `!(ip.addr == 10.10.50.1)` | Filter out/ Exclude IP address | +| `ip.addr == 10.10.50.1/24` | Filter IP subnet | +| `ip.addr == 10.10.50.1/24 and ip.addr == 10.10.51.1/24` | Filter by multiple specified IP subnets | +| `tcp.port == 25` | Filter by port (TCP) | +| `tcp.dstport == 23` | Filter by destination port (TCP) | +| `ip.addr == 10.10.50.1 and Tcp.port == 25` | Filter by ip address and port | +| `http.host == "host name"` | Filter by URL | +| `frame.time >= "June 02, 2019 18:04:00"` | Filter by time stamp | +| `tcp.flags.syn == 1` | Filter SYN flag | +| `tcp.flags.syn == 1 and tcp.flags.ack == 0` | - | +| `wlan.fc.type_subtype = 0x08` | Wireshark Beacon Filter | +| `eth.dst == ff:ff:ff:ff:ff:ff` | Wireshark broadcast filter | +| `(eth.dst[0] & 1)` | WiresharkMulticast filter | +| `ip.host = hostname` | Host name filter | +| `eth.addr == 00:70:f4:23:18:c4` | MAC address filter | +| `tcp.flags.reset == 1` | RST flag filter | + +--- + +Also see +-------- + +- [Wireshark User's Guide](https://www.wireshark.org/docs/wsug_html_chunked/) _(wireshark.org)_ +- [Wireshark CheatSheet](https://www.comparitech.com/net-admin/wireshark-cheat-sheet/) _(comparitech.com)_ \ No newline at end of file