Skip to content

Instantly share code, notes, and snippets.

View junaire's full-sized avatar
😽

Jun Zhang junaire

😽
View GitHub Profile
@junaire
junaire / tailscale-self-host-derp-notes.md
Created July 17, 2024 02:55
Tailscale Self Host DERP Server Notes

tailscale 介绍

tailscale 是一个免费强大的内网穿透服务,可以将多个处在不同网络环境下的设备组成子网,使其表现于位于同一局域网中。使用 tailsacle 的一个场景是你可以随时随地 ssh 到你位于家中或办公室的 Linux 主机中。

tailscale 工作原理

tailscale 一般情况下会尝试点对点通信(打洞),如果能成功那你的延迟将非常低(几到几十毫秒)。但这并不总是能成功的,如果失败了,tailscale 将使用中继服务器(DERP)进行中转通信。一个问题是 tailscale 的 DERP 服务器都处于国外,延迟相对较高。但 tailscale 是允许自建 DERP 服务的,下面将介绍下整个过程以及各种坑。

准备

为了自建 DERP 服务,你至少需要准备:

  1. 一台你访问起来延迟较低的服务器,一般是国内服务器。
@junaire
junaire / build-root.sh
Created September 6, 2022 06:36
Simple script to build root in the CMSSW workstation
#!/bin/bash
STORAGE=/tmp
BUILDTYPE=$1
echo "Setting essential dev tools..."
source /cvmfs/sft-nightlies.cern.ch/lcg/views/dev3/latest/x86_64-centos7-gcc8-opt/setup.sh
echo "Doing a ${BUILDTYPE} build..."
@junaire
junaire / build-llvm.sh
Last active August 1, 2023 06:53
Commands used to build LLVM and Clang
git clone https://github.com/llvm/llvm-project.git
cd llvm-project
mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_EXPORT_COMPILE_COMMANDS=YES \
-DBUILD_SHARED_LIBS=ON \
-DLLVM_USE_LINKER=lld \
-DLLVM_CCACHE_BUILD=ON \
@junaire
junaire / timer.cc
Created March 8, 2022 07:07
c/c++ program time-consuming
#include <chrono>
#include <iostream>
class Timer {
public:
Timer() : start_(std::chrono::high_resolution_clock::now()){};
~Timer() {
auto end = std::chrono::high_resolution_clock::now();
auto s = std::chrono::time_point_cast<std::chrono::microseconds>(start_)
@junaire
junaire / static-polymorphism.cc
Created October 19, 2021 04:56
Static polymorphism with c++20 concepts
// Core C++ 2021 :: C++ 20 Overview: The Big Four
// https://youtu.be/emcC_Cv8EpQ
#include <iostream>
#include <tuple>
template <typename T>
concept Drawable = requires(T s) {
s.draw();
};