This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Copyright (C) 2019 by Ben Wei <ben@juluos.org> | |
# Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. | |
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL | |
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, | |
# OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF | |
# CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
###### | |
# sample code of blog | |
## tested with bash 4.3.48 x86_64-pc-linux-gnu ubuntu-16.04.4 LTS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 2019-01-25 Ben Wei <ben@juluos.org> | |
IMAGE=a.img | |
BINFILE=boot.bin | |
all: $(IMAGE) $(BINFILE) | |
$(BINFILE): boot.asm | |
nasm boot.asm -f bin -o $(BINFILE) | |
dd if=$(BINFILE) of=./$(IMAGE) bs=512 count=1 | |
$(IMAGE): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- redis-cli --eval hello.lua Tester " devops" , Argument1 " argument2" | |
-- KEYS[1] == "Tester" | |
-- KEYS[2] == " devops" | |
-- ARGV[1] == "Argument1" | |
-- ARGV[2] == " argument2" | |
local msg = "Hello, world," .. KEYS[1] .. KEYS[2] .. "!" .. ARGV[1] .. ARGV[2] | |
return msg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ echo '{"ip":"8.8.8.8","a":"11"}' | jq -r '. | {"ip"} | .[]' | |
8.8.8.8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ls *.py | while read fn ; do line_num=`cat "$fn" | wc -l`; echo "\"$fn\",$line_num" ; done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 $? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
find *.txt | grep " " | while read fn ; do xfn=`echo $fn | tr -d ' '`; mv "$fn" "$xfn" ; done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |