Skip to content

Instantly share code, notes, and snippets.

@GongT
GongT / profile.ps1
Created Nov 4, 2020
Sync network drive mapping when run "PowerShell (admin)"
View profile.ps1
### append this into $PROFILE.CurrentUserAllHosts
foreach ($info in Get-ChildItem -Path HKCU:/Network) {
$letter = Split-Path -Leaf -Path $info.Name -ErrorAction SilentlyContinue
if (-Not $letter) { continue }
if (Test-Path -Path "${letter}:/") { continue }
$remote = $info.GetValue('RemotePath')
if (-Not $remote) { continue }
New-PSDrive -Scope Global -PSProvider "FileSystem" -Name $letter -Root $remote -ErrorAction SilentlyContinue | Out-Null
}
@GongT
GongT / create-initrd.sh
Created Sep 3, 2020
libvirtd direct kernel boot
View create-initrd.sh
#!/usr/bin/env bash
mkinitrd \
--with fuse \
--with virtio_scsi \
--with virtio_mmio \
--with virtio_console \
--with virtio_blk \
-f initrd.img \
"$(uname -r)"
@GongT
GongT / arguments.sh
Created Jan 27, 2020
bash argument options parser (BASH>=4.2)
View arguments.sh
declare -a _ARG_GETOPT_LONG
declare -a _ARG_GETOPT_SHORT
declare -A _ARG_COMMENT
declare -A _ARG_INPUT
declare -A _ARG_OUTPUT
declare -A _ARG_RESULT
declare -A _ARG_REQUIRE
function arg_string() {
if [[ "$1" == '+' ]]; then
shift
@GongT
GongT / profile.d-cygwin-path.sh
Created Dec 10, 2019
remove Windows staff from PATH cygwin
View profile.d-cygwin-path.sh
if uname | grep -iq "cygwin" ; then
IFS=: read -r -d '' -a path_array < <(printf '%s:\0' "$PATH")
WINPATH=""
LP=""
for P in "${path_array[@]}"; do
if [[ "$P" =~ ^/cygdrive ]]; then
WINPATH+=":$P"
else
LP+="$P:"
@GongT
GongT / cloudSettings
Last active Jan 11, 2020
cloudSettings
View cloudSettings
{"lastUpload":"2020-01-11T20:45:17.450Z","extensionVersion":"v3.4.3"}
@GongT
GongT / node-long-running.service
Created Nov 8, 2019
Systemd service file for long running nodejs project, eg, a website.
View node-long-running.service
[Unit]
Description=Auto run UMI UI
After=data.mount
# Requires=mariadb.service
[Service]
Type=simple
Restart=on-failure
Environment=DISPLAY= HOST=0.0.0.0 UMI_PORT=15000 UMI_UI_BROWSER=none DEBUG=umiui:*
ExecStart=/usr/local/bin/umi ui
@GongT
GongT / code.sh
Created Nov 5, 2019
start VSCode from cygwin (/usr/local/bin/code)
View code.sh
#/usr/bin/env bash
ARGS=("$@")
WPATH=()
PPATH=()
OIFS="$IFS"
IFS=":"
X=( $PATH )
@GongT
GongT / 00.service.md
Last active Sep 26, 2019
Windows 10 native OpenSSH Agent
View 00.service.md

To enable ssh-agent and add private key into it:

Set-Service ssh-agent -StartupType Automatic
Start-Service ssh-agent

ssh-add X:\xxx.ed25519

The permission of file X:\xxx.ed25519 need manual tweak before ssh-add:

  1. Right click X:\xxx.ed25519, click "Properties."
@GongT
GongT / ranbow.sh
Created Sep 16, 2019
ranbow animation in bash
View ranbow.sh
#!/bin/bash
RAINBOW=(196 202 208 214 220 226 190 154 118 82 46 46 47 48 49 50 51 45 39 33 27 21 21 57 93 129 165 201 200 199 198 197 196)
function char_rainbow() {
local STR="$1" I
J=$(( $J % ${#RAINBOW[@]} ))
for I in $(seq 0 $(( ${#STR} - 1 )) ) ; do
printf "\e[38;5;%dm%c" "${RAINBOW[J]}" "${STR:${I}:1}"
J=$(( $J + 1 ))
@GongT
GongT / rgb.sh
Last active Sep 16, 2019
color in shell
View rgb.sh
#!/bin/bash
# rgb R G B
# 0 <= RGB <= 5
function rgb() {
local R=$1 G=$2 B=$3
echo -n $(( $R * 36 + $G * 6 + $B + 16 ))
}