Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env bash
function token_to_array() {
local -n array=$1
local str=$2
local i=0 c quote start=0
while [ $i -lt ${#str} ]; do
c=${str:$i:1}
case "$c" in
\\) i=$(( i + 1 ))
defscrollback 10000
autodetach on
vbell on
hardstatus alwayslastline
hardstatus string '%{= kg}[ %{y}%H %{g}][%= %{=kw}%?%-w%?%{y}(%{W}%n*%t%?(%u)%?%{y})%{g}%?%+w%?%?%= %{g}][ %{y}%Y-%m-%d %{W}%c %D %{g}]'
escape ^Aa
#shell bash
@qgp9
qgp9 / uniq_test.c
Created July 11, 2020 22:48
uniqueness test for Linear congruential generator
#include <stdio.h>
#include <time.h>
#define NSUB (1L<<32)
#define NBIT 48
//#define NSUB (1<<4)
//#define NBIT 8
#define COUNT(isub, iseg) (isub*((long)NSUB)+iseg)
#define PRINT_COUNT(msg, count) printf("%s: iSub= %ld\tcount= %ld\tr1= %ld\tr2=%ld\telapse= %f\n", msg, isub, count, r1, r2, elapse)
#define PRINT(msg) PRINT_COUNT(msg, COUNT(isub, iseg))
@qgp9
qgp9 / Makefile
Created July 25, 2019 10:03
Makefile export and override
foo ?= default
override foo += added
export foo
all::
@echo outer: foo is "$(foo)"
@$(MAKE) -s -f sub-make.mk
#!/bin/bash
function ensure_privileged_or_exit() {
local cap_mask="0x00000007ffffffff"
local cap_bnd=0x$(grep ^CapBnd /proc/self/status | awk '{print $2}')
if [[ $(($cap_mask & $cap_bnd )) != $(($cap_mask)) ]]; then
echo -e "[ERROR] Run with --privileged option."
exit 1
fi
}
@qgp9
qgp9 / change_fn_esc_to_grave_accent_and_tilde.json
Created March 30, 2019 10:38
Chang fn/cmd+esc to grave_accent_and_tilde
{
"title": "Change fn + esc to grave_accent_and_tilde",
"rules": [
{
"description": "Change fn + esc grave_accent_and_tilde",
"manipulators": [
{
"type": "basic",
"from": {
"key_code": "escape",
@qgp9
qgp9 / example.sh
Created March 15, 2019 05:18
convert source code to syntax-highlighted ps/html
vim -c TOhtml -c wq -c q TxJSON.cxx
vim -c 'hardcopy > o1.ps' -c q TxJSON.cxx
a2ps --pro=color -o o2.ps TxJSON.cxx
------------------------------------------------- == ------------------------------------------------- ==
nench.sh v2018.04.14 -- https://git.io/nench.sh == nench.sh v2018.04.14 -- https://git.io/nench.sh ==
benchmark timestamp: 2018-11-18 10:05:43 UTC == benchmark timestamp: 2018-11-18 10:06:45 UTC ==
------------------------------------------------- == ------------------------------------------------- ==
== ==
Processor: Intel(R) Xeon(R) CPU E5-2687W v4 @ 3.00GHz == Processor: Virtual CPU 714389bda930 ==
CPU cores: 1
@qgp9
qgp9 / convert_broken_korean_filename_to_utf8.sh
Created November 15, 2018 16:08
Convert broken Korean filename of zip file to utf-8
#!/bin/bash
find "$1" -d | while read x; do
basename=$(basename "$x")
dirname=$(dirname "$x")
newname=$(echo $basename | iconv -c -f utf-8 -t cp866 | iconv -f cp949 -t utf-8)
if [ "$basename" != "$newname" ];then
mv "$dirname/$basename" "$dirname/$newname"
fi
done
#!/usr/bin/env python
import sys
# Basic recursion
def fibonacci (n):
def imp (n):
if n == 0: return 0
if n == 1: return 1
return imp(n-1) + imp(n-2)