Dec 15, 2021
python
Migrating from Python 2 to Python 3 requires careful planning. Here’s a step-by-step guide.
Key Differences Print Statement # Python 2 print "Hello" # Python 3 print("Hello") Division # Python 2 5 / 2 # 2 # Python 3 5 / 2 # 2.5 5 // 2 # 2 Unicode # Python 2 s = u"Hello" # Python 3 s = "Hello" # Unicode by default Migration Tools # 2to3 tool 2to3 -w script.py # Modernize python-modernize script.py Best Practices Test thoroughly Update dependencies Use type hints Handle bytes/strings Update string formatting Conclusion Migrate to Python 3 for modern Python development! 🐍
ReadNov 20, 2021
rust
Axum is a modern web framework for Rust. Here’s how to build your first API.
Setup [dependencies] axum = "0.7" tokio = { version = "1", features = ["full"] } serde = { version = "1.0", features = ["derive"] } Basic Server use axum::{Router, routing::get, Json}; #[tokio::main] async fn main() { let app = Router::new() .route("/", get(handler)); axum::Server::bind(&"0.0.0.0:3000".parse().unwrap()) .serve(app.into_make_service()) .await .unwrap(); } async fn handler() -> Json<serde_json::Value> { Json(serde_json::json!({"message": "Hello, World!"})) } Routes let app = Router::new() .route("/users", get(get_users)) .route("/users/:id", get(get_user)); JSON Handling use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize)] struct User { id: u32, name: String, } async fn create_user(Json(user): Json<User>) -> Json<User> { Json(user) } Best Practices Use type-safe routing Handle errors properly Use middleware Test endpoints Document APIs Conclusion Build fast and safe APIs with Rust and Axum! 🦀
ReadOct 15, 2021
python
Optimizing Spark jobs is crucial for performance. Here’s how to use partitioning and bucketing effectively.
Partitioning from pyspark.sql import SparkSession spark = SparkSession.builder.appName("Optimization").getOrCreate() # Repartition df = df.repartition(10, "column_name") # Coalesce df = df.coalesce(5) Bucketing df.write \ .bucketBy(10, "bucket_column") \ .sortBy("sort_column") \ .saveAsTable("bucketed_table") Broadcast Joins from pyspark.sql.functions import broadcast result = large_df.join(broadcast(small_df), "key") Caching df.cache() df.persist() Best Practices Partition appropriately Use bucketing for joins Broadcast small tables Cache frequently used data Monitor performance Conclusion Optimize Spark jobs for better performance! ⚡
Read