Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
set -eu -o pipefail
arg="${1-x}"
pid_file="$XDG_RUNTIME_DIR/code_server.pid"
bin=~/.local/code-server-3.4.1-linux-amd64/bin/code-server
log_file=~/.local/share/code-server/logs/console.log
if [[ $arg == 'run' ]]; then
find "$XDG_RUNTIME_DIR"/ /tmp -user "$USER" -a -type s -a -name 'vscode-*.sock' -exec sh -c 'lsof -w $1 || rm $1' _ {} \; 2>/dev/null || :
@xuboying
xuboying / demo.py
Created April 28, 2020 05:17
simple datetime handling
import datetime
import re
def demo(raw_time_str):
"""demo .
>>> demo('2020-04-07 08:18:43.317+02:00')
r_dt_with_tz = 2020-04-07 08:18:43.317000+02:00
r_dt_converted_to_utc = 2020-04-07 06:18:43.317000+00:00
r_dt_striped_tz = 2020-04-07 08:18:43.317000+00:00
@xuboying
xuboying / mdv.patch
Created April 3, 2020 05:54
patch mdv
--- a/lib/python3.6/site-packages/mdv/markdownviewer.py 2019-07-22 10:18:01.080295801 +0000
+++ b/lib/python3.6/site-packages/mdv/markdownviewer.py 2019-07-23 09:45:28.781552791 +0000
@@ -1390,7 +1390,7 @@
tags = Tags()
for ph in stash.rawHtmlBlocks:
nr += 1
- raw = html_parser.unescape(ph[0])
+ raw = html_parser.unescape(ph)
if raw[:3].lower() == "<br":
raw = "\n"
@xuboying
xuboying / check_rpm.sh
Last active March 17, 2020 05:00
check RPM files
#!/bin/bash
# $1 is RPM package name, not RPM filename. E.g foo OK; foo_1.0.1_x64.rpm NOK
set -eu
set -o pipefail
rpm_name=${1-x}
root_dir=${2-/NOT_EXIST}
rpm -V $rpm_name || :
[[ -d $root_dir ]] && comm -13 <(rpm -ilq $rpm_name | sort | uniq) <(find $root_dir | sort | uniq)
@xuboying
xuboying / one_line_perl_as_tree_cmd.md
Created September 27, 2019 08:14
One line perl as tree command
find /lib -maxdepth 4 -name ".*" -prune -o -print|perl -wne 'push @A,$_;END{my $lm=0;my %fill;print reverse map {s!^(.*/)!$_=()=$1=~m{/}g;(("|  ") x ($_-1))."+--"!e;my $m=index($_,"+");for (keys %fill){delete $fill{$_}if $_>$m};$fill{$m}=1;for (my $i=0;$i<$m;$i+=3){substr($_,$i,1)=" "if !exists $fill{$i};substr($_,$m,1)="\\";$lm=$m if $lm!=$m};$_}reverse sort @A}'

Produce:

+--lib
   \--apparmor
   |  \--functions
   |  \--profile-load
 \--bridge-utils
root@compute-0-3:~# perl -E 'printf "%30s : ", "HOST CPU LOAD";map { /[\d\.]+$/; $c++; $& > 80 ? print "." : $& > 60 ? print "-" : print "=" } grep { !/all|CPU/ } qx(mpstat -P ALL 1 1 | grep "Average");print "\n";for (qx(virsh list --name)){chomp;next if /^\s*$/;printf "%30s : ", $_; my $x="-" x $c; map { /\d+/;$&;substr($x,$&,1)="o" } grep { /^CPU:/ } qx(virsh vcpuinfo $_);say $x;};'
HOST CPU LOAD : -.=.-..................=-...-.=.....=...-.......
cic-3_vm : ------o-o-o-o-o-o-------------o-o-o-o-o-o-------
instance-00000664 : --------------------o-----------------------o---
instance-00000667 : ------------------o-----------------------o-----
instance-0000066a : ----------------------o-----------------------o-
instance-0000066d : -----------------o-----------------------o------
@xuboying
xuboying / csh_bash.sh
Last active August 1, 2018 10:08
merge bash and csh script together
#!/bin/csh
# vim: autoindent tabstop=4 shiftwidth=4 expandtab softtabstop=4
# One script includes bash and csh part
# used in very rare case when working shell is csh and needs to sources csh env before run bash scripts
# REF
# https://stackoverflow.com/questions/8426077/how-to-define-a-function-inside-another-function-in-bash
# https://stackoverflow.com/questions/9639103/is-there-a-goto-statement-in-bash
# https://stackoverflow.com/questions/17008169/pass-arguments-from-csh-to-program-exactly-as-they-are
@xuboying
xuboying / layout.bat
Created July 18, 2018 04:29
Script for Install Visual Studio 2017 on low bandwidth or unreliable network environments
REM # A Handy old school styled bat script used to download or/and install
REM # Visual Studio 2017 components.
REM # As Microsoft frequently updates the components, this script is used fetch
REM # and install the latest good stuffs.
REM # I use Visual C++ only, so this script only download the related
REM # components, modify the parameters to load the needed components.
REM # To start from scratch:
@xuboying
xuboying / description.txt
Created May 5, 2018 08:31
Karabiner-Elements complex_modifications rules for macvim
put file in /tmp/macvim.json
Open following link in browser(e.g ff)
karabiner://karabiner/assets/complex_modifications/import?url=file%3A%2F%2F%2Ftmp%2Fmacvim.json
@xuboying
xuboying / perlfunc.py
Last active October 30, 2018 14:10
perlfunc.py
#!/usr/bin/env python3
# vim: autoindent tabstop=4 shiftwidth=4 expandtab softtabstop=4 filetype=python
import sys
import os
import subprocess
import shlex
class PerlFuncs: