&      位运算 AND
| 位运算 OR
^ 位运算 XOR
&^ 位清空 (AND NOT)
<< 左移
>> 右移
// 获取0-n之间的所有偶数
func even(a int) (array []int) {
for i := 0; i < a; i++ {
if i&1 == 0 { // 位操作符&与C语言中使用方式一样
array = append(array, i)
}
}
return array
}

// 互换两个变量的值
func swap(a, b int) (int, int) {
a ^= b // 异或等于运算
b ^= a
a ^= b
return a, b
}

// 左移、右移运算
func shifting(a int) int {
a = a << 1
a = a >> 1
return a
}

// 取反操作
func nagation(a int) int {
// 注意: C语言中是 ~a+1这种方式
return ^a + 1 // Go语言取反方式和C语言不同,Go语言不支持~符号。
}

bnMultiplier := new(big.Int)
bnHeaderHash := new(big.Int)
bnChainOrigin := new(big.Int)
bnChainOrigin.Mul(bnHeaderHash,bnMultiplier)

A Set is a collection of values. You can iterate over those values, add new values, remove values and clear the set, get the set size, and check if the set contains an item. A value in the set might only be stored once, duplicates are not possible.

requiredClasses := mapset.NewSet()
requiredClasses.Add("Cooking")
requiredClasses.Add("English")
requiredClasses.Add("Math")
requiredClasses.Add("Biology")

scienceSlice := []interface{}{"Biology", "Chemistry"}
scienceClasses := mapset.NewSetFromSlice(scienceSlice)

electiveClasses := mapset.NewSet()
electiveClasses.Add("Welding")
electiveClasses.Add("Music")
electiveClasses.Add("Automotive")

bonusClasses := mapset.NewSet()
bonusClasses.Add("Go Programming")
bonusClasses.Add("Python Programming")

//Show me all the available classes I can take
allClasses := requiredClasses.Union(scienceClasses).Union(electiveClasses).Union(bonusClasses)
fmt.Println(allClasses) //Set{Cooking, English, Math, Chemistry, Welding, Biology, Music, Automotive, Go Programming, Python Programming}


//Is cooking considered a science class?
fmt.Println(scienceClasses.Contains("Cooking")) //false

//Show me all classes that are not science classes, since I hate science.
fmt.Println(allClasses.Difference(scienceClasses)) //Set{Music, Automotive, Go Programming, Python Programming, Cooking, English, Math, Welding}

//Which science classes are also required classes?
fmt.Println(scienceClasses.Intersect(requiredClasses)) //Set{Biology}

//How many bonus classes do you offer?
fmt.Println(bonusClasses.Cardinality()) //2

//Do you have the following classes? Welding, Automotive and English?
fmt.Println(allClasses.IsSuperset(mapset.NewSetFromSlice([]interface{}{"Welding", "Automotive", "English"}))) //true

这本书更多的讲的是对脑相关影响因素的讲解,有哪些因素,为什么,哪些坏处等等常识性普及。
没有太多的实用价值。

睡觉,冥想,心情愉快即可。

8b487920.png

引用文章

primecoin pow 是寻找质数链,包括三种类型:
第一类坎宁安链,第二类坎宁安链,和孪生坎宁安链。

第一类坎宁安链的规则是,素数链中每个数都是前一个数的两倍减一。第一个长度为5的第一类坎宁安链包含以下5个素数:
1531,3061,6121,12241,24481

第二类坎宁安链,素数链中每个数都是前一个数的两倍加一。第一个长度为5的第二类坎宁安链出现得更快,如下:
2,5,11,23,47

最后,孪生坎宁安链的规则是:大小相差2的孪生素数,后一对的平均值是前一对的平均值的两倍。很容易理解,双坎宁安链具有偶数个数。第一个长度为6的双坎宁安链是:
211049,211051,422099,422101,844199,844201

孪生坎宁安链本质上是第一类坎宁安链和第二类坎宁安链组合而成。每对的第一个数字组合正好是第二类坎宁安链,每对的第二个数字组合正好是第一类坎宁安链。

验证方式

费马测试(费马小定理):
费马测试是一种快速辨别素数的方法:以任意数字(通常为2)为底,以需要测试的素数为幂,计算结果再用来减去该素数和一个大数的乘积,看是否得到原来的数字。

费马小定理:
如果 n 是一个素数,a 是小于 n 的任意正整数,那么 a 的 n 次方与 a 模 n 同余。(两个数称为是模 n 的同余,如果它们除以 n 的余数相同。数 a 除以 n 的余数称为 a 取模 n 的余数,或简称为 a 取模 n)。

目标难度的匹配

怎么区分7.2和7.5的素数链长?
拿数列中第一个非素数,进行费马测试余数越小,分级长度越大。例如,我们的链2,5,11,23,47下一个值是95,依据上面使用的重复减法的过程计算后,余数是54,因此,链的长度为5+(95-54)/95=5.43。然而,1531……24481素数链的下一个值48961,费马余数为1024,所以链的长度为5+(48961-1024)/48961=5.97。为了一个为了使素数链可以成为有效的工作证明,它用小数表示的长度至少要和现在的难度想当。

我们不希望工作量证明可以重复使用,素数币还增加了另一种限制。基于素数币的目的,对于双向链的起点被定义为前面两个数字的平均,对于单坎宁安链的的起点被定义为假想双向链存在前面两数字的平均。例如,上面两个单坎宁安链的起点分别是1530和3。这样限制是因为素数列起点必须能够被工作证明的区块哈希数整除。哈希函数从属性看,寻找特定的散列值的唯一途径只能是采用简单地尝试新的值直到得到结果。因此,得到有效的工作证明的方法就是针对已知哈希值的区块寻找素数列,这些素数列只有对特定的区块才有效。

