Skip to content

Instantly share code, notes, and snippets.

View yuchen's full-sized avatar
🌴
On vacation

clark yuchen

🌴
On vacation
  • china, shanghai
  • 23:17 (UTC +08:00)
View GitHub Profile
@yuchen
yuchen / egos_throttle.sh
Created July 5, 2024 02:46 — forked from golimpio/egos_throttle.sh
Run cputhrottle for a list of applications in order to limit their CPU usage.
#!/bin/bash
# Run cputhrottle for a list of applications in order to limit their CPU usage.
# This script needs `pidof` and `cputhrottle` installed, which can be installed from homebrew.
# NOTE: This script was tested on MacOS only.
if [[ $EUID > 0 ]]; then
echo "Please run this script as root/sudo"
exit 1
fi
@yuchen
yuchen / curl.md
Last active February 3, 2021 03:10 — forked from subfuzion/curl.md
curl POST examples #shell #cmd

Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.

-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).

-c, --cookie-jar <file name> File to save response cookies to.

@yuchen
yuchen / .screenrc
Created April 1, 2020 03:39 — forked from joaopizani/.screenrc
A killer GNU Screen Config
# the following two lines give a two-line status, with the current window highlighted
hardstatus alwayslastline
hardstatus string '%{= kG}[%{G}%H%? %1`%?%{g}][%= %{= kw}%-w%{+b yk} %n*%t%?(%u)%? %{-}%+w %=%{g}][%{B}%m/%d %{W}%C%A%{g}]'
# huge scrollback buffer
defscrollback 5000
# no welcome message
startup_message off
@yuchen
yuchen / client.go
Last active January 10, 2022 03:47 — forked from jpillora/client.go
[Go Yamux Example] yamux sample code #golang
package main
import (
"fmt"
"log"
"net"
"time"
"github.com/hashicorp/yamux"
)
@yuchen
yuchen / wsl-ssh-server.md
Last active February 16, 2022 02:58 — forked from dentechy/WSL-ssh-server.md
[WSL 相关] wsl 相关文档 #wsl #ssh

How to automatically start ssh server on boot on Windows Subsystem for Linux

Microsoft partnered with Canonical to create Bash on Ubuntu on Windows, running through a technology called the Windows Subsystem for Linux. Below are instructions on how to set up the ssh server to run automatically at boot.

  1. Edit the /etc/ssh/sshd_config file by running the command sudo vi /etc/ssh/sshd_config and do the following
    1. Change Port to 2222 (or any other port above 1000)
    2. Change PasswordAuthentication to yes. This can be changed back to no if ssh keys are setup.
  2. Restart the ssh server:
    • sudo service ssh --full-restart
  3. With this setup, the ssh server must be turned on every time you run Bash on Ubuntu on Windows, as by default it is off. Use this command to turn it on:
@yuchen
yuchen / gist:4447d8f62a9c1a4fdd4f5b87ce18b1a2
Created February 12, 2020 05:03 — forked from cdown/gist:1163649
Bash urlencode and urldecode
urlencode() {
# urlencode <string>
old_lc_collate=$LC_COLLATE
LC_COLLATE=C
local length="${#1}"
for (( i = 0; i < length; i++ )); do
local c="${1:i:1}"
case $c in
[a-zA-Z0-9.~_-]) printf "$c" ;;
@yuchen
yuchen / tmux-cheatsheet.markdown
Last active April 28, 2021 16:50 — forked from ryerh/tmux-cheatsheet.markdown
[Tmux 文档] 快捷键、速查表、简明教程 #tmux

注意:本文内容适用于 Tmux 2.3 及以上的版本,但是绝大部分的特性低版本也都适用,鼠标支持、VI 模式、插件管理在低版本可能会与本文不兼容。

Tmux 快捷键 & 速查表 & 简明教程

启动新会话:

tmux [new -s 会话名 -n 窗口名]

恢复会话:

@yuchen
yuchen / imessage
Last active February 3, 2021 03:11 — forked from aktau/imessage
Send iMessage from the commandline #applescript #mac
#!/bin/sh
if [ "$#" -eq 1 ]; then stdinmsg=$(cat); fi
exec <"$0" || exit; read v; read v; read v; exec /usr/bin/osascript - "$@" "$stdinmsg"; exit
-- another way of waiting until an app is running
on waitUntilRunning(appname, delaytime)
repeat until my appIsRunning(appname)
tell application "Messages" to close window 1
delay delaytime
end repeat
@yuchen
yuchen / mac-network-commands-terminal.md
Last active February 1, 2020 14:14 — forked from jjnilton/mac-network-commands-cheat-sheet.md
[mac-network-commands] #mac #network #cmd

Mac Network Commands Cheat Sheet

After writing up the presentation for MacSysAdmin in Sweden, I decided to go ahead and throw these into a quick cheat sheet for anyone who’d like to have them all in one place. Good luck out there, and stay salty.

ipconfig & ifconfig

  1. Get an ip address for en0:
ipconfig getifaddr en0
@yuchen
yuchen / curl.md
Last active February 3, 2021 03:11 — forked from btoone/curl.md
A curl tutorial using GitHub's API #shell #cmd

Introduction

An introduction to curl using GitHub's API.

The Basics

Makes a basic GET request to the specifed URI

curl https://api.github.com/users/caspyin