This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local coroutine = coroutine | |
| local function receive(p) | |
| local s, value = coroutine.resume(p) | |
| return value | |
| end | |
| local function send(x) | |
| coroutine.yield(x) | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- map(table, function) | |
| -- e.g: map({1,2,3}, function(a) return a*2 end) -> {2,4,6} | |
| function map(tbl, func) | |
| local newtbl = {} | |
| for i,v in pairs(tbl) do | |
| newtbl[i] = func(v) | |
| end | |
| return newtbl | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <assert.h> | |
| #include <stdint.h> | |
| #include <string> | |
| #include <iostream> | |
| #include <thread> | |
| #include <chrono> | |
| #include <zmq.h> | |
| #include <zmq_utils.h> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function stripJsonComments(str) { | |
| var currentChar; | |
| var nextChar; | |
| var insideString = false; | |
| var insideComment = false; | |
| var ret = ''; | |
| for (var i = 0; i < str.length; i++) { | |
| currentChar = str[i]; | |
| nextChar = str[i + 1]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <algorithm> // std::min | |
| #ifdef _WIN32 | |
| #include <windows.h> | |
| #include <dbghelp.h> | |
| #pragma comment(lib, "dbghelp") | |
| #define TRACE_MAX_STACK_FRAMES 1024 | |
| #define TRACE_MAX_FUNCTION_NAME_LENGTH 1024 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * folly::merge() is an implementation of std::merge with one additonal | |
| * guarantee: if the input ranges overlap, the order that values *from the two | |
| * different ranges* appear in the output is well defined (std::merge only | |
| * guarantees relative ordering is maintained within a single input range). | |
| * This semantic is very useful when the output container removes duplicates | |
| * (such as std::map) to guarantee that elements from b override elements from | |
| * a. | |
| * |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdint.h> | |
| #include <stdio.h> | |
| int32_t GetFileLength(const char* filename) | |
| { | |
| assert(filename); | |
| FILE* fp = fopen(filename, "r"); | |
| if (fp) | |
| { | |
| int32_t length = 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| std::string bin2hex(const void* data, size_t len) | |
| { | |
| std::string result; | |
| result.reserve(len * 2); | |
| static const char hex[] = "0123456789abcdef"; | |
| for (size_t i = 0; i < len; i++) | |
| { | |
| char ch = ((const char*)data)[i]; | |
| result += hex[ch >> 4]; | |
| result += hex[ch & 0x0f]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdint.h> | |
| #include <assert.h> | |
| #include <time.h> | |
| #define CHECK assert | |
| #if defined(_MSC_VER) | |
| #include <windows.h> | |
| inline uint64_t getPerformanceFreqency() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <WinSock2.h> | |
| #include <WS2tcpip.h> | |
| #include <Windows.h> | |
| #include <malloc.h> | |
| #include <assert.h> | |
| #include <lua.hpp> | |
| #define SOCKET_HANDLE "socket*." | |
| #define check_socket(L) (*(SOCKET*)luaL_checkudata(L, 1, SOCKET_HANDLE)) |