Skip to content

Instantly share code, notes, and snippets.

View mitsu-ksgr's full-sized avatar
🍣
🍶 🍣

mitsu-ksgr mitsu-ksgr

🍣
🍶 🍣
View GitHub Profile
@mitsu-ksgr
mitsu-ksgr / c11_get_time_test.cpp
Created June 18, 2014 15:55
C++11 で時間を取得するテストコード
#include <iostream>
#include <chrono>
// for sleep
#include <thread>
void sleep(unsigned long sleep_time)
{
std::chrono::milliseconds duration(sleep_time);
std::this_thread::sleep_for(duration);
@mitsu-ksgr
mitsu-ksgr / c11_unique_ptr_array_test.cpp
Created June 19, 2014 01:28
C++11 std::unique_ptrに配列を持たせるテスト
#include <iostream>
#include <memory>
struct Item {
public:
Item() {
std::cout << "Item::Constructor" << std::endl;
}
~Item() {
std::cout << "Item::Destructor" << std::endl;
@mitsu-ksgr
mitsu-ksgr / c11_generate_rand_engine_test.cpp
Last active August 29, 2015 14:02
C++11で追加された乱数機能をちょっぴり使いやすく。
#include <iostream>
#include <random>
#include <limits>
/**
* @brief ランダムな整数を生成する関数を作成します。
* @tparam T 実数型(short, int, long...)。省略時は unsigned int.
* @param min 乱数最小値。省略時は0が指定される。
* @param max 乱数最大値。省略時はT型の最大値が指定される。
* @return 整数乱数生成関数
@mitsu-ksgr
mitsu-ksgr / cpp_merge_vector_and_sort_with_erase_duplicates_test.cpp
Last active August 29, 2015 14:03
【C++】std::vectorをマージして、ソートと重複削除を行うテスト。
/**************************************************************************//**
* @brief Example of merge std::vector And sort with erase duplicates.
* @par Bibliography
* http://stackoverflow.com/questions/1041620/most-efficient-way-to-erase-duplicates-and-sort-a-c-vector
*
* @author Mitsu
* @date 2014-07-07. 七夕!
******************************************************************************/
#include <chrono>
#include <iostream>
@mitsu-ksgr
mitsu-ksgr / Cpp_comment_template.cpp
Created July 10, 2014 03:12
【汎用】自分用のコメント文のテンプレート
//------------------------------ Common Template ------------------------------//
////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////
/******************************************************************************
*
******************************************************************************/
@mitsu-ksgr
mitsu-ksgr / cpp_string_count_test.cpp
Last active August 29, 2015 14:04
【C++】文字列中に指定文字列がいくつ出現するかカウントする関数。UTF-8の文字列の長さを取得する関数。
#include <iostream>
/**
* @brief Return the number of occurrences of substring 'sub in string 'src'.
* @param src search target.
* @param sub substring.
* @return the number of occurrences of substring.
*/
int countSubStr(std::string &src, std::string &sub)
{
@mitsu-ksgr
mitsu-ksgr / cpp_byteorder_check_test.cpp
Created July 25, 2014 08:42
【C++】実行時にバイト・オーダを判定するコードのメモ。
#include <iostream>
#include <cstdint>
/*
1. Assigns 1 to 16bit variable.
int16_t x16 = 1;
BE : 00000000 00000001
LE : 00000001 00000000
2. Cast it to 8bit variable, then get upper 8bits.
@mitsu-ksgr
mitsu-ksgr / cpp_unique_ptr_in_vector.cpp
Created September 30, 2014 13:42
【C++】std::unique_ptrをvectorで扱うメモ
#include <iostream>
#include <memory>
#include <vector>
struct Test {
Test(int data = 0) : data(data) {
std::cout << "Test::Constructor: " << this->data << std::endl;
}
~Test() {
std::cout << "Test::Destructor: " << this->data << std::endl;
@mitsu-ksgr
mitsu-ksgr / ShebangList.md
Created October 18, 2014 17:17
【Markdown】shebang list

Shebang List

Mac OS X 10.9.x (Mavericks)

Shell
#!/usr/bin/env sh

Python
@mitsu-ksgr
mitsu-ksgr / cpp_time_test.cpp
Created October 21, 2014 01:35
【C++】時間取得のてすと
#include <iostream>
#include <ctime>
#include <thread>
#include <iomanip>
void sleep(unsigned long sleep_time)
{
std::chrono::milliseconds duration(sleep_time);
std::this_thread::sleep_for(duration);
}