Skip to content

Instantly share code, notes, and snippets.

@du-song
du-song / README.md
Last active October 13, 2022 14:12
Software KVM Switch. Tested with Logi keyboard/mouse + Dell monitor. Inspired by https://github.com/pwr-Solaar/Solaar

Requirement

on macOS

brew install hidapi
brew install ddcctl

on Linux

@du-song
du-song / img2xlsx.py
Created March 30, 2022 22:44
Convert image to Excel file
import xlsxwriter
from PIL import Image
import sys
def rgb2hex(r, g, b):
return '#{:02x}{:02x}{:02x}'.format(r, g, b)
if len(sys.argv) != 3:
@du-song
du-song / patch-edid.rb
Last active February 4, 2022 05:48 — forked from adaugherity/patch-edid.rb
Patch EDID to force RGB instead of YCbCr. Modified original script to add support for 1 extension block, works on MBP 2014 + macOS 11.6 + Dell S2722QC
#!/usr/bin/ruby
# Create display override file to force Mac OS X to use RGB mode for Display
# see http://embdev.net/topic/284710
require 'base64'
data=`ioreg -l -d0 -w 0 -r -c AppleDisplay`
edids=data.scan(/IODisplayEDID.*?<([a-z0-9]+)>/i).flatten
vendorids=data.scan(/DisplayVendorID.*?([0-9]+)/i).flatten
@du-song
du-song / multipass-fix.sh
Last active February 4, 2022 14:52
Run Multipass in macOS as non-admin user
sudo killall -9 multipassd && sleep 5 && sudo chgrp staff /var/run/multipass_socket && multipass list
@du-song
du-song / connect.sh
Last active March 5, 2021 05:33
Connect Cisco AnyConnect server with OTP in OpenWrt
# use vanilla vpnc instead of the wrapped one in OpenWrt, which handles route table properly
wget http://git.infradead.org/users/dwmw2/vpnc-scripts.git/blob_plain/HEAD:/vpnc-script
/usr/sbin/openconnect $SERVER -b --script ./vpnc-script -u $USER
# update iptables manually instead of UCI
iptables -I zone_wan_dest_ACCEPT 5 -o tun0 -j ACCEPT
iptables -I FORWARD 5 -i tun0 -j zone_wan_forward
iptables -t nat -I POSTROUTING 5 -o tun0 -j zone_wan_postrouting
@du-song
du-song / connect.sh
Last active April 26, 2022 11:39
Cisco AnyConnect VPN Client on UBNT EdgeOS 2.0.9 via OpenConnect
openconnect -b -u USER SERVER
@du-song
du-song / crop_card.sh
Created December 28, 2016 03:08
Crop 3x3 card images using ImageMagick
#!/bin/sh
## brew install imagemagick
OPT="-crop 3x3@ +repage +adjoin -fuzz 20% -trim -bordercolor White -border 10x10"
mkdir -p tiled
convert PLACEMENT-CARDS/PLACEMENT-CARDS-12-2016.jpg $OPT tiled/0PLACEMENT-1-tiles%02d.jpg
convert PLACEMENT-CARDS/PLACEMENT-CARDS-12-20162.jpg $OPT tiled/PLACEMENT-2-tiles%02d.jpg
convert PLACEMENT-CARDS/PLACEMENT-CARDS-12-20163.jpg $OPT tiled/PLACEMENT-3-tiles%02d.jpg
@du-song
du-song / keybase.md
Created August 15, 2016 15:13
keybase.md

Keybase proof

I hereby claim:

  • I am freewizard on github.
  • I am freewizard (https://keybase.io/freewizard) on keybase.
  • I have a public key whose fingerprint is A206 174A 6283 D676 198A E2DF 6B3E 476C B857 14A6

To claim this, I am signing this object:

Sampling process 91414 for 3 seconds with 1 millisecond of run time between samples
Sampling completed, processing symbols...
Analysis of sampling Quicksilver (pid 91414) every 1 millisecond
Process: Quicksilver [91414]
Path: /Applications/Quicksilver.app/Contents/MacOS/Quicksilver
Load Address: 0x100000000
Identifier: com.blacktree.Quicksilver
Version: ß72 (3946)
Code Type: X86-64 (Native)
Parent Process: ??? [1]
@du-song
du-song / Disable Notification Center Alerts and Banners.applescript
Created February 5, 2013 03:26
Disable & Re-Enable Notification Center Alerts and Banners
do shell script "defaults write ~/Library/Preferences/ByHost/com.apple.notificationcenterui.*.plist doNotDisturb -boolean true"
set theDate to quoted form of (do shell script "date +\"%Y-%m-%d %I:%M:%S +0000\"")
do shell script "defaults write ~/Library/Preferences/ByHost/com.apple.notificationcenterui.*.plist doNotDisturbDate -date " & theDate
do shell script "killall NotificationCenter"