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 <ctype.h> | |
#include <inttypes.h> | |
#include <stdio.h> | |
#include <string.h> | |
uintptr_t HexDumpData(const uint8_t *data, size_t length, size_t width = 16, | |
uintptr_t base_address = 0, bool tail_addr_out = true) { | |
const uint8_t *data_cur = data; | |
if (!data || width == 0) return 0; | |
while (length) { |
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
#!/bin/bash | |
target_language=$(trans -id ${!#} | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})*)?m//g" | awk '$1=="Code" && $2!="zh-CN" {printf ":zh-CN"}') | |
trans $target_language "$@" |
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
// Reference from kfifo of linux | |
class FifoPowerOfTwo { | |
#define _is_power_of_2(x) ((x) != 0 && (((x) & ((x)-1)) == 0)) | |
public: | |
FifoPowerOfTwo(void *buffer, size_t buf_size, size_t element_size = 1) | |
: data_((unsigned char *)buffer), | |
element_size_(element_size != 0 ? element_size : 1), | |
is_allocated_memory_(false) { | |
size_t num_elements = buf_size / element_size_; |
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
#pragma once | |
#include <stdio.h> | |
#include <string.h> | |
// Precompiler define to get only filename; | |
#if !defined(__FILENAME__) | |
#define __FILENAME__ \ | |
(strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 \ | |
: strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 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 <ulog/ulog.h> | |
namespace ulog { | |
namespace token { | |
// void * | |
inline void print(const char *name, const void *value) { | |
logger_raw(false, "%s => %p", name ? name : "unnamed", value); | |
} |
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
void *memcpy(void *dst, void *src, unsigned n) { | |
if (!dst || !src) { | |
return nullptr; | |
} | |
auto dst_c = (char *) dst; | |
auto src_c = (char *) src; | |
if (dst_c < src || dst_c > (src_c + n)) { | |
while (n--) { |
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
template<typename T> | |
static inline auto RoundPowOfTwo(T n) -> decltype(n) { | |
uint64_t value = n; | |
// Fill 1 | |
value |= value >> 1U; | |
value |= value >> 2U; | |
value |= value >> 4U; | |
value |= value >> 8U; | |
value |= value >> 16U; |
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
// Convert a struct sockaddr address to a string, IPv4 and IPv6: | |
char *get_ip_str(const struct sockaddr *sa, char *s, size_t maxlen) | |
{ | |
switch(sa->sa_family) { | |
case AF_INET: | |
inet_ntop(AF_INET, &(((struct sockaddr_in *)sa)->sin_addr), | |
s, maxlen); | |
break; |
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 <vector> | |
#include <string> | |
inline std::vector<std::string> Split(const std::string &s, const std::string &delimiters = " ") { | |
std::vector<std::string> tokens; | |
std::string::size_type start = s.find_first_not_of(delimiters, 0); | |
std::string::size_type end = s.find_first_of(delimiters, start); | |
while (std::string::npos != end || std::string::npos != start) { | |
tokens.emplace_back(s.substr(start, end - start)); | |
start = s.find_first_not_of(delimiters, 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
unsigned char HexNumber(char c) { | |
if (c >= '0' && c <= '9') { | |
return c - '0'; | |
} else if (c >= 'a' && c <= 'f') { | |
return c - 'a' + 10; | |
} else if (c >= 'A' && c <= 'F') { | |
return c - 'A' + 10; | |
} else { | |
return 0; | |
} |