Skip to content

Instantly share code, notes, and snippets.

View Shaun289's full-sized avatar

Sunjong Park Shaun289

View GitHub Profile
@Shaun289
Shaun289 / copy_if.cpp
Created January 17, 2023 03:13
C++ Functional : filter copy_if
#include <iostream>
#include <vector>
#include <numeric>
#include <gtest/gtest.h>
TEST(test_copy_if, TestOdd)
{
std::vector<int> v1(10);
std::vector<int> v2(5);
std::iota(v1.begin(), v1.end(), 0);
@Shaun289
Shaun289 / rvo.cpp
Created January 16, 2023 07:01
Return value optimization
#include <iostream>
class C
{
private:
int _data;
public:
C(int data) {
_data = data;
@Shaun289
Shaun289 / gist:ea60d52b6b2329d8e91a7ff1699535af
Created November 7, 2022 08:45
settings.json for cpptools exclude
{
"files.exclude": {
"**/exclude_path1": true,
"**/exclude_path2": true
},
"search.exclude": {
"**/exclude_path1": true,
"**/exclude_path2": true
}
}
@Shaun289
Shaun289 / gist:aca195a807ccb46a46166eec705827d6
Created October 7, 2022 22:57
exercism : reverse string
/// https://exercism.org/tracks/rust/exercises/reverse-string/iterations?idx=1
/// 함수형으로 쉽게 할 수 있으나 문제 의도에 맞춰 iteration으로 만듬
/// 기초적인 언어 문제를 다시 생각할 수 있게 되서 좋았음
pub fn reverse(input: &str) -> String {
//input.chars().rev().collect()
let len = input.len();
let mut s = String::with_capacity(input.len());
for c in input.chars().rev() {
s.push(c);
@Shaun289
Shaun289 / duration.cpp
Last active May 27, 2022 10:49
C++11 성능 측정을 위한 간단히 ms 단위 측정 코드
#include <iostream>
#include <chrono>
#include <thread>
/**
# 성능 측정을 위한 간단히 ms 단위 측정 코드
- C++11 코드로 작성
- 명확하게 하기 위해 일부러 namespace는 사용하지 않음
- chrono_literals 의 ms 등 편리한 operator는 C++14부터 사용 가능
@Shaun289
Shaun289 / keyboard_numpad.cnf
Created May 10, 2022 01:19
Teraterm keyboard.cnf for numpad
[VT numeric keypad]
;Num pad 0 key
Num0=off
;Num pad 1 key
Num1=off
;Num pad 2 key
Num2=off
;Num pad 3 key
Num3=off
@Shaun289
Shaun289 / thread_condition_variable_and_async.md
Last active April 1, 2022 13:34
thread condition_variable and async

thread and condition_variable

                 thread1     thread2
                    |            | wait
   do_my_job        |            |
                    |            |
   notify_one       |----------->|
                    |            | wakeup
 do_my_job | |
@Shaun289
Shaun289 / cv_test.cpp
Created April 1, 2022 09:13
c++11 condition_variable test
#include <iostream>
#include <chrono>
#include <thread>
#include <mutex>
#include <condition_variable>
/// compile : g++ -std=c++11 -pthread cv_test.cpp -o cv_test && ./cv_test
std::condition_variable _cv;
std::mutex _mutex;
@Shaun289
Shaun289 / closure_fn.rs
Created November 10, 2021 21:45
Rust study : As input parameters
/*
The rust by example ko https://hanbum.gitbooks.io/rustbyexample/content/fn/closures/input_parameters.html
compiled on https://play.rust-lang.org/
Fn 클로저는 참조로 획득 (&T)
FnMut 클로저는 가변참조로 획득 (&mut T)
FnOnce 클로저는 값으로 획득 (T)
...
이해가 잘 안되네..
*/
@Shaun289
Shaun289 / closure_capturing.rs
Created November 9, 2021 04:23
Rust study : closure capturing
/*
The rust by example ko https://hanbum.gitbooks.io/rustbyexample/content/fn/closures/capture.html
compiled on https://play.rust-lang.org/
result :
*/
fn main()
{
use std::mem;