본문 바로가기

전체 글293

[Rust] Derive 예제 (54일차) // 'Centimeters', a tuple struct that can be compared #[derive(PartialEq, PartialOrd)] struct Centimeters(f64); // 'Inches', a tuple struct that can be printed #[derive(Debug)] struct Inches(i32); impl Inches { fn to_centimeters(&self) -> Centimeters { let &Inches(inches) = self; Centimeters(inches as f64 * 2.54) } } // 'Seconds', a tuple struct with no additional attributes struct Seconds(i32);.. 2023. 2. 7.
[JavaScript] Input에 null 값 막기 script에 click event function으로 들어오는 값을 검수하여 null이면 알림을 띄운다 input 자체에서 null 값을 못 넣게 한다 -> required 넣기 ==> required 만 넣으면 Browser에서 알아서, text 넣으라고 알림을 띄운다! https://ninetynine-2026.tistory.com/320 2023. 2. 5.
[Rust] Tokio 예제 : 기본 (53일차) use tokio::net::TcpListener; use tokio::io::{AsyncReadExt, AsyncWriteExt}; #[tokio::main] async fn main() -> Result { let listener = TcpListener::bind("127.0.0.1:8080").await?; loop { let (mut socket, _) = listener.accept().await?; tokio::spawn(async move { let mut buf = [0; 1024]; // In a loop, read data from the socket and write the data back. loop { let n = match socket.read(&mut buf).await {.. 2023. 2. 5.
[Rust] HashMap 예제 (52일차) fn main() { use std::collections::HashMap; // HashMap 생성 let mut hash_ages : HashMap = HashMap::new(); // 데이터 삽입 hash_ages.insert(String::from("Nachfolge"), 32); println!("HashMap : {:?}", hash_ages); } fn main() { use std::collections::HashMap; // HashMap 키에 해당하는 벡터 생성 let names = vec![String::from("Nachfolge"), String::from("Selah")]; // HashMap 값에 해당하는 벡터 생성 let ages = vec![10, 50]; // HashMa.. 2023. 2. 3.
[Rust] Overloading 예제 (51일차) use std::ops; struct Foo; struct Bar; #[derive(Debug)] struct FooBar; #[derive(Debug)] struct BarFoo; // The 'std::ops::Add' trait is used to specify the functionality of '+'. // Here, we make 'Add' - the trait for addition with a RHS of type 'Bar'. // The follow block implements the operation: Foo + bar = FooBar impl ops::Add for Foo { type Output = FooBar; fn add(self, _rhs: Bar) -> FooBar { p.. 2023. 2. 2.
[Rust] Field Init Shorthand, 필드 초기화 (50일차) Field Init Shorthand : 필드 초기화 단축 을 쓰는 이유? >> name field를가진 Data Structure (struct, enum, union)를 초기화할 때 fieldname: fieldname 형식으로 fieldname 작성을 압축 시켜 Code 중복을 적게하고 압축된 Syntax를 제공, >> When initializing a data structure (struct, enum, union) with named fields, allow writing fieldname as a shorthand for fieldname: fieldname. This allows a compact syntax for initialization, with less duplication. #[.. 2023. 2. 1.
[Rust] Web Server : Multi-Threading 추가 (49일차) >> 이전에 작업한 lib.rs 파일 Code 를 수정 >> 중간에 lifetime syntax ` 로 인해 주석처럼 보이나, 정상 Compile 되는 코드다. use std::thread; use std::sync::mpsc; use std::sync::Arc; use std::sync::Mutex; pub struct ThreadPool { workers: Vec, sender: mpsc::Sender, } trait FnBox { fn call_box(self: Box); } impl FnBox for F { fn call_box(self: Box) { (*self)() } } type Job = Box ThreadPool { assert!(size > 0); let (sender, receiver.. 2023. 1. 31.
[MySQL] Partition 예제 ==> PARTITION 할 때 Column 하나에만 Primary Key 를 걸면 Error 발생. ==> 모든 Column 을 Partition 해야함. CREATE TABLE sales ( sales_id INT, sales_date DATE, amount INT, PRIMARY KEY (sales_id, sales_date, amount) ) PARTITION BY RANGE(YEAR(sales_date)) ( PARTITION p_2015 VALUES LESS THAN (2016), PARTITION p_2016 VALUES LESS THAN (2017), PARTITION p_2017 VALUES LESS THAN (2018), PARTITION p_others VALUES LESS THAN .. 2023. 1. 30.