use vscode as ide for bitcoin

  1. make sure compile bitcoin manually successful
  2. ubuntu 16.04 install vscode
  3. install c++ (microsoft) and C++ Intellisense
  4. open project folder, press F5 debug select C++(GDB/LLDB), will auto generate a file
    launch.json. need some modification
"program": "${workspaceRoot}/src/primecoind", //setup application path
"args": ["-printtoconsole"], //application params
"cwd": "${workspaceRoot}",
  1. ctrl+p, input task, select config build task will generate a file tasks.json
    do some modify
    "command":"BDB_PREFIX=/home/ubuntu/prime/db-4.8.30.NC/build_unix/build BDB_INCLUDE_PATH=${BDB_PREFIX}/include BDB_LIB_PATH=${BDB_PREFIX}/lib cd ${workspaceFolder}/src && make -f makefile.unix"
  2. press crtl + shift + B to build. setup breakpoint and tap F5 run debug

Use Cases

The common use case for apt-cacher-ng is where you have a sizable network and
would like to speed up all the apt-get update calls made by your nodes,
especially if you are running chef or puppet periodically.
It is also used for complying to security policies that restrict internet access
to bulk of hosts except for a designated proxy server.

Apt-Cacher-NG是一个缓存代理服务(或者apt代理),对基于Debian的设备,如 Ubuntu, Kubuntu, Xubuntu, Edubuntu, Linux Mint等,它被是用来缓存已经下载过的包。

7fbbd728.png

install in docker

create docker file

# docker file for apt-cacher-ng service 2018.11.14
FROM ubuntu:18.04

MAINTAINER Tyler Cheng - "<zhengjun2018@gmail.com>"

ARG DEBIAN_FRONTEND=noninteractive

# modify to custom china source
RUN sed -i 's/archive.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list

VOLUME ["/var/cache/apt-cacher-ng"]
RUN apt-get update && apt-get install -y apt-cacher-ng

EXPOSE 3142
CMD chmod 777 /var/cache/apt-cacher-ng && /etc/init.d/apt-cacher-ng start && tail -f /var/log/apt-cacher-ng/*

create image

docker build -t apt_cache_ng_service .

run image

启动镜像,并且把端口映射到宿主机的3142上

docker run -d -p 3142:3142 --name apt_cacher_service apt_cache_ng_service

可以使用docker命令来查看日志

docker logs -f apt_cacher_service

登录浏览器查看
http://localhost:3142

install and use

sudo apt-get install apt-cacher-ng
sudo /etc/init.d/apt-cacher-ng start

Patch configuration file:
sudo nano /etc/apt-cacher-ng/acng.conf

sudo service apt-cacher-ng force-reload

If everything went okay, then when visiting http://localhost:3142
you should see instructions on how to configure your clients to use the proxy.

HTTPS repositories:
PassThroughPattern: .*

Client Proxy Configuration
There are two ways to tell apt-get to use your proxy:

  1. Global /etc/apt/apt.conf method
    RUN echo “Acquire::http::Proxy "http://dockerhost:3142\";" > /etc/apt/apt.conf.d/00aptproxy

Add this line to /etc/apt/apt.conf (or to a file named /etc/apt/apt.conf.d/00proxy):
Acquire::http { Proxy "http://yourdomain.example:3142"; };
This tells apt to proxy all requests to that address and port.

  1. Per repository /etc/apt/sources.list method
    You can edit the /etc/apt/sources.list file and append the proxy to the beginning like so:
    Before:
    deb http://ftp.debian.org/debian stable main contrib non-free
    deb-src http://ftp.debian.org/debian stable main contrib non-free
    After:
deb http://yourdomain.example:3142/ftp.debian.org/debian stable main contrib non-free
deb-src http://yourdomain.example:3142/ftp.debian.org/debian stable main contrib non-free

Note about Cache Visibility
It’s important to note that apt-get has it’s own internal cache, and is pretty good about not downloading the same indexes and packages over and over again. Unfortunately, this is at odds with apt-cacher-ng, as it cannot cache requests it never receives. You can force a download by clearing the contents of local caches (/var/cache/apt/* and /var/lib/apt/lists/*), then running apt-get update again to ensure that apt-cacher-ng sees all possible requests. Note: apt-get clean is not sufficient, as it only clears the local package cache, and not the index and list cache.

清理无效的缓存

http://localhost:3142/acng-report.html?abortOnErrors=aOe&byPath=bP&byChecksum=bS&truncNow=tN&incomAsDamaged=iad&purgeNow=pN&doExpire=Start+Scan+and%2For+Expiration&calcSize=cs&asNeeded=an#bottom

xxd 可以将镜像文件导出为 hex 格式
然后使用 diff 比较

xxd primecoind > primecoind.hex
diff -u 1/primcoind.hex 2/primecoind.hex

总体来说推荐阅读。
日本-和田秀树的作品,分了几个类别来说明应用的注意事项等。
提高干劲所需的心理学知识
三大法则:

  1. 希望法则
  2. 充实法则
  3. 关系法则

建立职场人际关系所需的心理学知识
市场营销等
还是有些收获的。

b0e99a36.png 0a229ece.png 635ad584.png

赋值给变量

var=$(command)