Skip to content

Instantly share code, notes, and snippets.

ben6 benwei

  • Taiwan
Block or report user

Report or block benwei

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@benwei
benwei / output of jq
Created Sep 5, 2018
test json with jq command
View output of jq
# jq tool: https://github.com/stedolan/jq
$ echo '[{"a":"2"}]' | jq '.[]'
{
"a": "2"
}
$ echo '[{"a":"2"}]' | jq '.[] | .["a"]'
"2"
# view with online tool jqplay
## https://jqplay.org/s/OrtlyrkIyg
@benwei
benwei / gen_md5sum_of_folder.sh
Created Aug 29, 2018
Generate single check sum of a directory's contents
View gen_md5sum_of_folder.sh
#!/bin/sh
target="$1"
if [ -z "$target" ]; then
echo "syntax: <folder-name>"
exit 1
fi
find $target -type f -exec md5sum {} + | cut -d" " -f1 | sort | md5sum | cut -d" " -f1
exit $?
@benwei
benwei / trim_sp_txtfiles.sh
Created Apr 13, 2018
trim space chars in txt filename in current directory
View trim_sp_txtfiles.sh
find *.txt | grep " " | while read fn ; do xfn=`echo $fn | tr -d ' '`; mv "$fn" "$xfn" ; done
@benwei
benwei / check_threads_status_in_a_process.txt
Last active Nov 28, 2017
How to check thread load within a process in embedded linux system?
View check_threads_status_in_a_process.txt
How to check threads status within a process in embedded linux system?
Author: Ben Wei 2017-11-28
system linux kernel 3.10.73+
# ps aux | grep pulseaudio | grep -v grep
pulse 142 7.5 4.3 44312 4664 ? S<sl Nov24 406:35 /usr/bin/pulseaudio --daemonize=no
## use top command with -H, you can browse the thread load in the file
# top -H -p 142
@benwei
benwei / date_convert_osx_example.sh
Created Jan 28, 2016
MacOS convert timestamp by date command with GNU bash
View date_convert_osx_example.sh
#!/bin/bash
# author: terry, ben
# tested GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin14)
# FYR (for Mac OS, may need some change for linux)
# second -> ISO8601
date -u -r 1453951368 +%FT%TZ
## ouptput: 2016-01-28T03:22:48Z
# ISO8601 -> second
date -ju -f "%FT%TZ" 2016-01-28T03:22:48Z +%s
## output: 1453951368
View dump_ssl_heartbeat_enabled_header.sh
openssl s_client -connect $your_ssl_website -tlsextdebug 2>&1 | grep 'server extension'
@benwei
benwei / shell_script_path.sh
Created Nov 9, 2015
get script's location path
View shell_script_path.sh
t="${0%%`basename $0`}"; cd "$t" ; SCT_PATHPATH=`pwd`
echo $SCT_PATHPATH
@benwei
benwei / dict.sh
Created Oct 26, 2015
simple dictionary using curl with dict protocol
View dict.sh
#!/bin/sh
## refernce http://www.dict.org/rfc2229.txt
word="$1"
if [ -z "$word" ]; then
echo "syntax: ./dict <word>"
exit 1
fi
curl "dict://dict.org/d:$word"
@benwei
benwei / vim-note01
Created Jul 6, 2014
vim search and replace binary characters by regular expression
View vim-note01
/\%xnn characters (nn range is 00-FF)
%s/\%xnn//g -- replace all \xnn characters (nn range is 00-FF)
%s/\%unnnn//g -- replace all unicode code 'nnnn' characters, (nn range is 0000-FFFF)
View vimtips_regex01
replace
test-keyworkd : anything ;
to
“test-keyworkd” :“anything”,
regex:
s/^\([ \t]*\)\([a-z-]*\):[ \t]*\(.*\);/\1"\2":"\3",/g
You can’t perform that action at this time.