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
// | |
// Created by shawnfeng on 2021-08-12. | |
// https://gist.github.com/ShawnFeng0/429b6caef85ec0d32f34081374dcdb8a | |
// | |
#pragma once | |
#include <atomic> | |
#include <condition_variable> | |
#include <mutex> |
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
find -type d -empty | xargs -t -L1 -I _ touch _/.gitkeep |
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/sh | |
if [ $# -lt 3 ] ; then | |
echo "Usage: $0 old_email new_email new_name" | |
echo "Example: $0 [email protected] [email protected] new_name" | |
exit 1; | |
fi | |
echo "old_email: $1" | |
echo "new_email: $2" |
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
sync && dd if=/dev/zero of=/var/avi/mmc0/tmp.bin bs=1M count=100 && sync && dd if=/var/avi/mmc0/tmp.bin of=/dev/null bs=1M |
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 <openssl/evp.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <string> | |
#include <vector> | |
// From https://www.openssl.org/docs/man1.1.1/man3/EVP_EncryptInit.html | |
static bool CryptAes256Cfb(const std::vector<uint8_t> &key, | |
const std::vector<uint8_t> &iv, |
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; | |
} |
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
// 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
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
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--) { |