++wythern++

X presents Y for a better Z

2019年3月27日 #

[转]CRLF和LF在跨渠道作业时分带来的烦恼以及处理方法

原文在此

在运用git提交代码时分,有时分会遇到一个问题,便是自己分明只批改了其间几行,提交上去今后发现整个文件都被批改了,在设置了格局风格今后还会有提交不上去的状况,这个时分常常让人摸不到脑筋,其实便是CRLF和LF在作祟

CRLF LF CR 都是什么意思:

  • CRLF: 是carriagereturnlinefeed的缩写。中文意思是回车换行。

  • LF: 是line feed的缩写,中文意思是换行。

  • CR: 是carriagereturn的缩写。中文意思是回车。

简略的换行回车为什么会引出这么多的问题呢,关键在于操作体系之间的不合:

前期的mac体系运用CR作为换行,现在也现已一致成了LF

Unix(包括现在很多运用的linux)体系运用LF

windows体系运用LFCR作为换行(自作聪明的兼容性??)

也正是因为不同体系的不合,在多人协作共同开发的时分,或许导致提交代码时分发生问题。

处理方法:

Android Studio内部能够设置不同方法,详细位置在setting-->查找code style见下图:





















设置格局

其间有四个选项System-Dependent LF CR CRLF,默许是System-Dependent,也便是依据你是什么体系挑选什么类型,假如想要自界说的话能够在这儿设置,今后创立的新代码也默许用设置的方法

而假如想独自批改某个文件的类型,也能够在右下角进行批改,见下图:

独自批改某个文件

跨渠道协作时分的处理方法:

当咱们运用git库提交代码的时分,有的人或许运用mac,有的人运用linux,有的人运用windows,不同的开发环境假如都是依照自己体系的方法恣意批改换行类型,难免会让代码库全体紊乱或许发生许多没有必要的代码更新

那么处理该问题的方法有:core.autocrlf指令

git为了避免以上问题打乱跨渠道协作开发,运用指令能够转化LF和CRLF

详细体现为:

  • git config --global core.autocrlf true


Git能够在你push时主动地把行结束符CRLF转化成LF,而在pull代码时把LF转化成CRLF。用core.autocrlf来翻开此项功用,假如是在Windows体系上,把它设置成true,这样当签出代码时,LF会被转化成CRLF

  • git config --global core.autocrlf input

Linux或Mac体系运用LF作为行结束符;当一个以CRLF为行结束符的文件不小心被引入时你必定想进行批改,把core.autocrlf设置成input来告知 Git 在push时把CRLF转化成LF,pull时不转化

  • git config --global core.autocrlf false

在本地和代码库中都保存CRLF,不管pull仍是push都不变,代码库什么样,本地仍是什么姿态

当然在多人跨渠道作业时分,最好仍是约好运用LF,仍是CRLF,然后不同体系进行对应的设置,这样是作业标准,也有利于进步作业效率,期望以上能够协助我们。



作者:sososun
链接:https://www.jianshu.com/p/dd7464cf32b5
来历:简书
简书著作权归作者一切,任何方法的转载都请联络作者取得授权并注明出处。

posted @ 2019-03-27 13:29 wythern 阅览(13) | 谈论 (0)修改 保藏

2019年1月17日 #

How to shuffle arrays and slices in Go

原文在此

因为
Go没有为slice供给shuffle函数,所以需求自己想办法。因为我只需求随机一次遍历1 -> N,所以这段code最匹配。
func main() {
  vals := []int{10, 12, 14, 16, 18, 20}
  r := rand.New(rand.NewSource(time.Now().Unix()))
  for _, i := range r.Perm(len(vals)) {
    val := vals[i]
    fmt.Println(val)
  }
}

好像go不像scala有那种慵懒求值的特性,所以这儿的r.Perm()仍是发生了一个slice,假如N很大或许是个问题。



posted @ 2019-01-17 20:27 wythern 阅览(25) | 谈论 (0)修改 保藏

2018年8月14日 #

go test 用args带参数

测验中想经过指令行传递一些参数给test func,网上找了一些材料但进程不是很顺畅,这儿记载一下。
首要go test有一个-args的参数说能够到达这个意图,但实测下来发现有没有没差异。。。
google查到的大部分也是用到了flag类型。
flag.go的注释写的比较清楚
/*
    Package flag implements command-line flag parsing.

    Usage:

    Define flags using flag.String(), Bool(), Int(), etc.

    This declares an integer flag, -flagname, stored in the pointer ip, with type *int.
        import "flag"
        var ip = flag.Int("flagname", 1234, "help message for flagname")
    If you like, you can bind the flag to a variable using the Var() functions.
        var flagvar int
        func init() {
            flag.IntVar(&flagvar, "flagname", 1234, "help message for flagname")
        }
    Or you can create custom flags that satisfy the Value interface (with
    pointer receivers) and couple them to flag parsing by
        flag.Var(&flagVal, "name", "help message for flagname")
    For such flags, the default value is just the initial value of the variable.

    After all flags are defined, call
        flag.Parse()
    to parse the command line into the defined flags.

*/
因而需求做的工作便是:
1. 界说flag,这个需求在main()履行之前完结,我这儿在test文件里边用全局变量完结,但a能够放在函数里边。
var (
    
// Define global args flags.
    pA = flag.Int("a"0,  "a.")
    a 
= 0
)
2. parse flag,这个要在test func履行之前,所以能够考虑参加一个init()在test文件里。
func init() {
    flag.Parse()
    a 
= *pA
}
后边运用这些变量就没有问题了,比方这样
func TestInit(t *testing.T) {
    flag.Parse()
    t.Log(
"a = ", a)
}
这儿用到的首要是flag的功用,测验用发现有没有-args问题不大,所以这个用法或许不是很契合go test的要求,先用起来再说了。
REF
1. https://www.golangtc.com/t/584cbd16b09ecc2e1800000b
2. https://stackoverflow.com/.../process-command-line-arguments-in-go-test
3. https://hsulei.com/2017/08/23/gotest怎么运用自界说参数/

