Skip to content

Instantly share code, notes, and snippets.

View tossmilestone's full-sized avatar
:octocat:
Coding life

Shaw Ho tossmilestone

:octocat:
Coding life
  • Alauda
  • Nanjing, China
View GitHub Profile
@tossmilestone
tossmilestone / k8s-watch-diff.sh
Last active July 19, 2024 15:30
Watch the diff change of the kubernetes resource
#!/bin/bash
# Define the resource and namespace to be monitored
RESOURCE_TYPE=$1 # Can be replaced with other resource types, such as deployments, services, etc.
NAMESPACE=$2 # Can be replaced with the actual namespace
RESOURCE_NAME=$3 # If a specific resource name is specified, only monitor that resource; leave empty to monitor all resources of that type
# Get the initial resource YAML
PREVIOUS_YAML=$(kubectl get $RESOURCE_TYPE $RESOURCE_NAME -n $NAMESPACE -o yaml)$'\n'
@tossmilestone
tossmilestone / SimpleHTTPServerWithUpload.py
Created March 10, 2022 04:03 — forked from UniIsland/SimpleHTTPServerWithUpload.py
Simple Python Http Server with Upload
#!/usr/bin/env python
"""Simple HTTP Server With Upload.
This module builds on BaseHTTPServer by implementing the standard GET
and HEAD requests in a fairly straightforward manner.
"""
@tossmilestone
tossmilestone / prevent_sleep.sh
Last active February 9, 2022 08:17
Prevent macos to sleep if specified program is running
#!/bin/sh
if [[ -n "$1" ]]; then
pid=$(ps rax | awk '{print $1, $5}' | grep -i "$1" | cut -d ' ' -f 1)
if [[ -n $pid ]]; then
caffeinate -s -w "$pid" &
echo "Systemp sleep prevented by $1"
else
echo "Sorry, the $1 could not be found."
fi
else
@tossmilestone
tossmilestone / hosts
Created April 5, 2021 08:17
bettertouchtool hosts
# BetterTouchTool
127.0.0.1 bettertouchtool.net
127.0.0.1 updates.bettertouchtool.net
127.0.0.1 folivora.ai
127.0.0.1 updates.boastr.net
127.0.0.1 updates.folivora.ai
@tossmilestone
tossmilestone / rename.py
Created December 8, 2020 13:02
A simple batch rename python script
import os
import re
regex = r"\[(\d+)\]"
for f in os.listdir("./"):
if f.endswith(".mp4"):
matches = re.finditer(regex, f, re.MULTILINE)
for num, match in enumerate(matches, start=1):
ep = match.group(1)
print(r'TV.%s.mp4' % ep)
@tossmilestone
tossmilestone / v2ray-tp.sh
Last active November 4, 2024 00:04
V2ray transparent proxy for TCP
#!/bin/sh
install_v2ray(){
echo "Install v2ray..."
if [[ ! -f /usr/bin/v2ray/v2ray ]]
then
curl -Ls https://install.direct/go.sh | bash
fi
mkdir -p /etc/v2ray
@tossmilestone
tossmilestone / Certificates.go
Created January 8, 2020 02:17 — forked from Mattemagikern/Certificates.go
Create x509 certificate chain using Golang. Root CA, Designated CA, server CA
package main
import (
"crypto/rand"
"crypto/rsa"
"crypto/x509"
"crypto/x509/pkix"
"encoding/pem"
"fmt"
"math/big"
@tossmilestone
tossmilestone / python.rb
Last active January 6, 2020 17:04 — forked from SamuelMarks/python.rb
python 3.6.8 brew formula
class Python < Formula
desc "Interpreted, interactive, object-oriented programming language"
homepage "https://www.python.org/"
url "https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tar.xz"
sha256 "35446241e995773b1bed7d196f4b624dadcadc8429f26282e756b2fb8a351193"
revision 1
bottle do
sha256 "1bc5a2d3f0a8602bf2f46de7c43fcb6dde4f110c0f4518d4e802cb1f733a43de" => :high_sierra
sha256 "131d39120ac6ca2f21bf231de7414c08916cea472bc5219e0bcb49541f77cb9f" => :sierra
@tossmilestone
tossmilestone / pwfile
Last active December 16, 2019 02:30
ssh with password from a file
dev MTIzNDU2Cg==
@tossmilestone
tossmilestone / run_for_pods.sh
Created May 20, 2019 04:33
Run command for each pod in a workload
#!/bin/bash
PODS=$(kubectl get pods -n alauda-system |grep Running|grep $1|awk '{print $1}')
ARGS=${@:2}
for POD in $PODS
do
echo "Exec $ARGS on pod $POD"
kubectl exec -it -n alauda-system $POD -c $1 -- ${ARGS[@]}
done