Skip to content

Instantly share code, notes, and snippets.

View benwei's full-sized avatar

ben6 benwei

View GitHub Profile
@benwei
benwei / Result_test_jq_get_raw_data_of_json_data.txt
Created September 12, 2018 06:10
JSON get specific field of json data by jq command
$ echo '{"ip":"8.8.8.8","a":"11"}' | jq -r '. | {"ip"} | .[]'
8.8.8.8
@benwei
benwei / hello_for_redis.lua
Created September 17, 2018 09:43
using multipe keys and arguments with lua script via redis-cli
-- 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
@benwei
benwei / Makefile.orangeos-ch1-a
Last active January 27, 2019 09:16
For testing with orangeos's example chapter1-a
# 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):
@benwei
benwei / bash_arguments_example.sh
Last active February 22, 2019 15:56
Use bash to implement like C's argc and argv
#!/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
@benwei
benwei / test-cases.sh
Last active March 14, 2019 16:38
run remote cases by ssh with multiple arguments using shell - https://ben6.blogspot.com/2019/03/run-command-with-multiple-arguments.html
#/bin/bash
# 2019 Ben Wei <ben@juluos.org>
#
# This is a example script for CI tests for blog
# if not defined in environment variable
# you can use the following command to defined it
#
# export TEST_SSH_HOST="your_ssh_host"
#!/bin/bash
i=1
while [ ! "x$1" = "x" ]; do
echo "argv[$i]=[$1]"
shift
i=$((i + 1))
done
@benwei
benwei / yaml_test1.py
Last active March 14, 2019 16:25
test to load yaml syntax by pyyaml library
import yaml
document = """
a: 1
b:
c: 3
current_mk_abspathname := $(abspath $(lastword $(MAKEFILE_LIST)))
current_mk_absdir := $(dir $(current_mk_abspathname))
all:
@echo "Makefile absolute pathname: $(current_mk_abspathname)" ; \
echo "Makefile absolute path: $(current_mk_absdir)"
@benwei
benwei / test_result_on_linux_01-abspath-mk
Last active March 21, 2019 14:03
test result of 01-abspath-mk.mk
/build$ make -v
GNU Make 4.1
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
/build$ lsb_release -a
No LSB modules are available.
@benwei
benwei / start.sh
Last active November 14, 2019 08:24
Logging CPU load by top command per minute with BusyBox command environment
#!/bin/sh
## if you want to run toplog_per_minute.sh in background
## you have to use leading script to put it into backgroud without
## issue of "Stopped (tty output)" Error Message of script that
## stucked on busybox top command
## tested in BusyBox v1.20.2
##################################################################
/bin/sh /mnt/nand/toplog_per_minute.sh &