Skip to the relevant sections if needed.
This file contains 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
Lisp interpreter in 90 lines of C++ | |
I've enjoyed reading Peter Norvig's recent articles on Lisp. He implements a Scheme interpreter in 90 lines of Python in the first, and develops it further in the second. | |
Just for fun I wondered if I could write one in C++. My goals would be | |
1. A Lisp interpreter that would complete Peter's Lis.py test cases correctly... | |
2. ...in no more than 90 lines of C++. | |
Although I've been thinking about this for a few weeks, as I write this I have not written a line of the code. I'm pretty sure I will achieve 1, and 2 will be... a piece of cake! |
This file contains 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
/* recursive mkdir based on | |
http://nion.modprobe.de/blog/archives/357-Recursive-directory-creation.html | |
*/ | |
#include <unistd.h> | |
#include <sys/types.h> | |
#include <sys/stat.h> | |
#include <string.h> | |
#define PATH_MAX_STRING_SIZE 256 |
This file contains 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 | |
# This script is used to complete the output of the docker stats command. | |
# The docker stats command does not compute the total amount of resources (RAM or CPU) | |
# Get the total amount of RAM, assumes there are at least 1024*1024 KiB, therefore > 1 GiB | |
#HOST_MEM_TOTAL=$(grep MemTotal /proc/meminfo | awk '{print $2/1024/1024}') | |
DOCKER_MEM_TOTAL=$(docker info | grep Memory | awk '{print $3}' | grep -o '[0-9]*\.[0-9]*') | |
# Get the output of the docker stat command. Will be displayed at the end |
This file contains 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
# origin link: https://gist.github.com/roachsinai/faf8ac80860065a7e78adc0b25abb445 | |
# compilation process: https://en.wikibooks.org/wiki/C%2B%2B_Programming/Programming_Languages/C%2B%2B/Code/Compiler/Linker | |
# Shared library concept: http://ehuss.com/shared/ | |
# 1. Creating the shared library | |
# Command reference: https://www.oreilly.com/library/view/c-cookbook/0596007612/ch01s05.html | |
g++ -dynamiclib -fPIC shared.cpp -o shared.so # MacOS | |
g++ -fPIC -shared shared.cpp -o shared.so # Linux |
This file contains 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 PrintA(void); | |
void PrintB(void); | |
int main(int argc, char *argv[]) | |
{ | |
PrintA(); | |
PrintB(); | |
return 0; | |
} |
This file contains 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
[custom] | |
;解决DNS泄露,无分流群组 | |
ruleset=🚀 节点选择,[]DOMAIN-SUFFIX,leetcode.cn | |
ruleset=🚀 节点选择,[]DOMAIN-SUFFIX,leetcode.com | |
ruleset=🚀 节点选择,[]DOMAIN-SUFFIX,xn--ngstr-lra8j.com | |
ruleset=🚀 节点选择,[]DOMAIN-SUFFIX,services.googleapis.cn | |
ruleset=🚀 节点选择,https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/Ruleset/GoogleCNProxyIP.list | |
ruleset=DIRECT,https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/LocalAreaNetwork.list | |
ruleset=DIRECT,https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/UnBan.list | |
ruleset=DIRECT,https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/ChinaDomain.list |
This file contains 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
// https://www.zhihu.com/question/33084689/answer/58994758 | |
#include <stdio.h> | |
#include <string.h> | |
typedef struct inst | |
{ | |
unsigned char code; // 指令 | |
unsigned char cond; // 执行该指令的条件 | |
short p1, p2; // 参数1、2 |
This file contains 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 <cstddef> | |
#include <cstdlib> | |
template <typename R, auto getter, auto setter, size_t (*offset)()> | |
struct property { | |
inline R *self() { | |
return reinterpret_cast<R *>(reinterpret_cast<size_t>(this) - offset()); | |
} | |
inline operator auto() { return (self()->*getter)(); } | |
inline void operator=(auto t) { (self()->*setter)(t); } |
This file contains 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 | |
import sys | |
import subprocess | |
from pathlib import Path | |
result = subprocess.run(sys.argv[1:], capture_output=True) | |
result.stderr = result.stderr.lower() | |