Initial commit
Initial commit Add lua template
This commit is contained in:
62
posts/async-rust.md
Normal file
62
posts/async-rust.md
Normal file
@@ -0,0 +1,62 @@
|
||||
# Async Programming in Rust
|
||||
|
||||
Asynchronous programming in Rust allows you to write concurrent code that's both fast and safe.
|
||||
|
||||
## What is Async?
|
||||
|
||||
Async programming is about doing multiple things at once without blocking. Instead of waiting for one operation to complete before starting another, async code can switch between tasks.
|
||||
|
||||
## Key Concepts
|
||||
|
||||
### Futures
|
||||
|
||||
A `Future` represents a value that may not be available yet:
|
||||
|
||||
```rust
|
||||
async fn fetch_data() -> String {
|
||||
// Simulate async work
|
||||
tokio::time::sleep(Duration::from_secs(1)).await;
|
||||
"Data fetched!".to_string()
|
||||
}
|
||||
```
|
||||
|
||||
### Async/Await
|
||||
|
||||
The `async` keyword makes a function asynchronous, and `await` pauses execution until a future is ready:
|
||||
|
||||
```rust
|
||||
async fn process_data() {
|
||||
let data = fetch_data().await;
|
||||
println!("Got: {}", data);
|
||||
}
|
||||
```
|
||||
|
||||
### Runtimes
|
||||
|
||||
Rust doesn't have a built-in async runtime. Popular choices include:
|
||||
|
||||
- **Tokio**: Full-featured runtime
|
||||
- **async-std**: Standard library approach
|
||||
- **smol**: Minimal runtime
|
||||
|
||||
## Example: Concurrent HTTP Requests
|
||||
|
||||
```rust
|
||||
use tokio::task;
|
||||
|
||||
async fn fetch_all() {
|
||||
let task1 = task::spawn(fetch_url("https://api1.example.com"));
|
||||
let task2 = task::spawn(fetch_url("https://api2.example.com"));
|
||||
let task3 = task::spawn(fetch_url("https://api3.example.com"));
|
||||
|
||||
let (result1, result2, result3) = tokio::join!(task1, task2, task3);
|
||||
}
|
||||
```
|
||||
|
||||
## Benefits
|
||||
|
||||
- **Performance**: Handle thousands of connections efficiently
|
||||
- **Resource Usage**: Lower memory and CPU usage
|
||||
- **Scalability**: Build systems that scale
|
||||
|
||||
Async Rust might seem complex at first, but it's worth learning for building high-performance applications!
|
||||
91
posts/git-workflow.md
Normal file
91
posts/git-workflow.md
Normal file
@@ -0,0 +1,91 @@
|
||||
# Git Workflow Best Practices
|
||||
|
||||
Git is an essential tool for modern software development. Here are some best practices for an effective Git workflow.
|
||||
|
||||
## Branching Strategy
|
||||
|
||||
### Main Branches
|
||||
|
||||
- **main/master**: Production-ready code
|
||||
- **develop**: Integration branch for features
|
||||
|
||||
### Supporting Branches
|
||||
|
||||
- **feature/**: New features
|
||||
- **bugfix/**: Bug fixes
|
||||
- **hotfix/**: Urgent production fixes
|
||||
|
||||
## Commit Messages
|
||||
|
||||
Good commit messages are crucial:
|
||||
|
||||
```
|
||||
Add user authentication system
|
||||
|
||||
- Implement JWT token generation
|
||||
- Add login and logout endpoints
|
||||
- Create user session middleware
|
||||
```
|
||||
|
||||
Follow the 50/72 rule:
|
||||
- First line: 50 characters or less
|
||||
- Body: Wrap at 72 characters
|
||||
|
||||
## Commands
|
||||
|
||||
### Creating a Feature Branch
|
||||
|
||||
```bash
|
||||
git checkout -b feature/new-feature develop
|
||||
```
|
||||
|
||||
### Committing Changes
|
||||
|
||||
```bash
|
||||
git add .
|
||||
git commit -m "Add feature description"
|
||||
```
|
||||
|
||||
### Merging
|
||||
|
||||
```bash
|
||||
git checkout develop
|
||||
git merge --no-ff feature/new-feature
|
||||
git branch -d feature/new-feature
|
||||
```
|
||||
|
||||
## Tips
|
||||
|
||||
1. **Commit Often**: Make small, logical commits
|
||||
2. **Pull Regularly**: Stay in sync with the team
|
||||
3. **Review Before Commit**: Use `git diff` to check changes
|
||||
4. **Use .gitignore**: Don't commit build artifacts or secrets
|
||||
|
||||
## Advanced Features
|
||||
|
||||
### Interactive Rebase
|
||||
|
||||
Clean up commit history:
|
||||
|
||||
```bash
|
||||
git rebase -i HEAD~3
|
||||
```
|
||||
|
||||
### Stashing
|
||||
|
||||
Save work in progress:
|
||||
|
||||
```bash
|
||||
git stash
|
||||
git stash pop
|
||||
```
|
||||
|
||||
### Cherry-pick
|
||||
|
||||
Apply specific commits:
|
||||
|
||||
```bash
|
||||
git cherry-pick <commit-hash>
|
||||
```
|
||||
|
||||
Master Git, and you'll be a more effective developer!
|
||||
38
posts/hello-world.md
Normal file
38
posts/hello-world.md
Normal file
@@ -0,0 +1,38 @@
|
||||
# Hello World
|
||||
|
||||
Welcome to my blog! This is my first post written in Markdown and served by a custom Rust web server.
|
||||
|
||||
## Features
|
||||
|
||||
This blog supports:
|
||||
|
||||
- **CommonMark** markdown parsing
|
||||
- Git-based cache invalidation
|
||||
- Template-driven rendering
|
||||
- Custom template tags
|
||||
|
||||
## Code Example
|
||||
|
||||
Here's a simple Rust function:
|
||||
|
||||
```rust
|
||||
fn greet(name: &str) -> String {
|
||||
format!("Hello, {}!", name)
|
||||
}
|
||||
```
|
||||
|
||||
## Lists
|
||||
|
||||
Unordered list:
|
||||
- Item one
|
||||
- Item two
|
||||
- Item three
|
||||
|
||||
Ordered list:
|
||||
1. First item
|
||||
2. Second item
|
||||
3. Third item
|
||||
|
||||
---
|
||||
|
||||
Thanks for reading!
|
||||
62
posts/markdown-guide.md
Normal file
62
posts/markdown-guide.md
Normal file
@@ -0,0 +1,62 @@
|
||||
# Markdown Guide
|
||||
|
||||
This blog uses CommonMark for rendering markdown content. Here's a quick guide to the syntax.
|
||||
|
||||
## Headers
|
||||
|
||||
Use `#` for headers:
|
||||
|
||||
```markdown
|
||||
# H1
|
||||
## H2
|
||||
### H3
|
||||
```
|
||||
|
||||
## Emphasis
|
||||
|
||||
- *Italic* with `*asterisks*`
|
||||
- **Bold** with `**double asterisks**`
|
||||
- ~~Strikethrough~~ with `~~tildes~~`
|
||||
|
||||
## Links and Images
|
||||
|
||||
Links: `[Link text](https://example.com)`
|
||||
|
||||
Images: ``
|
||||
|
||||
## Blockquotes
|
||||
|
||||
> This is a blockquote.
|
||||
> It can span multiple lines.
|
||||
|
||||
## Code
|
||||
|
||||
Inline `code` with backticks.
|
||||
|
||||
Code blocks with triple backticks:
|
||||
|
||||
```python
|
||||
def hello():
|
||||
print("Hello, world!")
|
||||
```
|
||||
|
||||
## Tables
|
||||
|
||||
| Column 1 | Column 2 | Column 3 |
|
||||
|----------|----------|----------|
|
||||
| Data 1 | Data 2 | Data 3 |
|
||||
| More | Data | Here |
|
||||
|
||||
## Task Lists
|
||||
|
||||
- [x] Completed task
|
||||
- [ ] Incomplete task
|
||||
- [ ] Another task
|
||||
|
||||
## Horizontal Rule
|
||||
|
||||
Use three or more hyphens:
|
||||
|
||||
---
|
||||
|
||||
That's the basics of Markdown!
|
||||
57
posts/rust-web-servers.md
Normal file
57
posts/rust-web-servers.md
Normal file
@@ -0,0 +1,57 @@
|
||||
# Building Web Servers in Rust
|
||||
|
||||
Rust has become a popular choice for building web servers due to its performance and safety guarantees.
|
||||
|
||||
## Why Rust for Web Development?
|
||||
|
||||
1. **Memory Safety**: No null pointer exceptions or data races
|
||||
2. **Performance**: Comparable to C/C++
|
||||
3. **Concurrency**: Fearless concurrency with async/await
|
||||
4. **Type System**: Catch errors at compile time
|
||||
|
||||
## Popular Frameworks
|
||||
|
||||
### Axum
|
||||
|
||||
Axum is a modern web framework built on top of Tokio. It provides:
|
||||
|
||||
- Type-safe routing
|
||||
- Extractors for parsing requests
|
||||
- Middleware support
|
||||
- Great ergonomics
|
||||
|
||||
### Actix Web
|
||||
|
||||
Actix Web is a powerful, pragmatic framework that:
|
||||
|
||||
- Uses the actor model
|
||||
- Provides excellent performance
|
||||
- Has a mature ecosystem
|
||||
|
||||
### Rocket
|
||||
|
||||
Rocket focuses on:
|
||||
|
||||
- Developer ergonomics
|
||||
- Type-safe routing
|
||||
- Easy to learn
|
||||
|
||||
## Example Server
|
||||
|
||||
```rust
|
||||
use axum::{routing::get, Router};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let app = Router::new()
|
||||
.route("/", get(|| async { "Hello, World!" }));
|
||||
|
||||
let listener = tokio::net::TcpListener::bind("127.0.0.1:3000")
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
axum::serve(listener, app).await.unwrap();
|
||||
}
|
||||
```
|
||||
|
||||
This is just the beginning of what you can build with Rust!
|
||||
Reference in New Issue
Block a user