2023年6月5日星期一

sha1sum check folder

 ref: https://stackoverflow.com/questions/545387/linux-compute-a-single-hash-for-a-given-folder-contents


One possible way would be:

sha1sum path/to/folder/* | sha1sum

If there is a whole directory tree, you're probably better off using find and xargs. One possible command would be

find path/to/folder -type f -print0 | sort -z | xargs -0 sha1sum | sha1sum

And, finally, if you also need to take account of permissions and empty directories:

(find path/to/folder -type f -print0  | sort -z | xargs -0 sha1sum;
 find path/to/folder \( -type f -o -type d \) -print0 | sort -z | \
   xargs -0 stat -c '%n %a') \
| sha1sum

hash a tar ball of the directory:

tar cvf - /path/to/folder | sha1sum

2023年5月10日星期三

git merge fatal: refusing to merge unrelated histories

fatal: refusing to merge unrelated histories

 git merge --allow-unrelated-histories origin/main

2023年2月3日星期五

shell sed append before delete and grep

srcfile=test0001.html

# backup $srcfile
mv $srcfile  ${srcfile}.bak
cp   ${srcfile}.bak $srcfile 

# check replace line
grep -3 -e 'name="txtName"' $srcfile

# delete first
sed -i -e '/name="test"/d'  $srcfile

# append line
sed -i -e '/name="txtName"/a <IMART type="imInputTd" style="text" name="test"></IMART>' $srcfile

2023年1月26日星期四

yml 仕様概要

documentAn ordered sequence of anonymous map nodes.
nodeA YAML node can be one of three types: list, scalar, map. Every node may optionally have a class.
# comment

list An ordered sequence of zero or more nodes. 
   # Nodes are included by reference, 
   # thus they may be part of more than one list or map.
men: [tester1, tester2]
women:
  - tester3
  - tester4

# scalar: An ordered sequence of zero or more bits. 
   # Where bits are an atomic construct able to have a value of one or zero.
name: lqwangxg
career: it
age: 40
 
map(key, value)
# An un-ordered sequence of zero or more (key, node) tuples 
# where the key is unique within the sequence.
- {name: lqwangxg, career: it}
- name: tester1
  career: test  
#key: A sequence of zero or more characters.
#classAn opaque object that has a serialization which complies with the class production.The serialization model adds an anchor attribute to every node, and introduces the reference node. The reference node advertises an anchor to indicate the repetition of a node previously encountered.
#anchor An additional attribute added to each node that provides for identification of the node within a given node sequence. Only nodes which could be referenced further in the sequence must be given an anchor. It is not necessary that the anchor is unique.
reference  An additional node type consisting of an anchor which is used to indicate the repetition of the node with the same anchor most previously encountered.
# indent縮進(通常2space)でレベルを分ける
table:
  - column1
    - size
    - type
  - column2
    - size
    - type

--- 複数YMLDocumentを一つファイルに記載1
- stringParam1
- stringParam2
--- 複数YMLDocumentを一つファイルに記載2
[stringParam3, stringParam4]

#各行の改行を維持
--- | 
  先頭行にspace無しデータStart
      先頭にspace有りデータ1
      先頭にspace有りデータ2
  先頭行にspace無しデータEnd

#最終行の改行を維持,ほかは1spaceに置換え
---  
  先頭行にspace無しデータStart
    先頭にspace有りデータ
  先頭行にspace無しデータEnd
#置き換え後の結果:    
先頭行にspace無しデータStart 先頭にspace有りデータ 先頭行にspace無しデータEnd

#Indicators Type説明
imap ::= '%'  /*indicate a map node*/
ilist   ::= '@'  /*indicate a list node*/
iquote ::='"'  /*indicate a quoted string*/
ikey   ::=':'  /*separate a key from a node*/
iblk    ::='|'   /*indicate a block scalar */
iblkend ::='\'  /*indicate end of a block*/
iescape ::='\'  /*indicate an escape sequence*/
iref ::='*'       /*indicate a reference node*/
iclass ::='#'    /*indicate a class attribute*/
inull ::='~'   /*indicate a null node*/
ianchor ::='&'   /*indicate an anchor attribute*/
ibin   ::='['   /*indicate begin of binary scalar*/
ibinend ::=']'   /*indicate end of binary scalar*/
ireserved  ::='^' | '!' | ';' | '`' | ',' | '.' | '(' | ')' | '{' | '}' /* reserved*/

#Block Scalar
first: |This is a block scalar,    with significant
       |whitespace, and the use of " @, etc.
       |The \ is used to signify the end of the block.
       |     Whitespace    *is*    significant.
       \
#Quoted Scalar
second: "Escape sequences can be used 
             to removed or \ add white\
             space, \\ and \" must be escapted"
#Binary Scalar
binary: [R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAO
         fn515eXvPz7Y6OjuDg4J+fn5OTk6enp56enmlp
         aWNjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f
         /++f/++f/++f/++f/++f/++f/++f/++SH+Dk1h
         ZGUgd2l0aCBHSU1QACwAAAAADAAMAAAFLCAgjo
         EwnuNAFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYN
         G84BwwEeECcgggoBADs=]   
desc: "A binary scalar uses the base64 encoding. 
         Base64 strings are a sequence of base64 characters intermixed with 
         whitespace which is ignored by the base64 processor. 
         An additional constraint is that no more than 76 sequential characters
         are allowed without at least one intermediate whitespace character. "
参考: 
https://ja.wikipedia.org/wiki/YAML
https://yaml.org/spec/history/2001-05-26.html

2023年1月20日星期五

宋词欣赏《卜算子-自嘲》,《西江月-悟》

《卜算子-自嘲》

本是后山人,偶做堂前客。醉舞经阁半卷书,坐井观天阔。

大志戏功名,海斗量福祸。论到囊中羞涩时,怒指乾坤错。

---出自《遥远的救世主》 丁元英和一帮文人于酒宴


《西江月-悟》

悟道休言天命,修行勿取真经,一悲一喜一枯荣,哪个生前注定?

袈裟本无清净,红尘不染性空,幽幽古刹千年钟,都是痴人说梦。

---出自《遥远的救世主》 丁元英上五台山


2023年1月10日星期二

C# TaskRun with parameter and return

====================
private bool IsSkipInput(string content)
{
    if (skipInput == null) return false;

    // skip if match the pattern
    if (skipInput.isTrue(content)) return true;
    return false;
}
====================
public async void matchText(string content, List<Match> matches)
{
    if (string.IsNullOrEmpty(pattern)) return;
    
    bool isSkipOK = await Task.Run<bool>(() => { return IsSkipInput(content); });
    if (isSkipOK)
    {
        return ;
    }
}

2022年12月7日星期三

shell different between return and exit

1. return used in function, 
    shell will continue after return from function 

2. exit used in everywhere of shell, stop and exit shell immediately.

example:
#========================
function testreturn(){
   echo "It will return 1"
   return 1
}

function testexit(){
   echo "It will exit 1"
   exit 1 
}

echo "start..."
testreturn
echo " after return "
testexit
echo " after exit"
#========================
#run result:
start...
It will return 1
after return 
It will exit 1
==========================