Skip to content

Instantly share code, notes, and snippets.

View moycat's full-sized avatar
💮
明日晴

Qing Deng moycat

💮
明日晴
View GitHub Profile
@moycat
moycat / nvidia-dind.Dockerfile
Created March 15, 2024 04:04
Dockerfile for moycat/nvidia-dind
FROM ubuntu:22.04
ARG VERSION=5:25.0.4-1~ubuntu.22.04~jammy
RUN apt update \
&& apt install -y ca-certificates curl gpg \
&& install -m 0755 -d /etc/apt/keyrings \
&& curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc \
&& chmod a+r /etc/apt/keyrings/docker.asc \
&& echo \
@moycat
moycat / gavatar.js
Created February 2, 2024 06:59
Gavatar proxy via Cloudflare Worker
const host = "secure.gravatar.com";
const defaultSize = "512";
addEventListener("fetch", function(event) {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
// Check referer.
let referer = request.headers.get("referer")
@moycat
moycat / walk.go
Created September 14, 2022 12:45
Ultra-fast walk in Golang.
package walk
import (
"errors"
"fmt"
"os"
"path/filepath"
"sort"
"sync"
"time"
#!/bin/bash -e
PROXY=""
export http_proxy="${PROXY}" https_proxy="${PROXY}"
apt-get update
apt-get install -y \
apt-transport-https \
ca-certificates \
@moycat
moycat / install_k8s.sh
Created January 23, 2022 10:34
A script to install Kubernetes with continerd.
#!/bin/bash -e
VERSION=1.23.2
PROXY=""
cat <<EOF > /etc/modules-load.d/containerd.conf
overlay
br_netfilter
EOF
modprobe overlay
@moycat
moycat / unionfs-sandbox.sh
Created November 11, 2020 04:53
UnionFS Sandbox
# run as root
# create
mkdir -p /tmp/union/root /tmp/union/tmp
unionfs-fuse -o cow,dev,suid,allow_other /tmp/union/tmp=RW:/=RO /tmp/union/root
mount --bind /dev /tmp/union/root/dev
mount --bind /sys /tmp/union/root/sys
mount --bind /proc /tmp/union/root/proc
# enter
@moycat
moycat / field_migration.go
Created April 13, 2020 15:14
Copy contents to same-name fields of another kind of struct, with auto marshaling & unmarshaling.
package main
import (
"encoding/json"
"errors"
"fmt"
"reflect"
)
type N struct {
@moycat
moycat / redirect-to-https-non-www.js
Created March 15, 2020 07:58
Why occupy a PAGE RULE when you can do it with a WORKER? For CloudFlare users.
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
/**
* Respond to the request
* @param {Request} request
*/
async function handleRequest(request) {
url = new URL(request.url)
@moycat
moycat / icmp.go
Created March 15, 2020 05:37
Spoof ICMP package from any source IP.
package main
import (
"golang.org/x/net/ipv4"
"log"
"net"
"os"
"strconv"
"strings"
"syscall"
@moycat
moycat / add-port-forwarding.py
Created March 6, 2020 03:29
Utils for port forwarding using iptables on a single NIC Proxmox VE machine. Suppose your intranet subnet is 192.168.0.0/24, the public IP is 1.2.3.4 & the NIC is vmbr0.
#!/usr/bin/env python3
import argparse
import ipaddress
import os
INTERNAL_SUBNET = "192.168.0.0/24"
INTERNET_ADDRESS = "1.2.3.4"
INTERFACE = "vmbr0"