Skip to content

Instantly share code, notes, and snippets.

@gaoyifan
gaoyifan / gist:7c4d4bac07172141157472d0c2da6525
Last active January 24, 2024 13:30
Install winget on Windows Server 2022
# from https://gist.github.com/likamrat/cae833a6e5b3461709f14c093c21c293?permalink_comment_id=4634351#gistcomment-4634351
# Install Chocolately Package Manager
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
$env:Path = [System.Environment]::ExpandEnvironmentVariables([System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User"))
# Install WinGet from Chocolatey
choco install winget
choco install winget.powershell
#!/usr/bin/env bash
# require: git version > 2.3
# require: `db/letsencrypt` existed in git repo
if [[ -z "$CERTBOT_DOMAIN" ]] || [[ -z "$CERTBOT_VALIDATION" ]]; then
echo '$CERTBOT_DOMAIN and $CERTBOT_VALIDATION environment variables required.'
fi
source /etc/letsencrypt/dns-auth.conf
@gaoyifan
gaoyifan / convertor.py
Created June 11, 2023 08:56
dhcp option 121 hex format convertor
import ipaddress
def hex_to_cidr(hex_str):
i = 0
while i < len(hex_str):
# The first byte is the mask
mask = int(hex_str[i:i+2], 16)
i += 2
# Calculate how many bytes the subnet will occupy
@gaoyifan
gaoyifan / tc-mark.nft
Created September 24, 2018 10:20
Traffic control mark with nftables
#! /usr/sbin/nft -f
chain tc-wan {
# check default priority
mark & 0xff0 == 0x130 ip dscp set af22 return
# real-time application
## Dota2
udp dport 27000-27200 \
meta mark set mark & 0xfffff00f ^ 0x110 ip dscp set af41 return
@gaoyifan
gaoyifan / gen.py
Last active January 9, 2023 07:56
frame rate testing with opencv
import cv2
import pyqrcode
import numpy as np
import io
# Set the width, height and frame rate of the video
width, height, fps = 512, 512, 10
# Create a video writer object, using FFmpeg
@gaoyifan
gaoyifan / google-fonts-proxy
Last active November 10, 2022 10:02
google-fonts-proxy
server {
listen 80;
listen 443;
listen [::]:80;
listen [::]:443;
server_name fonts.lug.ustc.edu.cn;
access_log /var/log/nginx/revproxy_access.log;
error_log /var/log/nginx/revproxy_error.log;
@gaoyifan
gaoyifan / ubuntu-mount-new-disk.md
Last active November 18, 2021 07:49
ubuntu 添加新硬盘

ubuntu 添加新硬盘

查看硬盘:

# fdisk -l
...
Disk /dev/sdb: 274.9 GB, 274877906944 bytes
255 heads, 63 sectors/track, 33418 cylinders, total 	536870912 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
#!/usr/bin/env bash
set -xe
apt install -y build-essential git gcc-arm-none-eabi bison flex device-tree-compiler bc debootstrap
BASE=${BASE:-$(mktemp -d)}
cd $BASE
pwd
git clone https://github.com/ARM-software/arm-trusted-firmware.git
@gaoyifan
gaoyifan / uml-on-debian.md
Created November 21, 2016 14:37
User Mode Linux on Debian Jessie

User Mode Linux on Debian Jessie

host kernel version: 3.16.36-1+deb8u2

target kernel version: 4.9-rc5

Build UML kernel

Preparation

@gaoyifan
gaoyifan / RTAI installation for ubuntu 14.04.md
Last active March 17, 2019 10:31
RTAI installation for ubuntu 14.04

RTAI installation for ubuntu 14.04

Preparation

download and unzip

cd /usr/src
curl -L https://www.rtai.org/userfiles/downloads/RTAI/rtai-4.1.tar.bz2 | tar xj
curl -L https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.10.32.tar.xz | tar xJ
curl -L http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.10.32-saucy/linux-image-3.10.32-031032-generic_3.10.32-031032.201402221635_amd64.deb -o linux-image-3.10.32-generic-amd64.deb