posted @ 伟德官网 wythern 阅览(197) | 谈论 (0)修改 保藏

[转]shell中if条件字符串、数字比对,[[ ]]和[ ]差异

原文在此

学习shell的时分总是被shell里的条件判别方法搞得头疼,常常不知道改 用[],[[]],(())仍是test,let,而很少有书把它们的联系解说的很清楚(应该是我领悟差或是看书太少),今日总结一下,根底的东西如它们 的运用方法不再赘述,要点说说它们的差异的运用时应该留意的当地。

先说[]和test,两者是相同的,在指令行里test expr和[ expr ]的作用相同。test的三个根本作用是判别文件、判别字符串、判别整数。支撑运用与或非将表达式连接起来。要留意的有:

1.test中可用的比较运算符只需==和!=,两者都是用于字符串比较的,不可用于整数比较,整数比较只能运用-eq, -gt这种方法。不管是字符串比较仍是整数比较都千万不要运用大于号小于号。当然,假如你真实想用也是能够的,关于字符串比较能够运用尖括号的转义方法, 假如比较"ab"和"bc":[ ab \< bc ],成果为真,也便是回来状况为0.

然后是[[ ]],这是内置在shell中的一个指令,它就比方才说的test强壮的多了。支撑字符串的方法匹配(运用=~操作符时乃至支撑shell的正则表达 式)。几乎强壮的令人发指!逻辑组合能够不运用test的-a,-o而运用&&,||这样更亲热的方法(针对c、Java程序员)。当 然,也不必想的太杂乱,根本只需记住
1.字符串比较时能够把右边的作为一个方法(这是右边的字符串不加双引号的状况下。假如右边的字符串加了双引号,则认为是一个文本字符串。),而不仅仅是一个字符串,比方[[ hello == hell? ]],成果为真。

别的要留意的是,运用[]和[[]]的时分不要小气空格,每一项两头都要有空格,[[ 1 == 2 ]]的成果为“假”,但[[ 1==2 ]]的成果为“真”!后一种显然是错的


3.最终便是let和(()),两者也是相同的(或许说根本上是相同的,双括号比let稍弱一些)。首要进行算术运算(上面的两个都不可),也比较合适进 行整数比较,能够直接运用了解的<,>等比较运算符。能够直接运用变量名如var而不需求$var这样的方法。支撑分号离隔的多个表达式

posted @ 2018-08-14 16:44 wythern 阅览(32) | 谈论 (0)修改 保藏

2018年8月1日 #

一张图了解公链和私链

图片来历:https://blog.slock.it/public-vs-private-chain-7b7ca45044f

posted @ 2018-08-01 14:05 wythern 阅览(29) | 谈论 (0)修改 保藏

2018年7月21日 #

Full go tool list (keep constructing)

REF:  https://dominik.honnef.co/posts/2014/12/an_incomplete_list_of_go_tools/

go get github.com/golang/lint/golint
go get github.com/kisielk/errcheck
go get golang.org/x/tools/cmd/benchcmp
go get github.com/cespare/prettybench
go get github.com/ajstarks/svgo/benchviz
go get golang.org/x/tools/cmd/stringer
go get github.com/josharian/impl
go get golang.org/x/tools/cmd/goimports
go get sourcegraph.com/sqs/goreturns
go get code.google.com/p/rog-go/exp/cmd/godef
go get github.com/nsf/gocode
go get golang.org/x/tools/cmd/oracle
go get golang.org/x/tools/cmd/gorename
go get github.com/kisielk/godepgraph

posted @ 2018-07-21 14:09 wythern 阅览(65) | 谈论 (0)修改 保藏

2018年7月14日 #

Some materials about RPC transaction call.

Introduction

