Go Standard Lib

fmt Format specifiers: %t: boolean %c: character %U: unicode code point %s: strings or []bytes %q: quoted string %#q: quoted string with backquotes %b: bit representation %d: integers (base 10) %o: octal (base 8) notation %x/%X: hexadecimal (base 16) notation %f: floats %g: complex %e: scientific notation %p: pointers (hexadecimal address with prefix 0x) %v: default format, when String() exists, this is used. %+v: gives a complete output of the instance with its fields %#v: gives us a complete output of the instance with its fields and qualified type name %T gives us the complete type specification %%: if you want to print a literal % sign type user struct { name string } func main() { u := user{"tang"} //Printf 格式化输出 fmt.Printf("%+v\n", u) //格式化输出结构 fmt.Printf("%#v\n", u) //输出值的 Go 语言表示方法 fmt.Printf("%T\n", u) //输出值的类型的 Go 语言表示 fmt.Printf("%t\n", true) //输出值的 true 或 false fmt.Printf("%b\n", 1024) //二进制表示 fmt.Printf("%c\n", 11111111) //数值对应的 Unicode 编码字符 fmt.Printf("%d\n", 10) //十进制表示 fmt.Printf("%o\n", 8) //八进制表示 fmt.Printf("%q\n", 22) //转化为十六进制并附上单引号 fmt.Printf("%x\n", 1223) //十六进制表示,用a-f表示 fmt.Printf("%X\n", 1223) //十六进制表示,用A-F表示 fmt.Printf("%U\n", 1233) //Unicode表示 fmt.Printf("%b\n", 12.34) //无小数部分,两位指数的科学计数法6946802425218990p-49 fmt.Printf("%e\n", 12.345) //科学计数法,e表示 fmt.Printf("%E\n", 12.34455) //科学计数法,E表示 fmt.Printf("%f\n", 12.3456) //有小数部分,无指数部分 fmt.Printf("%g\n", 12.3456) //根据实际情况采用%e或%f输出 fmt.Printf("%G\n", 12.3456) //根据实际情况采用%E或%f输出 fmt.Printf("%s\n", "wqdew") //直接输出字符串或者[]byte fmt.Printf("%q\n", "dedede") //双引号括起来的字符串 fmt.Printf("%x\n", "abczxc") //每个字节用两字节十六进制表示,a-f表示 fmt.Printf("%X\n", "asdzxc") //每个字节用两字节十六进制表示,A-F表示 fmt.Printf("%p\n", 0x123) //0x开头的十六进制数表示 } io studygolang - io — 基本的 IO 接口 ...

January 1, 2000

Graph

Libraries DGL (Deep Graph Library) References Overview of DGL Pytorch Geometric Documentation Networkx # import import networkx as nx # load adjacency matrix G = nx.from_numpy_matrix(A) # get adjacency matrix A = nx.adjacency_matrix(G) A = nx.adjacency_matrix(G).todense() # drawing fig = plt.figure(figsize=(10,8)) ax = plt.subplot(111) pos = nx.spring_layout(G) #pos = nx.kamada_kawai_layout(G) nx.draw(G, ax=ax, pos=pos, node_size=10, node_color=colors, alpha=0.5, with_labels=True) # or nx.draw_networkx_nodes(G, ax=ax, pos=pos, node_size=100, node_color=colors, alpha=0.5) nx.draw_networkx_edges(G, ax=ax, pos=pos, alpha=0.1) # Laplacian Matrix lap = nx.linalg.laplacianmatrix.laplacian_matrix(G) lap = nx.linalg.laplacianmatrix.normalized_laplacian_matrix(G) # N=D^(-1/2)LD^(-1/2) # connected components nx.algorithms.components.number_connected_components(G) # relabel G = nx.relabel_nodes(G, lambda x: int(x[1:])) # get weights for n, nbrs in G.adj.items(): for nbr, eattr in nbrs.items(): wt = eattr['weight'] print('(%d, %d, %.3f)' % (n, nbr, wt)) for (u, v, wt) in G.edges.data('weight'): print('(%d, %d, %.3f)' % (u, v, wt)) # shorest path nx.shorest_paht(G, source, target) nx.shorest_paht_length(G, source, target) Projects deepwalk node2vec GraphEmbedding GraphSAGE graphsage-simple karateclub SINE Overlapping Community Detection with Graph Neural Networks

January 1, 2000

Hadoop

Hadoop Basics # 查看hdfs文件系统 hadoop fs -ls <dir> # 查看文本文件 hadoop fs -cat <filename> hadoop fs -cat <filename> | head # 查看压缩文件 hadoop fs -text <filename> # 查看文件大小 hadoop fs -du <dir> 其他命令可以看:hadoop shell commands

January 1, 2000

Hive

