代码片段

#! /bin/sh
echo $0
echo $1
echo $@
echo $#

andy$./test.sh 1 2 3 4 .
/test.sh 1 1 2 3 4 4
print(select('#', ...))
print(select(2, ...))
local arg = select(2, ...)
print("arg=" .. arg)

andy$ lua test.lua 1 2 3
3
2    3
arg=2
for k, v in pairs(table) do
    print("key = " .. k .. ", value = " .. v)
end

 

//c++11 get elapsed time
#include <chrono> auto last_time = std::chrono::steady_clock::now();
auto now = std::chrono::steady_clock::now(); auto elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(now - last_time);
if(elapsed_time.count() > 100) {//do sth}

 

#include <iostream>
#include <chrono>

int main() {
// 使用 system_clock 获取当前系统时间
auto system_now = std::chrono::system_clock::now();

// 使用 steady_clock 获取当前稳定时间
auto steady_now = std::chrono::steady_clock::now();

// 使用 high_resolution_clock 获取当前高分辨率时间
auto high_resolution_now = std::chrono::high_resolution_clock::now();

// 输出当前时间点
std::cout << "System clock now: " << system_now.time_since_epoch().count() << std::endl;
std::cout << "Steady clock now: " << steady_now.time_since_epoch().count() << std::endl;
std::cout << "High resolution clock now: " << high_resolution_now.time_since_epoch().count() << std::endl;

return 0;
}

 

#include <sstream>

std::ostringstream os; os
<< memory.uMemoryUsed; obj["uMemoryUsed"] = os.str(); //os.clear(); this method doesn't clear the buffer... clear : clears error and eof flags os.str(""); os << memory.uMemoryTotal; obj["uMemoryTotal"] = os.str(); os.str(""); os << memory.uProcessMemroyUsed; obj["uProcessMemroyUsed"] = os.str();

 


#include <iostream>


template<typename T>
class LD_Singleton
{
public:
static T& getInstance() {
static T value;
return value;
}
private:
LD_Singleton();
~LD_Singleton();
};

 

LD_Singleton<bool>::getInstance() = true;
g_enable_new_bitrate_table = LD_Singleton<bool>::getInstance();

 

posted @ 2016-10-15 21:23  AndyHu518  阅读(164)  评论(0)    收藏  举报