Solidiay doc about ABI and contract access.
https://solidity.readthedocs.io/en/develop/abi-spec.html
https://solidity.readthedocs.io/en/latest/introduction-to-smart-contracts.html?highlight=selfdestruct
http://www.ethdocs.org/en/latest/contracts-and-transactions/accessing-contracts-and-transactions.html
http://ethdocs.org/en/latest/contracts-and-transactions/contracts.html#testing-contracts-and-transactions
https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=suicide [global variables like msg.sender]
ABI intro in Ethereum Wiki.
https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI#argument-encoding
https://github.com/ethereum/go-ethereum/wiki/Contract-Tutorial
JAON rpc api of Eth.
https://github.com/ethereum/wiki/wiki/JSON-RPC#json-rpc-api
https://github.com/ethereum/wiki/wiki/JavaScript-API#contract-methods
Deploy a contract using RPC.
https://github.com/rsksmart/rskj/wiki/Deploying-contracts-using-RPC-calls
A tool to generate the grpc server code for a contract
https://github.com/getamis/grpc-contract

How to test.

http://ethereum-tests.readthedocs.io/en/latest/test_types/transaction_tests.html
https://github.com/ethereum/cpp-ethereum/blob/develop/doc/generating_tests.rst
go-ethereum里边有一批vm和contract相关的tests,结合ABI和contract的界说,能够很简单的写一批自己定制的测验,从web3js或许直接在go project里边调用都能够。

posted @ 2018-07-14 17:00 wythern 阅览(46) | 谈论 (0)修改 保藏

2017年6月19日 #

What is shade jar, and what is its purpose.

https://stackoverflow.com/questions/13620281/what-is-the-maven-shade-plugin-used-for-and-why-would-you-want-to-relocate-java


Uber JAR, in short, is a JAR containing everything.

Normally in Maven, we rely on dependency management. An artifact contains only the classes/resources of itself. Maven will be responsible to find out all artifacts (JARs etc) that the project depending on when the project is built.

An uber-jar is something that take all dependencies, and extract the content of the dependencies and put them with the classes/resources of the project itself, in one big JAR. By having such uber-jar, it is easy for execution, because you will need only one big JAR instead of tons of small JARs to run your app. It also ease distribution in some case.

Just a side-note. Avoid using uber-jar as Maven dependency, as it is ruining the dependency resolution feature of Maven. Normally we create uber-jar only for the final artifact for actual deployment or for manual distribution, but not for putting to Maven repository.


Update: I have just discovered I haven't answered one part of the question : "What's the point of renaming the packages of the dependencies?". Here is some brief updates and hopefully will help people having similar question.

Creating uber-jar for ease of deployment is one use case of shade plugin. There are also other common use cases which involve package renaming.

For example, I am developing Foo library, which depends on a specific version (e.g. 1.0) of Bar library. Assuming I cannot make use of other version of Bar lib (because API change, or other technical issues, etc). If I simply declare Bar:1.0 as Foo's dependency in Maven, it is possible to fall into a problem: A Qux project is depending on Foo, and also Bar:2.0 (and it cannot use Bar:1.0 because Qux needs to use new feature in Bar:2.0). Here is the dilemma: should Qux use Bar:1.0 (which Qux's code will not work) or Bar:2.0 (which Foo's code will not work)?

In order to solve this problem, developer of Foo can choose to use shade plugin to rename its usage of Bar, so that all classes in Bar:1.0 jar are embedded in Foo jar, and the package of the embedded Bar classes is changed from com.bar to com.foo.bar. By doing so, Qux can safely depends on Bar:2.0 because now Foo is no longer depending on Bar, and it is using is own copy of "altered" Bar located in another package.

posted @ 2017-06-19 11:23 wythern 阅览(39) | 谈论 (0)修改 保藏

2017年5月18日 #

[Collection] Spark partition related things.

Partition:
Understanding:
1. https://www.dezyre.com/article/how-data-partitioning-in-spark-helps-achieve-more-parallelism/297
2. http://dev.sortable.com/spark-repartition/ -- example of partition & repartition to avoid data-imbalance.
3. https://acadgild.com/blog/partitioning-in-spark/ -- real case on existing partitioner & self-created partitioner.

Programming guidence.
Avoid using GroupByKey https://databricks.gitbooks.io/databricks-spark-knowledge-base/content/best_practices/prefer_reducebykey_over_groupbykey.html

Reference 1 says: Applying transformations that return RDDs with specific partitioners. Some operation on RDDs that hold to and propagate a partitioner are-
  • Join
  • LeftOuterJoin
  • RightOuterJoin
  • groupByKey
  • reduceByKey
  • foldByKey
  • sort
  • partitionBy
  • foldByKey
groupByKey is one of them, My understanding is such operations may cause extra shuffle, but repartition also helps relieve data imbalance if well considered, so use head please! :)

posted @ 2017-05-18 14:29 wythern 阅览(38) | 谈论 (0)修改 保藏

2017年4月17日 #

ubuntu switch window in current workspace.

gsettings set org.gnome.shell.app-switcher current-workspace-only true

[ref]https://unix.stackexchange.com/questions/171964/restrict-alttab-to-the-current-workspace-in-gnome-3

posted @ 2017-04-17 10:21 wythern 阅览(58) | 谈论 (0)修改 保藏

仅列出标题  下一页