Skip to content

Instantly share code, notes, and snippets.

@jwangac
jwangac / adb-network-connect
Created December 28, 2023 10:00
A Bash script to connect to an Android device over ADB using a hostname
#!/bin/bash
set -euo pipefail
shopt -s inherit_errexit
if [[ $# -ne 1 ]]; then
>&2 echo "usage: $0 <hostname>"
exit 1
fi
# fix freeze when adb is not running
@jwangac
jwangac / sway-clipboard-monitor.sh
Last active December 24, 2023 09:48
Recover emptied clipboard after window closes under Sway using CopyQ, supposing CopyQ has been run as a server in the background.
#!/bin/bash
while [[ true ]]; do
# Subscribe to window events in Sway, capturing the output
output=$(swaymsg -t subscribe '["window"]')
# Check the return value of the swaymsg command
retval=$?
if [[ $retval -ne 0 ]]; then
>&2 echo "$0: swaymsg subscription failed with $retval. Retrying in 10 seconds..."
@jwangac
jwangac / README.md
Last active May 22, 2023 04:22
Binary of MikroTik RB750Gr3

I no longer have this device. Use at your own risk.

@jwangac
jwangac / Makefile
Last active November 7, 2017 12:35
General purpose Makefile for LaTeX
all:
@mkdir -p $$(find -name '*.tex' -printf 'output/%h\n')
@SOURCE_DATE_EPOCH=0 latexmk -pdf -output-directory=output
clean:
@rm -rf output/
@jwangac
jwangac / fixics.ps1
Last active April 7, 2017 07:55
Restart the ICS service in Windows.
# Create a NetSharingManager object
$m = New-Object -ComObject HNetCfg.HNetShare
# Find connections
$c_wan = $m.EnumEveryConnection |? { $m.NetConnectionProps.Invoke($_).Name -eq 'WLAN' }
$c_lan = $m.EnumEveryConnection |? { $m.NetConnectionProps.Invoke($_).Name -eq 'vEthernet (internal)' }
# Get configurations
$config_wan = $m.INetSharingConfigurationForINetConnection.Invoke($c_wan)
$config_lan = $m.INetSharingConfigurationForINetConnection.Invoke($c_lan)
@jwangac
jwangac / md5sum.bat
Created April 3, 2017 11:59
Wrapper for native checksum calculator in Microsoft Windows.
@echo off
if "%~1" equ "" (
echo Usage: %~n0 file
exit /b
)
if not exist "%~1" (
echo No such file or directory
exit /b
@jwangac
jwangac / autologin
Last active April 20, 2018 08:16
Autologin script for BUAA.
#!/bin/sh
CURL=/usr/bin/curl
if [ $# -ne 2 ]; then
echo "Usage: $0 <username> <password>"
exit 1
fi
check()
@jwangac
jwangac / GWX.reg
Last active October 6, 2016 02:34
I don't want Windows 10.
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\Gwx]
"DisableGwx"=dword:00000001
@jwangac
jwangac / ContextMenu.cmd
Last active March 18, 2017 08:48
Add "Open with Sublime Text" to your Windows right-click context menu.
@echo off
set NAME=Sublime Text
set TEXT=Open with Sublime Text
set EXEC=%~dp0sublime_text.exe
set ICON=%~dp0sublime_text.exe,0
reg add "HKEY_CLASSES_ROOT\*\shell\%NAME%" /t REG_SZ /v "" /d "%TEXT%" /f
reg add "HKEY_CLASSES_ROOT\*\shell\%NAME%" /t REG_SZ /v "Icon" /d "%ICON%" /f
reg add "HKEY_CLASSES_ROOT\*\shell\%NAME%\command" /t REG_SZ /v "" /d "%EXEC% """%%1"""" /f