Hive [TOC] CLI # 启动cli hive # or hive --service cli # 定义变量 hive --define A=B # or hive -d A=B # 执行SQL语句 hive -e SELECT * FROM a_table # 运行文件 hive -f filename # or hive > source filename; # 运行初始化文件 # 可以将初始化内容加到$HOME/.hiverc文件中 hive -i filename # 历史记录保存在$HOME/.hivehistory文件中 # 配置文件在$HIVE_HOME/conf/hive-default.xml.template # 配置 hive --hiveconf option_A=true hive set hiveconf:option_A=trues; # 执行jar应用 hive --service jar # 执行shell命令,前面加! hive > !pwd; # 执行hadoop命令,去掉前面的hadoop hive > fs -ls /; # 注释 # -- 注释内容前面加'--' Database操作 # 查看database列表 SHOW DATABASES; # 创建database CREATE DATABASE a_database; # 查看信息 DESCRIBE DATABASE a_database; # 使用database USE a_database; # 删除database DROP a_database; # 修改属性 ALTER DATABASE a_database SET DBPROPERTIES('edited-by' = 'ychen'); Table操作 # 查看table列表 SHOW TABLES; SHOW TABLES IN a_database; # 查看表信息 DESCRIBE a_table; DESCRIBE a_database.a_table; DESCRIBE a_table.a_column; # 查看某一列 # 创建表 CREATE TABLE IF NOT EXISTS a_table ( name STRING COMMENT 'the name', salary FLOAT COMENT 'the salary' ) COMMENT 'Description of the table' TBLPROPERTIES ('creator'='me') LOCATION '/user/hive/warehouse/a_database/a_table'; # 删除表 DROP TABLE IF EXISTS a_table; # 重命名表 ALTER TABLE a_table RENAME TO b_table; # 修改列 ALTER TABLE a_table CHANGE COLUMN old_column new_column INT # 重命名列 AFTER other_column; # 修改位置 # 增加列 ALTER TABLE a_table ADD COLUMNS ( app_name STRING session_id LONG ) # 删除与替换列 ALTER TABLE a_table REPLACE COLUMNS ( a_column INT, b_column STRING ) 外部表 Hive没有所有权的数据,但是可以进行查询 ...

January 1, 2000

HTML

HTML Basic Template <!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <h1>This is a Heading</h1> <p>This is a paragraph.</p> </body> </html>

January 1, 2000

Java

Java Install sudo apt-get update sudo apt install openjdk-11-jdk Hello world public class Test { public static void main(String[] args) { System.out.println("Hello world!"); } } 指定JDK版本 export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home" export PATH=$JAVA_HOME/bin:$PATH:. 编译与打包 运行class # 编译java文件 javac Test.java # 会生成 Test.class # 运行编译后文件 java Test # 运行 Test.class # 指定 classpath 运行 java -classpath yourClassPath Test java -cp yourClassPath Test java -cp .:yourClassPath:yourClassPath2 Test # 默认为当前目录,多个 path 用分号分割 分离源文件与编译后文件 mkdir src && mv *.java src/ javac -d ./classes src/*.java # -d 表示生成的class文件存放位置 cd ./classes java Test 包管理 # add package echo "package here.there\n"`cat Test.java` > Test.java # 首行写包路径 mkdir here && mkdir here/there && mv Test.java here/there/ # 安装包路径创建文件夹 javac -d ../classes here/there/Test.java cd ../classes java here.there.Test # 运行时要指定包路径 JAR打包与运行 Working with Manifest Files: The Basics ...

January 1, 2000

Javascript

