Skip to content

Instantly share code, notes, and snippets.

View jw-foss's full-sized avatar
:octocat:
Available at 7pm - 11pm UTC+8

Jeremy jw-foss

:octocat:
Available at 7pm - 11pm UTC+8
  • Earth
  • 22:33 (UTC +08:00)
View GitHub Profile
@jw-foss
jw-foss / Handy.md
Created July 13, 2022 03:03
Handy commands

Copy ssh public key to the remote server

ssh-copy-id -i [file-to-identity_file] [user]@[host]

Sometimes Mac won't recognize your disk after you did something stupid, you should do:

# This command lists all your disks(internal & external)
$ diskutil list

# The result would be something like: 
# /dev/disk6[this number is important] (external, physical):

# After getting this number, we should do:
@jw-foss
jw-foss / clash.md
Created November 26, 2021 01:32
Installing clash proxy with command line on Linux distros

How to install clash on POSIX system with command line.

Pre-request: You need to know which executable your distro can run without complaining.

  1. Go to https://github.com/Dreamacro/clash/releases to find the latest or the version you desired.
  2. Find the correct distro version, for example, if you are running a distro with arm64 archtecture, you should download the one with armv8 suffix.
  3. Download the executables with curl or wget at your wish.
$ curl -O [url/to/clash]
@jw-foss
jw-foss / ssh-config
Last active June 24, 2021 10:15
proxy ssh connection
# SSH connection is under raw TCP and UDP, which was implemented in `ssh` command via `nc` or `socat` for different platform
# So that in order to connect to the server via proxies, we need to as these commands to do that for us.
# Use `man nc` or `man socat` for more detail.
# Put this into `/Users/username/Home/.ssh/config`
Host git.github.com
# ProxyCommand does the magic to access the proxy server.
ProxyCommand /bin/nc -X 5 -x 127.0.0.1:7890 %h %p
echo $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
@jw-foss
jw-foss / type_of.rs
Created June 15, 2020 03:37
Rust way of printing the actual type of a variable
use std::any::type_name;
fn type_of<T>(_: T) -> &'static str {
type_name::<T>()
}
@jw-foss
jw-foss / Get_Source_Directory.sh
Created October 16, 2019 05:59
Get_Source_Directory.sh
#!/usr/bin/bash
# Senario
# Direcotry: /Home/uname/work/some_proj/sub_folder
# File in /Home/uname/work/some_proj
# Command would be like
# sh ../some_shell.sh
# $pwd gets the current working diretory
BASE_DIR="$(pwd)/$(dirname $BASH_SOURCE)"
export COOKIE_JAR='cookie-jar'
function _curl () {
curl --insecure -b $COOKIE_JAR -c $COOKIE_JAR -s "$@"
}
export -f _curl
@jw-foss
jw-foss / parse.sh
Created September 27, 2018 10:05
Parse through command line arguments
#!/usr/bin/env bash
# Parse command line arguments in a pattern like --flag value
while (( "$#" )); do
case "$1" in
-f|--flag)
statement
shift 2
;;
@jw-foss
jw-foss / operators.md
Created September 27, 2018 08:54
Shell script operators

-b filename - Block special file

-c filename - Special character file

-d directoryname - Check for directory Existence

-e filename - Check for file existence, regardless of type (node, directory, socket, etc.)

-f filename - Check for regular file existence not a directory