Skip to content

Instantly share code, notes, and snippets.

View trustin's full-sized avatar
🌄
▂▃▅▇█▓▒░۩۞۩░▒▓█▇▅▃▂

Trustin Lee trustin

🌄
▂▃▅▇█▓▒░۩۞۩░▒▓█▇▅▃▂
View GitHub Profile
@trustin
trustin / git-checkout-pr.sh
Last active May 16, 2023 02:08
git-checkout-pr.sh - fetches a Git pull request from the remote and creates a local branch for it
#!/usr/bin/env bash
set -Eeuo pipefail
log() {
echo -en '\033[1;32m'
echo -n "$@"
echo -e '\033[0m'
}
choice() {
@trustin
trustin / smi2ass.py
Last active January 24, 2023 03:25
smi2ass.py - converts a SAMI (.smi) subtitle file to the SubStationAlpha (.ass) format.
#!/usr/bin/env python2
# -*- coding: UTF-8 -*-
# Note: A newer version of this script is located at https://github.com/trustin/smi2ass
#
# Copyright (C) 2018 Trustin Heuiseung Lee and other contributors
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
@trustin
trustin / reconfigure-display.sh
Created March 10, 2016 04:00
Trustin's single/dual monitor setup script for laptops with nVidia GPU
#!/bin/bash
if [[ $# -gt 0 ]]; then
CLONE=1
else
CLONE=0
fi
function get_max_resolution() {
xrandr | grep -A100 "^$1 " | grep -P '^\s+[0-9]+x[0-9]+\s+[0-9\.]+\s*\*?\+.*$' | head -1 | awk '{ print $1; }'
}
@trustin
trustin / noroaming.patch
Created September 12, 2015 08:00
broadcom-wl patch that fixes the crash on multi-AP environment
diff -urN a/src/wl/sys/wl_cfg80211_hybrid.c b/src/wl/sys/wl_cfg80211_hybrid.c
--- a/src/wl/sys/wl_cfg80211_hybrid.c 2015-09-12 16:39:28.000000000 +0900
+++ b/src/wl/sys/wl_cfg80211_hybrid.c 2015-09-12 16:50:44.908084821 +0900
@@ -2150,8 +2150,12 @@
WL_DBG(("\n"));
if (status == WLC_E_STATUS_SUCCESS) {
- err = wl_bss_roaming_done(wl, ndev, e, data);
- wl->profile->active = true;
+ if (!wl_bss_roaming_done(wl, ndev, e, data)) {
@trustin
trustin / gist:8552089
Last active January 4, 2016 01:59
A simple scripts that turns 'Ctrl' into 'Super' key in X. It also reverts the changes made by your desktop environment by monitoring xkbmap periodically.
#/bin/bash
# 0 - Init, 1 - Set XKBMAP
KBD_STATUS=0
while true; do
KBD_OPT='caps:super,terminate:ctrl_alt_bksp'
if [[ $KBD_STATUS -eq 1 ]]; then
setxkbmap -query | grep -qF "$KBD_OPT" || ((KBD_STATUS=0))
fi
@trustin
trustin / hintstyle.patch
Created November 1, 2013 18:10
Wine patch for saner font hinting configuration, which applies 'hintslight' for ASCII glyphs and 'hintnone' for others such as CJK glyphs. I hope Wine uses fontconfig to respect the hintstyle, lcdfilter, and rgba properties like other GTK apps do.
diff -urN wine-orig/dlls/gdi32/freetype.c wine-patched/dlls/gdi32/freetype.c
--- wine-orig/dlls/gdi32/freetype.c 2013-07-19 02:57:36.000000000 +0900
+++ wine-patched/dlls/gdi32/freetype.c 2013-11-01 11:05:11.998232947 +0900
@@ -6199,10 +6199,15 @@
}
if(format & GGO_UNHINTED) {
- load_flags |= FT_LOAD_NO_HINTING;
format &= ~GGO_UNHINTED;
}
@trustin
trustin / pavol.sh
Created June 13, 2013 07:43
Volume control script for PulseAudio
#!/bin/bash
SINK="`pactl info | grep -P '^Default Sink: ' | sed 's/[^:]\+:\s\+//'`"
[[ -z "$SINK" ]] && exit 1
if [[ "$SINK" =~ DragonFly ]]; then
INCR='24'
MIN_VOLUME=65050
MAX_VOLUME=65146
else
INCR='2%'
@trustin
trustin / gist:5752973
Created June 10, 2013 22:26
Simplistic HTTP performance test: Netty 3 vs 4 (master) /// Became a tad bit slower with less variation. Maybe due to validations required for more strict thread model and reduced garbage production. 4 at port 8080 and 3 at port 8088.
$ wrk -c 1024 -d 120m -t 1 --latency http://localhost:8080/
Running 120m test @ http://localhost:8080/
1 threads and 1024 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 5.80ms 2.68ms 65.36ms 80.40%
Req/Sec 101.95k 221.90 107.00k 95.17%
Latency Distribution
50% 4.81ms
75% 5.45ms
90% 9.84ms
4 + less_footprint:
===================
$ wrk -c 1 -d 3m -t 1 --latency http://localhost:8080/
Running 3m test @ http://localhost:8080/
1 threads and 1 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 26.51us 76.35us 0.98ms 99.25%
Req/Sec 40.01k 81.60 41.00k 99.33%
Latency Distribution
@trustin
trustin / btsync-secret.sh
Last active December 16, 2015 15:09
Simple shell script that generates a base64-encoded BitTorrent Sync secret with arbitrary length parameter
#!/bin/bash -e
SECRET_SIZE=128
mkdir -p "$HOME/.local/tmp"
rm -f "$HOME/.local/tmp/btsync-secret".*
umask 0077
SECRET_FILE="`mktemp "$HOME/.local/tmp/btsync-secret.XXXXXXXXXX"`"
echo -n "Generating a $SECRET_SIZE-byte secret "
head --bytes=$SECRET_SIZE /dev/random > "$SECRET_FILE" &
while true; do
CUR_SECRET_SIZE=`stat --format='%s' "$SECRET_FILE"`