Basic var a = 10; // let b = 20; // 作用域以外不可引用,建议尽量用 let const c = 30; scope Hoisting Re-declaration var Function-scoped Yes, undefined if not initialized Yes let Block-scoped No, must be declared No const Block-scoped No, must be declared No String let s = "Hello, world" // => "ell": the 2nd, 3rd, and 4th characters s.substring(1,4) // => "ell": same thing s.slice(1,4) // => "rld": last 3 characters s.slice(-3) // => ["Hello", "world"]: s.split(", ") // => 2: position of first letter l s.indexOf("l") // => true: the string starts with these s.startsWith("Hell") // => true: s includes substring "or" s.includes("or") // => "Heya, world" s.replace("llo", "ya") // => "hello, world" s.toLowerCase() // => "H": the first character s.charAt(0) // => " x": add spaces on the left to a length of 3 "x".padStart(3) Template // greeting == "Hello Bill." let name = "Bill" let greeting = `Hello ${ name }.` Pattern Matching let text = "testing: 1, 2, 3" let pattern = /\d+/g pattern.test(text) text.search(pattern) text.match(pattern) text.replace(pattern, "#") text.split(/\D+/) 类型转换 // Number to string let n = 17 let s = n.toString() // String to number // => 3 parseInt("3 blind mice") // => 0.1 parseFloat(".1") // If the value is a string, wrap it in quotes, otherwise, convert (typeof value === "string") ? "'" + value + "'" : value.toString() 对象 let square = { area: function() { return this.side * this.side; }, side: 10 }; //等价于 let square = { area() { return this.side * this.side; }, side: 10 }; 数组 // forEach let data = [1, 2, 3, 4, 5], sum = 0 data.forEach(value => { sum += value; }) // map let a = [1, 2, 3] a.map(x => x*x) // filter let a = [5, 4, 3, 2, 1] a.filter(x => x < 3) // find and findIndex let a = [1, 2, 3, 4, 5] a.findIndex(x => x === 3) a.find(x => x % 5 === 0) // every and some a.every(x => x < 10) a.some(isNaN) // reduce a.reduce((x,y) => x+y, 0) // flat and flatMap [1, [2, 3]].flat() let phrases = ["hello world", "the definitive guide"] let words = phrases.flatMap(phrase => phrase.split(" ")) // concat let a = [1,2,3]; a.concat(4, 5) // stack and queue let stack = [] stack.push(1,2) stack.pop() let q = [] q.push(1,2) q.shift() // subarrays let a = [1, 2, 3, 4, 5, 6, 7, 8] a.slice(0,3) a.splice(4) // fill let a = new Array(5); a.fill(0) // indexOf let a = [0, 1, 2, 1, 0] a.indexOf(1) // includes let a = [1, true, 3, NaN] a.includes(true) // sort let a = ["banana", "cherry", "apple"] a.sort() // reverse a.reverse() // to string let a = [1, 2, 3] a.join(" ") [1,2,3].toString() 遍历 遍历列表 ...

January 1, 2000

JVM

JVM 概念 内存空间 程序计数器 虚拟机栈 本地方法栈 堆 方法区 运行时常量池 直接内存 垃圾回收 算法 引用计数法 可达性分析法 分配回收策略 Young Old 回收器 When to choose SerialGC, ParallelGC over CMS, G1 in Java? Serial:Mainly for single-cpu machine. Parallel:It uses multiple gc threads to handle heap, and perform stop-the-world pause during any gc. CMS:It’s designed to eliminate the long pause associated with the full gc of parallel & serial collector. G1:It’s low pause / server style gc, mainly for large heap (> 4Gb). ...

January 1, 2000

Kafka

Kafka Docker Install Install docker pull wurstmeister/zookeeper docker run -d --name zookeeper -p 2181:2181 -t wurstmeister/zookeeper docker pull wurstmeister/kafka docker run -d --name kafka -p 9092:9092 \ -e KAFKA_BROKER_ID=0 \ -e KAFKA_ZOOKEEPER_CONNECT=${host}:2181 \ -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://${host}:9092 \ -e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 \ wurstmeister/kafka Usage docker exec -it kafka /bin/bash cd opt/kafka_2.11-2.0.0/ # producer ./bin/kafka-console-producer.sh --broker-list localhost:9092 --topic mykafka # consumer ./bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic mykafka --from-beginning 配置 auto.create.topics.enable=false/true num.partitions=1 default.replication.factor=1 Listeners配置 Kafka 2.1 Documentation - 3.1 Broker Configs kafka的listeners和advertised.listeners,配置内外网分流 Kafka从上手到实践-Kafka集群:Kafka Listeners 只需要内网访问kafka listeners=PLAINTEXT://inner_ip:9092 或者配置SASL ...

January 1, 2000

Kubernetes

Kubernetes Viewing, finding resources # Get commands with basic output kubectl get services # List all services in the namespace kubectl get pods --all-namespaces # List all pods in all namespaces kubectl get pods -o wide # List all pods in the current namespace, with more details kubectl get deployment my-dep # List a particular deployment kubectl get pods # List all pods in the namespace kubectl get pod my-pod -o yaml # Get a pod's YAML # Describe commands with verbose output kubectl describe nodes my-node kubectl describe pods my-pod # print logs kubectl logs my-pod Creating objects kubectl apply -f ./my-manifest.yaml # create resource(s) kubectl apply -f ./my1.yaml -f ./my2.yaml # create from multiple files kubectl apply -f ./dir # create resource(s) in all manifest files in dir kubectl apply -f https://git.io/vPieo # create resource(s) from url kubectl create deployment nginx --image=nginx # start a single instance of nginx # create a Job which prints "Hello World" kubectl create job hello --image=busybox -- echo "Hello World" # create a CronJob that prints "Hello World" every minute kubectl create cronjob hello --image=busybox --schedule="*/1 * * * *" -- echo "Hello World" 模版文件 可以通过 kubectl explain pod 详细查看Pod资源所支持的所有字段的详细说明 ...

January 1, 2000