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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# 参照《GB 11714-1997》《GB 32100-2015》两个标准文件 | |
class BaseCode(str): | |
MAX_LENGTH: int | |
def __new__(cls, *args, **kwargs): | |
_s = str.__new__(cls, *args, **kwargs) |
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import torch | |
import matplotlib.pyplot as plt | |
from torch.utils.data import Dataset, DataLoader | |
from torch import nn | |
class RandomLinearDataset(Dataset): |
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
def levenshtein_distance(s1: str, s2: str) -> int: | |
""" | |
求解两个字符串的莱文斯坦距离。 | |
""" | |
len1, len2 = len(s1) + 1, len(s2) + 1 | |
f = list(range(len2)) | |
for i in range(1, len1): | |
t1 = f[0] | |
f[0] += 1 | |
for j in range(1, len2): |
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 <sstream> | |
template <class _StrTyp, class _SeqTyp, class... _Arg> | |
_StrTyp join(_StrTyp&& seperator, _SeqTyp&& sequence, _Arg&&... args) | |
{ | |
using _Elem = typename _StrTyp::value_type; | |
using _Traits = typename _StrTyp::traits_type; | |
using _Alloc = typename _StrTyp::allocator_type; | |
std::basic_stringstream<_Elem, _Traits, _Alloc> oss; | |
((oss << args), ...); |
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 <queue> | |
#include <mutex> | |
#include <condition_variable> | |
#include <type_traits> | |
namespace concurrent | |
{ | |
template <class _Ty, class _Container> | |
class queue | |
: private std::queue<_Ty, _Container> |
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
#!/usr/bin/bash | |
# @see: https://superuser.com/questions/1348508/can-i-create-three-veth-interfaces-to-build-a-virtual-lan-in-linux | |
# @see: https://unix.stackexchange.com/questions/255484/how-can-i-bridge-two-interfaces-with-ip-iproute2 | |
ip -all netns del | |
ip netns add router | |
ip netns add net1 | |
ip netns add net2 |
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 <mutex> | |
#include <iostream> | |
#include <utility> | |
static std::mutex mtx_concurrent_stream; | |
struct concurrent_ostream | |
{ | |
private: | |
std::ostream&& os; |
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
// Question: | |
// @see: https://stackoverflow.com/questions/650162/why-the-switch-statement-cannot-be-applied-on-strings | |
// | |
// Solution: | |
// @see: https://blog.csdn.net/yozidream/article/details/22789147 | |
#include <iostream> | |
namespace SimpleHash | |
{ |
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 <fstream> | |
#include <iostream> | |
int interactive(const std::string& path) | |
{ | |
int count{ 0 }; | |
char buffer[1024]{ 0 }; | |
std::ifstream ifs{ path }; | |
if (!ifs) | |
return -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
#!/bin/bash | |
# TODO check if there is enough memory | |
MemFree=$(cat /proc/meminfo | grep 'MemFree' | awk '{print $2}') | |
MemNeed=1048576 | |
if [ $MemFree -lt $MemNeed ]; then | |
# memory is not enough | |
dd if=/dev/zero of=/swapfile bs=100M count=10 | |
chmod 0600 /swapfile | |
mkswap /swapfile |
NewerOlder