├── .gitignore ├── antlr_practise ├── .gitignore ├── array_init │ ├── ArrayInit.g4 │ ├── readme.md │ └── translate.md ├── calculator │ ├── LabeledExpr.g4 │ ├── readme.md │ └── t.expr ├── expr │ ├── Expr.g4 │ ├── readme.md │ └── t.expr ├── grammar_import │ ├── CommonLexerRules.g4 │ ├── LibExpr.g4 │ └── readme.md ├── hello │ └── Hello.g4 ├── readme.md └── sql │ └── where.g4 ├── asciidoc └── demo.adoc ├── c++ ├── align_ptr.cpp ├── c++14 │ ├── array_sort.cpp │ ├── constptr.cpp │ ├── decltype.cpp │ ├── map.cpp │ ├── nullptr.cpp │ ├── rawstring.cpp │ ├── return_mul.cpp │ ├── rvalue.cpp │ ├── swap_range.cpp │ ├── tuple.cpp │ ├── type_deduction.cpp │ ├── unordered_map.cpp │ ├── unordered_set.cpp │ └── various_auto.cpp ├── double.cpp ├── goto.c ├── linux_ns.cpp ├── memory_order │ ├── relaxed-for-counter.cc │ ├── release-acquire.cc │ ├── release-consume.cc │ ├── run.sh │ ├── seq-cst.cc │ └── transive-release-acquire.cc ├── parent.cpp ├── project_template │ ├── .vscode │ │ ├── launch.json │ │ ├── settings.json │ │ └── tasks.json │ └── cpp │ │ ├── .vscode │ │ ├── launch.json │ │ ├── settings.json │ │ └── tasks.json │ │ ├── Makefile │ │ └── src │ │ └── main │ │ └── a.cpp ├── signal │ ├── sigaction.cc │ ├── sigaction2.cc │ └── signal.cc ├── unordered_map.cpp └── vec.cc ├── c ├── atomic.c ├── c11 │ └── noreturn.c ├── devrandom.c ├── encapsulation │ ├── main.c │ ├── point.c │ └── point.h ├── gettimeofday.c ├── implicit_convertion │ ├── compare.c │ ├── compare.php │ └── compare.py ├── limit.c ├── linux_errno.c ├── null_equal.c ├── pidtest.c ├── sds │ ├── .gitignore │ ├── .vscode │ │ └── launch.json │ ├── Makefile │ ├── README.md │ ├── binary_safe_test.c │ ├── cch.c │ ├── sds.c │ ├── sds.h │ ├── sds.h.gch │ ├── sdsalloc.h │ ├── sdstest.c │ └── testhelp.h ├── set_nonblocking.c ├── setlinebuf.c ├── tid_pid_lwpid.c └── variant.c ├── ch.go ├── database └── mysql │ └── sql │ ├── check_cardinality.sql │ ├── find_index_not_used.sql │ └── find_tables_without_primary.sql ├── design_patterns ├── Go │ └── readme.md ├── Rust │ └── readme.md └── readme.md ├── elasticconfigs ├── README.md └── elasticsearch2.0 │ ├── elasticsearch │ ├── elasticsearch.yml │ ├── jdbc │ └── test.sh │ ├── reindex.json │ └── result_window.json ├── envoy └── envoy.yaml ├── etcd ├── etcd_cluster.sh ├── etcd_cluster2.sh └── etcd_cluster3.sh ├── github_icons └── show.md ├── go ├── 1.8 │ ├── db.go │ ├── sort.go │ └── struct_convert.go ├── 1.9 │ ├── alias.go │ └── syncMap.go ├── Makefile ├── a.go ├── algorithm │ ├── 8queens.go │ ├── leetcode │ │ ├── 1 │ │ │ ├── 1_test.go │ │ │ └── main.go │ │ ├── 1.go │ │ ├── 100.go │ │ ├── 11.go │ │ ├── 14.go │ │ ├── 15.go │ │ ├── 17.go │ │ ├── 19.go │ │ ├── 2.go │ │ ├── 20.go │ │ ├── 21.go │ │ ├── 24.go │ │ ├── 27.go │ │ ├── 32.go │ │ ├── 344.go │ │ ├── 387.go │ │ ├── 4.go │ │ ├── 520.go │ │ ├── 557.go │ │ ├── 561.go │ │ ├── 566.go │ │ ├── 7.go │ │ ├── 74.go │ │ ├── 8.go │ │ └── 88.go │ └── merge_sort.go ├── array │ ├── array2.go │ └── array_index.go ├── asm │ ├── basic_math_ops │ │ ├── math.go │ │ └── math.s │ ├── control_flow │ │ ├── m.go │ │ └── m.s │ ├── func_call │ │ ├── call.go │ │ ├── call.s │ │ └── readme.md │ ├── global │ │ ├── global.go │ │ ├── global.s │ │ ├── global2.s │ │ └── readme.md │ ├── goid │ │ ├── go_tls.h │ │ ├── goid.go │ │ └── goid_amd64.s │ ├── hardware_or_virtual │ │ ├── where.go │ │ └── where.s │ ├── is_frame_pointer_on_stack_value_equal_to_directive_FP │ │ ├── global.go │ │ ├── global.s │ │ └── readme.md │ ├── leaq_test │ │ ├── a.go │ │ └── a.s │ ├── local_var.go │ ├── math │ │ ├── math.go │ │ └── math_amd64.s │ ├── non_local_var.go │ ├── paramtest │ │ └── param.go │ ├── readme.md │ ├── refer_to_global_var_in_go_file │ │ ├── a.go │ │ └── a.s │ ├── registers_test │ │ ├── r.go │ │ └── r.s │ ├── relative_pos_of_FP_and_SP │ │ ├── global.go │ │ └── global.s │ ├── what_is_struct_in_asm │ │ ├── t.go │ │ └── t.s │ └── where_is_fp_sp │ │ ├── readme.md │ │ ├── where.go │ │ └── where.s ├── assert │ ├── assert.go │ ├── assert2.go │ └── bench │ │ ├── assert_benchmark.go │ │ └── assert_test.go ├── ast │ ├── .vscode │ │ └── settings.json │ ├── example.go │ ├── example.go.bak2 │ ├── example.go.bakk │ ├── example2.go │ ├── token.go │ └── x.go ├── atomic │ └── uber_atomic.go ├── atomic_bench │ ├── atomic.go │ └── atomic_test.go ├── badcode │ └── badcode.go ├── beanstalkDemo │ ├── consumer.go │ └── producer.go ├── bit │ └── flags.go ├── black_magic │ ├── a.s │ ├── linkname.go │ └── readme.md ├── broadcast │ └── src │ │ ├── broadcast │ │ └── broadcast.go │ │ └── main.go ├── buffer_chain │ ├── buf.go │ └── buf_test.go ├── builtin │ ├── readme.md │ ├── slice.go │ └── str.go ├── channel │ ├── channelLen.go │ ├── readFromClosedChannel.go │ └── writeToClosedChannel.go ├── circular_dependency │ ├── a │ │ └── a.go │ ├── b │ │ └── b.go │ └── main.go ├── cli │ ├── app.go │ └── subcmds.go ├── closure │ ├── closure.go │ └── closure2.go ├── comparable │ ├── func_compare.go │ └── str.go ├── concurrent │ ├── conMapRead.go │ ├── conMapRead2.go │ ├── conMapRead3.go │ ├── conMapRead4.go │ └── readme.md ├── concurrent_map_write_iter │ ├── m.go │ └── readme.md ├── context │ ├── ctx_should_not_be_printed.go │ ├── pass_nil_to_context_param.go │ ├── timeout.go │ ├── with_cancel.go │ ├── with_cancel_same_ctx.go │ └── with_value.go ├── copy │ └── shallow.go ├── count_bit_in_str.go ├── crawler │ ├── crawler.go │ ├── demo_cr.go │ └── z.go ├── cryptoBench │ ├── bcrypt.go │ ├── md4 │ │ ├── md4.go │ │ └── md4_test.go │ └── sha1 │ │ ├── sha1.go │ │ └── sha1_test.go ├── dataStructs │ ├── annoymous_struct.go │ ├── appendtest.go │ ├── arrtest.go │ ├── complextest.go │ ├── extendtest.go │ ├── interfacetest.go │ ├── interfacetest2.go │ ├── interfacetest3.go │ ├── listtest.go │ ├── maptest.go │ ├── nested_struct.go │ └── typeEqualTest │ │ ├── a │ │ └── sss.go │ │ └── typetest.go ├── db │ └── mysql.go ├── deepl │ ├── fetch.go │ ├── markdown.go │ └── md.md ├── dependency-experiment │ ├── func_based │ │ ├── init.go │ │ ├── main.go │ │ ├── online_funcs.go │ │ └── test_funcs.go │ ├── injection_based │ │ ├── codis.go │ │ ├── dependency_injection.go │ │ ├── rate_service.go │ │ └── star_service.go │ ├── interface_based │ │ ├── init.go │ │ ├── main.go │ │ ├── order_service.go │ │ ├── price_service.go │ │ ├── push_service.go │ │ └── user_service.go │ └── nested_struct_based │ │ ├── init.go │ │ ├── main.go │ │ ├── order_service.go │ │ ├── price_service.go │ │ ├── push_service.go │ │ └── user_service.go ├── dirty_part │ ├── aaa.go │ ├── for_block.go │ ├── for_block2.go │ ├── http_get.go │ ├── loop_iterator_snapshot.go │ ├── nilInterface.go │ ├── nil_receiver.go │ ├── polymorphic.go │ ├── polymorphic2.go │ └── stackcheck.go ├── distlock │ └── etcd_lock.go ├── dlv.go ├── double_buffer │ ├── conc.go │ └── readme.md ├── dubbotest │ └── registry.go ├── elasticsearch │ ├── elastic.go │ └── elasticsql_example.go ├── encrypt │ ├── aes.go │ ├── aes_decode.go │ └── readme.md ├── env │ └── demo.go ├── epoll │ ├── easygo │ │ ├── easygo.go │ │ ├── go.mod │ │ └── go.sum │ ├── evio │ │ └── evio.go │ └── gaio │ │ └── gaio.go ├── errcheck │ └── errcheck.go ├── error │ ├── err_print.go │ ├── internal_err.go │ ├── juju_err │ │ └── juju_err.go │ └── pkg_err │ │ ├── .vscode │ │ └── launch.json │ │ └── printf.go ├── escape_analysis │ ├── a.go │ └── a.o ├── etcdTest │ ├── clientErrHandler.go │ ├── clientTest.go │ └── lock.go ├── expand │ ├── channel.go │ ├── map.go │ ├── readme.md │ └── slice.go ├── file │ ├── filetest.go │ ├── get_file_list.go │ ├── list_all_file.go │ ├── merged │ ├── read.go │ └── read_all.go ├── fixData │ └── fix.go ├── flag │ └── parse.go ├── flowControl │ ├── addaddtest.go │ ├── defertest.go │ ├── for.go │ ├── gotest.go │ ├── gototest.go │ ├── panictest.go │ ├── strtest.go │ └── typetest.go ├── flow_based │ ├── flow.go │ ├── foo.bar │ └── foo.txt ├── full_chan.go ├── future │ ├── panic_or_not.go │ └── runner.go ├── gc.go ├── gc │ ├── gc.go │ ├── main.go │ ├── pre-collect-problem │ │ ├── main.go │ │ └── readme.md │ └── readme.md ├── gdb │ └── t.go ├── generics │ ├── QuicksortWithoutGenerics.go │ └── newSort.go ├── go-prompt │ └── test.go ├── go1.13 │ ├── deferproc │ ├── deferproc.go │ ├── deferstack.go │ └── readme.md ├── gocyclo.go ├── goevaluate │ ├── demo.go │ └── m.go ├── gomod │ ├── go.mod │ ├── go.sum │ ├── main.go │ └── vendor │ │ ├── github.com │ │ ├── cch123 │ │ │ ├── elasticsql │ │ │ │ ├── .gitignore │ │ │ │ ├── .travis.yml │ │ │ │ ├── LICENSE │ │ │ │ ├── glide.lock │ │ │ │ ├── glide.yaml │ │ │ │ ├── main.go │ │ │ │ ├── readme.md │ │ │ │ ├── select_agg_handler.go │ │ │ │ ├── select_handler.go │ │ │ │ └── unsupported.go │ │ │ └── gomodexp │ │ │ │ └── esutil │ │ │ │ └── main.go │ │ └── xwb1989 │ │ │ └── sqlparser │ │ │ ├── .gitignore │ │ │ ├── .travis.yml │ │ │ ├── CONTRIBUTORS.md │ │ │ ├── LICENSE.md │ │ │ ├── Makefile │ │ │ ├── README.md │ │ │ ├── analyzer.go │ │ │ ├── ast.go │ │ │ ├── comments.go │ │ │ ├── dependency │ │ │ ├── bytes2 │ │ │ │ └── buffer.go │ │ │ ├── hack │ │ │ │ └── hack.go │ │ │ ├── querypb │ │ │ │ └── query.pb.go │ │ │ └── sqltypes │ │ │ │ ├── bind_variables.go │ │ │ │ ├── plan_value.go │ │ │ │ ├── testing.go │ │ │ │ ├── type.go │ │ │ │ └── value.go │ │ │ ├── encodable.go │ │ │ ├── impossible_query.go │ │ │ ├── normalizer.go │ │ │ ├── parsed_query.go │ │ │ ├── redact_query.go │ │ │ ├── sql.go │ │ │ ├── sql.y │ │ │ ├── token.go │ │ │ └── tracked_buffer.go │ │ └── modules.txt ├── gopacket │ ├── learn │ │ ├── auto_reset_conn.go │ │ ├── filter_port.go │ │ ├── find_all_devices.go │ │ ├── live_capture.go │ │ ├── loop_back.go │ │ ├── read_pcap_file.go │ │ └── write_to_pcap_file.go │ ├── readme.md │ ├── rst.go │ └── rst2.go ├── gopsutil │ ├── .gitignore │ ├── cpu_of_pid.go │ ├── cpu_of_pid2.go │ ├── go.mod │ ├── go.sum │ └── main.go ├── goroutine │ ├── blocktest.go │ ├── channel.go │ ├── channelmakeandchannelnotmake.go │ ├── chantest.go │ ├── goForPrint.go │ ├── goroutine.go │ ├── goroutinetest.go │ ├── maxprocstest.go │ ├── nilfuncgo.go │ ├── ppchantest.go │ ├── server.go │ └── worker-pool.go ├── goroutine_schedule │ └── schedule_example.go ├── goyacc │ ├── parse.y │ ├── prac │ │ └── parse.y │ ├── readme.md │ ├── y.go │ └── y.output ├── grpc │ ├── c.go │ ├── hello.pb.go │ ├── hello.proto │ ├── readme.md │ └── s.go ├── hack │ └── export_private_struct.go ├── hash_bench │ ├── alg.go │ └── alg_test.go ├── hex │ └── decode.go ├── html-to-markdown │ ├── go.mod │ ├── go.sum │ ├── main.go │ └── newyorker.html ├── http │ ├── client_with_timeout.go │ ├── client_without_timeout.go │ ├── fasthttp │ │ └── helloserver.go │ ├── gen_cert.sh │ ├── handlerLeak.go │ ├── http2 │ │ ├── h2c.go │ │ ├── http2.go │ │ ├── readme.md │ │ ├── server.crt │ │ └── server.key │ ├── http_get.go │ ├── httpclient.go │ ├── httpclient_grequest.go │ ├── httprouter │ │ └── httprouter.go │ ├── httptest.go │ ├── jsontest.go │ ├── panic │ │ ├── panictest.go │ │ ├── panicwrap.go │ │ ├── pppptest.go │ │ └── readme.md │ ├── proxy.go │ ├── proxyclient.go │ ├── reco.go │ ├── server.key │ └── server.pem ├── import_cycle │ ├── break_cycle │ │ ├── action │ │ │ └── act.go │ │ ├── character │ │ │ └── cha.go │ │ └── item │ │ │ └── item.go │ └── original │ │ ├── action │ │ └── action.go │ │ ├── character │ │ └── cha.go │ │ └── item │ │ └── item.go ├── inherit.go ├── interface │ ├── checkInterface.go │ ├── int.go │ ├── inter.go │ ├── interfacePointer.go │ ├── interfacePtrMoreTest.go │ ├── interfaceReflect.go │ ├── isHandlerFuncPointer.go │ ├── multi_instance.go │ ├── nilInterface.go │ ├── pointerInterface.go │ └── readme.md ├── interface_unmsarshal.go ├── internal │ ├── copytest.go │ └── copytest2.go ├── json │ ├── djsontest.go │ ├── emptyunmarshal.go │ ├── ffjs.go │ ├── ffjs_ffjson.go │ ├── ffjsontest.go │ ├── jsonTest.go │ ├── nestedMarshal.go │ ├── omitTest.go │ └── rawMessage.go ├── left_recursion_detect │ └── main.go ├── line_feed.go ├── linkname │ └── private_fields.go ├── linter │ └── gometalinter.sh ├── linux_processes │ ├── pidtest.go │ └── ppidtest.go ├── lock │ ├── local_lock.go │ ├── redis_setnx.go │ ├── redlock.go │ └── trylock.go ├── lockfree │ └── atomic_side_effect.go ├── log │ ├── etcdlogtest.go │ ├── getFuncAndLine.go │ ├── logrus_and_rotation.go │ ├── logrus_withfields.go │ └── zap.go ├── map │ ├── isMapOrdered.go │ ├── is_len_of_map_thread_safe.go │ ├── map_query.go │ ├── range.go │ ├── range2.go │ ├── readme.md │ ├── res.txt │ └── structmap.go ├── map_bench │ ├── map.go │ └── map_test.go ├── mapexpr │ ├── mapexpr.go │ ├── mapexpr_test.go │ └── readme.md ├── math │ ├── accurance.go │ ├── nan.go │ └── rand.go ├── memmap │ ├── demo.jpg │ └── memmap.go ├── metalintertest │ └── a.go ├── middleware │ └── standard_middleware.go ├── monkey_test │ ├── cannot_patch_private_function.go │ └── t.go ├── msgpack │ ├── ignoretest.go │ ├── t.go │ └── ugorji.go ├── nats │ ├── pub.go │ ├── qs.go │ └── t1.go ├── net │ ├── iptest.go │ ├── readhttpontcp.go │ ├── redistest.go │ ├── sockettest.go │ ├── tcp.go │ └── urltest.go ├── offheap │ └── main.go ├── os │ ├── net_proc.go │ ├── ostest.go │ ├── pidtest.go │ ├── replace_function_on_the_fly.go │ ├── signaltest.go │ ├── sysinfo.go │ └── test │ │ └── www_test.go ├── panic │ ├── before_1-9-2-bug.go │ ├── concurrent_map_writes_panic.go │ ├── defer_can_run_or_not.go │ ├── panic_or_not.go │ ├── panic_recover_and_return.go │ └── readme.md ├── params │ └── demo.go ├── parser │ ├── decl.go │ └── left_recur_detect.go ├── parser_related │ └── tableName.go ├── path │ ├── api.go │ └── dir_t.go ├── peg │ ├── go_peg_parser.go │ ├── grammar.peg │ └── readme.md ├── pipe │ ├── main.go │ └── pipe ├── pkgerror │ └── demo.go ├── pool │ └── redigo_with_pool │ │ ├── Godeps │ │ ├── Godeps.json │ │ └── Readme │ │ ├── redigo_self_pool.go │ │ ├── redigo_with_vitess_pool.go │ │ └── vendor │ │ ├── github.com │ │ ├── garyburd │ │ │ └── redigo │ │ │ │ ├── LICENSE │ │ │ │ ├── internal │ │ │ │ └── commandinfo.go │ │ │ │ └── redis │ │ │ │ ├── conn.go │ │ │ │ ├── doc.go │ │ │ │ ├── go17.go │ │ │ │ ├── log.go │ │ │ │ ├── pool.go │ │ │ │ ├── pre_go17.go │ │ │ │ ├── pubsub.go │ │ │ │ ├── redis.go │ │ │ │ ├── reply.go │ │ │ │ ├── scan.go │ │ │ │ └── script.go │ │ ├── golang │ │ │ └── glog │ │ │ │ ├── LICENSE │ │ │ │ ├── README │ │ │ │ ├── glog.go │ │ │ │ └── glog_file.go │ │ └── youtube │ │ │ └── vitess │ │ │ ├── LICENSE │ │ │ └── go │ │ │ ├── acl │ │ │ ├── acl.go │ │ │ └── fallback_policy.go │ │ │ ├── cache │ │ │ └── lru_cache.go │ │ │ ├── pools │ │ │ ├── id_pool.go │ │ │ ├── numbered.go │ │ │ └── resource_pool.go │ │ │ └── sync2 │ │ │ ├── atomic.go │ │ │ ├── consolidator.go │ │ │ ├── doc.go │ │ │ └── semaphore.go │ │ └── golang.org │ │ └── x │ │ └── net │ │ ├── AUTHORS │ │ ├── CONTRIBUTORS │ │ ├── LICENSE │ │ ├── PATENTS │ │ └── context │ │ ├── context.go │ │ ├── go17.go │ │ └── pre_go17.go ├── pprof │ ├── pprof.go │ ├── producer_consumer.go │ ├── producer_consumer_test.go │ ├── producer_consumer_without_write.go │ └── readme.md ├── producer_consumer │ ├── 1_to_1_improved.go │ ├── 1_to_1_improved2.go │ ├── 1_to_1_original.go │ └── 1_to_many_original.go ├── profile │ ├── auto_dump_heap.go │ └── thread_profile.go ├── proxy │ └── main.go ├── race │ ├── g.go │ ├── g2.go │ └── g_test.go ├── raft │ ├── hashicorp.go │ └── hashicorp │ │ ├── config.go │ │ ├── fsm.go │ │ ├── handler.go │ │ ├── main.go │ │ └── state.go ├── rand │ └── 1.go ├── ratelimit │ ├── jujulimit.go │ └── uberratelimitdemo.go ├── receiver │ ├── interface.go │ ├── normal.go │ └── pointer_rec.go ├── recover │ └── rec.go ├── redis │ ├── main.go │ ├── readme.md │ ├── redisTest.go │ ├── redisTest.php │ ├── redis_protocal_server.go │ ├── redispool.go │ ├── redlock.go │ └── redlock2.go ├── reflect │ ├── basic_type.go │ ├── call.go │ ├── deep_equal.go │ ├── field_offset.go │ ├── init │ │ └── main.go │ ├── interface_and_slice_in_reflect.go │ ├── make_func.go │ ├── map_type.go │ ├── readme.md │ ├── ref_cp.go │ ├── reflecttest.go │ ├── slice_type.go │ ├── slice_type2.go │ ├── struct_type.go │ ├── time_type.go │ ├── use_name_to_generate_instance.go │ └── zero_is_what.go ├── regex │ └── MatchString.go ├── ringbuffer │ ├── readme.md │ ├── t.go │ └── t2.go ├── runtime │ ├── forloopinline.go │ ├── goroutine.go │ ├── gotoolobjdump.go │ ├── inline.go │ ├── keepalive.go │ ├── monitor │ │ ├── gops.go │ │ ├── goroutine_num.go │ │ └── memstats.go │ ├── runtimeCaller.go │ └── schedule.go ├── select │ ├── neverstop_select.go │ ├── timeout.go │ └── timetick.go ├── shell │ └── exe.go ├── shuffle.go ├── slice │ ├── append_when_under_array_has_capacity.go │ ├── del_elem.go │ ├── merge_slices.go │ ├── nil_and_empty_slice.go │ ├── nil_slice_empty_slice.go │ └── reverse.go ├── snowflake │ ├── maxInt.go │ ├── snow.go │ ├── snowflake.go │ └── sonyflake.go ├── spiders │ ├── 0daydown.go │ └── crawler_daydown.go ├── sql │ ├── queryDemo.go │ ├── sqlx.go │ └── upperdb.go ├── strconv │ └── formatFloat.go ├── string │ ├── .vscode │ │ └── launch.json │ ├── alloc_or_not_alloc │ │ ├── a.go │ │ ├── a_test.go │ │ └── readme.md │ ├── b.go │ ├── convert.go │ ├── hasPrefix.go │ ├── joinAndConcatBench │ │ ├── ben_test.go │ │ ├── main.go │ │ └── readme.md │ ├── replaceNums.go │ ├── replaceTest.go │ ├── searchStr.go │ ├── splintN.go │ ├── splitTest.go │ ├── split_and_same_under_array │ │ ├── ben_test.go │ │ ├── main.go │ │ └── readme.md │ └── string_display_same_but_not_euqal.go ├── struct │ └── struct_copy.go ├── subset │ ├── subset.go │ └── subset_test.go ├── suffix │ └── main.go ├── sync │ ├── copyOfLocks.go │ └── structLock.go ├── syscall │ ├── file.dat │ ├── mmap_to_read.go │ ├── mmap_to_write.go │ └── test.dat ├── template │ ├── main.go │ └── querycode.tpl ├── test_fail_in_1.13 │ ├── lib.go │ └── lib_test.go ├── test_with_tags │ ├── m.go │ ├── m_test.go │ ├── production.go │ ├── readme.md │ └── test_fakes.go ├── text_scanner │ └── scan.go ├── thrift │ ├── GoUnusedProtection__.go │ ├── client │ │ └── c.go │ ├── hello-consts.go │ ├── hello.go │ ├── hello.thrift │ └── server │ │ └── s.go ├── time │ ├── location.go │ ├── parseAnyTime.go │ ├── parseInLocation.go │ ├── timetest.go │ ├── timetime.go │ └── timeunmarshal.go ├── tls │ ├── client.go │ ├── client2.go │ ├── client_no_tls.go │ ├── read_buffer │ │ ├── server.crt │ │ ├── server.key │ │ └── tls_http_server.go │ ├── server.crt │ ├── server.go │ └── server.key ├── trace │ ├── readme.md │ └── trace.go ├── types │ ├── aliasTypeConvert.go │ └── intConvert.go ├── unicode │ ├── encod.go │ └── utest.go ├── unicorn │ ├── readme.md │ └── test.go ├── unixsocket │ ├── client.go │ └── server.go ├── unsafe │ ├── gc_free_map │ │ └── gc_free_test.go │ ├── readme.md │ └── unsafeAlignment.go ├── uuidtest │ ├── useUUIDGEN │ │ ├── util.go │ │ └── uuid_test.go │ └── uselib │ │ ├── util.go │ │ └── uuid_test.go ├── validator │ └── main.go ├── version │ └── v.go ├── viper │ └── main.go ├── web_framework_component │ ├── ginLikeMW │ │ ├── main.go │ │ └── middleware.go │ └── middlewaretest.go ├── zk.go └── zookeeper │ ├── lock.go │ ├── lock2.go │ └── testWatch.go ├── go_web ├── api_code_gen │ ├── controller_generate.go │ └── model_generate.go ├── chi_with_doc.go ├── echo.go ├── form │ ├── ben_test.go │ └── goplayground-form.go ├── gin.go ├── gin │ ├── main.go │ └── templates │ │ └── index.tmpl ├── httprouter_learn.go ├── httprouter_learn2.go ├── inject.go ├── interfaceof.go ├── martini.go ├── readme.md ├── upload.go └── validator │ ├── asaskevich_govalidator.go │ ├── binderr.go │ ├── cch123_binding.go │ ├── ginbind.go │ ├── gorilla_schema.go │ └── mholt_binding.go ├── gomod ├── go.mod ├── go.sum └── main.go ├── graphviz ├── ggg.svg ├── gsm.svg ├── gsm_true.svg ├── gsm_without_gc.svg ├── psm.png ├── psm.svg └── psm_true.svg ├── images └── 5g war.png ├── js ├── closure.js ├── closure2.html ├── closure2.js ├── generator.js ├── intervaltest.js ├── node_modules │ └── fibers │ │ ├── .npmignore │ │ ├── LICENSE │ │ ├── README.md │ │ ├── bin │ │ ├── .npmignore │ │ ├── darwin-ia32-v8-3.14 │ │ │ └── fibers.node │ │ ├── darwin-x64-v8-3.14 │ │ │ └── fibers.node │ │ ├── linux-ia32-v8-3.14 │ │ │ └── fibers.node │ │ ├── linux-x64-v8-3.14 │ │ │ └── fibers.node │ │ ├── win32-ia32-v8-3.14 │ │ │ └── fibers.node │ │ └── win32-x64-v8-3.14 │ │ │ └── fibers.node │ │ ├── binding.gyp │ │ ├── build.js │ │ ├── fibers.js │ │ ├── future.js │ │ ├── package.json │ │ ├── quick-test.js │ │ ├── src │ │ ├── coroutine.cc │ │ ├── coroutine.h │ │ ├── fibers.cc │ │ └── libcoro │ │ │ ├── LICENSE │ │ │ ├── README │ │ │ ├── conftest.c │ │ │ ├── coro.c │ │ │ └── coro.h │ │ ├── test.js │ │ └── test │ │ ├── already-running.js │ │ ├── bad-context.js │ │ ├── child-process.js │ │ ├── current.js │ │ ├── exec.js │ │ ├── exit.js │ │ ├── fibonacci.js │ │ ├── finish-multiple.js │ │ ├── future-exception.js │ │ ├── future.js │ │ ├── illegal-yield.js │ │ ├── pool.js │ │ ├── process-title.js │ │ ├── stack-overflow.js │ │ ├── stack-overflow2.js │ │ ├── started.js │ │ └── unwind.js ├── segmentfault.js ├── sleep.js ├── test.js ├── test2.js ├── test3.js ├── thistest.js └── timeouttest.js ├── kafka ├── go.mod ├── go.sum └── producer.go ├── net ├── programming │ ├── readme.md │ └── tcpip │ │ ├── ch17 │ │ ├── echo_EPETserv.c │ │ └── echo_epollserver.c │ │ ├── ch7 │ │ ├── file_client.c │ │ ├── file_server.c │ │ └── readme.md │ │ ├── correct_echo_client.c │ │ ├── echo_client.c │ │ ├── echo_server.c │ │ ├── endian_conv.c │ │ ├── hello_client.c │ │ ├── hello_server.c │ │ ├── inet_addr.c │ │ ├── inet_aton.c │ │ ├── inet_ntoa.c │ │ ├── tcp_client.c │ │ ├── tcp_server.c │ │ ├── udp_echo_client.c │ │ └── udp_echo_server.c └── same_port │ ├── readme.md │ └── same_port_outgoing_connections.py ├── os ├── chapter_2 │ ├── asciinema │ │ └── key2_p2.json │ ├── main.c │ └── readme.md ├── chapter_3 │ ├── hello.s │ ├── hello_with_jmp.s │ ├── practise │ │ ├── aplusb.go │ │ ├── loop.s │ │ ├── read_and_calc.s │ │ ├── readme.md │ │ └── reverse_string.s │ └── readme.md ├── chapter_4 │ ├── array_pointer.c │ ├── func_call.c │ ├── more_than_7_params.c │ └── readme.md └── tools_introduction │ └── nm.md ├── php ├── ISO8601.php ├── acc_test.php ├── accurance.php ├── arr_test.php ├── arr_test2.php ├── array_column_test.php ├── array_combine_test.php ├── array_slice.php ├── array_slice_test.php ├── array_unique.php ├── coltest.php ├── copydata.php ├── csvtest.php ├── datetest.php ├── decode_test.php ├── dump.rdb ├── equaltest.php ├── exec_test.php ├── explode_test.php ├── fuck.php ├── func_test.php ├── functest.php ├── implode_test.php ├── intstrtest.php ├── json_test.php ├── magic_test.php ├── mb_substr.php ├── mobile.php ├── multisort.php ├── nodirect.php ├── nowtest.php ├── ob_clean.php ├── php_int_max.php ├── pipeline_stacktest.php ├── pipelinetest.php ├── pregreplace_test.php ├── redis.php ├── redis_subtest.php ├── sort.php ├── sprintftest.php ├── stackoverflow │ └── 8queen.php ├── time_test2.php ├── timetest.php ├── timetest3.php ├── uniqid_test.php └── unset_test.php ├── python ├── checkAll.py ├── collectEvent.py ├── dict_init.py ├── extract │ ├── calc.py │ └── readme.md ├── for_range.py ├── get_cpu.py ├── getopt.py ├── guolele │ ├── guolele │ │ ├── __init__.py │ │ ├── __init__.pyc │ │ ├── items.py │ │ ├── items.pyc │ │ ├── pipelines.py │ │ ├── settings.py │ │ ├── settings.pyc │ │ └── spiders │ │ │ ├── __init__.py │ │ │ ├── __init__.pyc │ │ │ ├── guolele_spider.py │ │ │ └── guolele_spider.pyc │ └── scrapy.cfg ├── mysqltest.py ├── osArgs.py ├── otp.py ├── sendmail.py ├── sort.py ├── timedelta.py └── timetest.py ├── rabbitmq ├── delivery_confirm │ ├── consumer.py │ ├── producer.py │ └── readme.md ├── hello_world │ ├── config.py │ ├── consumer.py │ └── producer.py └── rpc_demo │ ├── rpc_client.py │ └── rpc_server.py ├── readme.md ├── rpc ├── shared.thrift └── tutorial.thrift ├── rust ├── 1.40 │ └── non_exhaustive │ │ ├── a │ │ ├── Cargo.toml │ │ └── src │ │ │ └── lib.rs │ │ └── b │ │ ├── Cargo.toml │ │ └── src │ │ └── main.rs ├── 1.42 │ └── hello │ │ ├── Cargo.toml │ │ └── src │ │ └── main.rs ├── 1.43 │ └── hello │ │ ├── Cargo.toml │ │ └── src │ │ └── main.rs ├── actix │ └── actix_test │ │ ├── Cargo.lock │ │ ├── Cargo.toml │ │ └── src │ │ └── main.rs ├── assoc │ ├── Cargo.lock │ ├── Cargo.toml │ └── src │ │ └── main.rs ├── assoc2 │ ├── Cargo.lock │ ├── Cargo.toml │ └── src │ │ └── main.rs ├── assoc3 │ ├── Cargo.lock │ ├── Cargo.toml │ ├── readme.md │ └── src │ │ └── main.rs ├── astd_load_test │ ├── Cargo.toml │ └── src │ │ └── main.rs ├── async_demos │ ├── Cargo.lock │ ├── Cargo.toml │ └── src │ │ └── main.rs ├── async_tcp_server │ ├── Cargo.toml │ └── src │ │ └── main.rs ├── asyncstd │ ├── Cargo.lock │ ├── Cargo.toml │ └── src │ │ └── main.rs ├── box_arr │ ├── Cargo.lock │ ├── Cargo.toml │ └── src │ │ └── main.rs ├── box_linklist │ ├── Cargo.lock │ ├── Cargo.toml │ └── src │ │ └── main.rs ├── build_list_from_vec.rs ├── capstone.rs ├── channel │ ├── Cargo.lock │ ├── Cargo.toml │ └── src │ │ └── main.rs ├── closure │ ├── Cargo.lock │ ├── Cargo.toml │ └── src │ │ └── main.rs ├── combine │ └── demo │ │ ├── Cargo.lock │ │ ├── Cargo.toml │ │ └── src │ │ └── main.rs ├── csv_parser │ ├── Cargo.lock │ ├── Cargo.toml │ ├── numbers.csv │ └── src │ │ ├── csv.pest │ │ └── main.rs ├── elastic_test │ ├── Cargo.lock │ ├── Cargo.toml │ └── src │ │ └── main.rs ├── expr_test │ ├── Cargo.lock │ ├── Cargo.toml │ └── src │ │ ├── expr.pest │ │ └── main.rs ├── flat_map │ ├── Cargo.lock │ ├── Cargo.toml │ └── src │ │ └── main.rs ├── future-impl │ ├── executor │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── executor.rs │ │ │ └── main.rs │ ├── simple_poll │ │ ├── Cargo.toml │ │ └── src │ │ │ └── main.rs │ └── simplefuture │ │ ├── Cargo.toml │ │ └── src │ │ ├── future.rs │ │ └── main.rs ├── hashmap │ ├── Cargo.lock │ ├── Cargo.toml │ └── src │ │ └── main.rs ├── httparse │ ├── Cargo.lock │ ├── Cargo.toml │ └── src │ │ └── main.rs ├── iter │ ├── Cargo.toml │ └── src │ │ └── main.rs ├── lazy_static │ ├── Cargo.lock │ ├── Cargo.toml │ └── src │ │ └── main.rs ├── lifetime_test │ ├── Cargo.lock │ ├── Cargo.toml │ └── src │ │ └── main.rs ├── load_test │ ├── Cargo.toml │ └── src │ │ └── main.rs ├── loop_time_and_mul_threads_join │ ├── Cargo.toml │ └── src │ │ └── main.rs ├── maplit │ ├── .vscode │ │ └── settings.json │ ├── Cargo.toml │ └── src │ │ └── main.rs ├── mio_test │ ├── Cargo.toml │ └── src │ │ └── main.rs ├── module_test │ ├── Cargo.toml │ └── src │ │ ├── array.rs │ │ ├── inner │ │ ├── go.rs │ │ └── mod.rs │ │ ├── list.rs │ │ └── main.rs ├── net2_test │ ├── Cargo.toml │ └── src │ │ └── main.rs ├── ngx_rs │ ├── Cargo.toml │ └── src │ │ └── main.rs ├── nom │ └── basic │ │ ├── Cargo.lock │ │ ├── Cargo.toml │ │ ├── readme.md │ │ └── src │ │ └── main.rs ├── partial_eq │ ├── Cargo.lock │ ├── Cargo.toml │ └── src │ │ └── main.rs ├── pest_test │ ├── .idea │ │ ├── encodings.xml │ │ ├── misc.xml │ │ ├── modules.xml │ │ ├── pest_test.iml │ │ ├── vcs.xml │ │ └── workspace.xml │ ├── Cargo.lock │ ├── Cargo.toml │ └── src │ │ ├── ident.pest │ │ └── main.rs ├── phantomdata │ ├── Cargo.lock │ ├── Cargo.toml │ └── src │ │ └── main.rs ├── prec_climber_test │ ├── Cargo.lock │ ├── Cargo.toml │ └── src │ │ ├── grammar.pest │ │ └── main.rs ├── print_file_and_line │ ├── Cargo.lock │ ├── Cargo.toml │ └── src │ │ └── main.rs ├── proc_macro_workshop │ ├── Cargo.toml │ └── src │ │ ├── bool_expr.rs │ │ ├── callback.rs │ │ ├── count_tt.rs │ │ ├── debug.rs │ │ ├── easy.rs │ │ ├── internal_rule.rs │ │ ├── linkedlist.rs │ │ ├── main.rs │ │ ├── match_rule.rs │ │ ├── readme.md │ │ ├── substitution_is_not_token_based.rs │ │ └── tt_muncher.rs ├── programming_rust │ └── ch1 │ │ ├── cmd_args │ │ ├── Cargo.lock │ │ ├── Cargo.toml │ │ └── src │ │ │ └── main.rs │ │ ├── gcd │ │ ├── Cargo.lock │ │ ├── Cargo.toml │ │ └── src │ │ │ └── main.rs │ │ ├── hello │ │ ├── Cargo.lock │ │ ├── Cargo.toml │ │ ├── src │ │ │ └── main.rs │ │ └── target │ │ │ └── rls │ │ │ └── debug │ │ │ ├── .cargo-lock │ │ │ ├── .fingerprint │ │ │ └── hello-361a3be39b79a777 │ │ │ │ ├── bin-hello-361a3be39b79a777 │ │ │ │ ├── bin-hello-361a3be39b79a777.json │ │ │ │ └── dep-bin-hello-361a3be39b79a777 │ │ │ ├── deps │ │ │ └── hello-361a3be39b79a777.d │ │ │ └── libhello.d │ │ └── web-sum │ │ ├── Cargo.lock │ │ ├── Cargo.toml │ │ └── src │ │ └── main.rs ├── read_from_stdin │ ├── Cargo.toml │ ├── readme.md │ └── src │ │ └── main.rs ├── refcell_linklist │ ├── Cargo.lock │ ├── Cargo.toml │ └── src │ │ └── main.rs ├── reqwest │ └── example │ │ ├── Cargo.lock │ │ ├── Cargo.toml │ │ └── src │ │ └── main.rs ├── rock_test │ ├── Cargo.lock │ ├── Cargo.toml │ └── src │ │ └── main.rs ├── rocket_complete_project │ ├── Cargo.lock │ ├── Cargo.toml │ ├── build.rs │ └── src │ │ ├── conf │ │ ├── db.toml │ │ ├── etcd.toml │ │ ├── ratelimit.toml │ │ └── redis.toml │ │ ├── config │ │ └── mod.rs │ │ ├── controller │ │ ├── mod.rs │ │ ├── order.rs │ │ └── user.rs │ │ ├── init.rs │ │ ├── logic │ │ └── mod.rs │ │ ├── main.rs │ │ └── model │ │ └── mod.rs ├── rust_book │ ├── ch1 │ │ ├── borrow_twice.rs │ │ └── clone.rs │ └── ch2 │ │ ├── cargo │ │ └── hello_world │ │ │ ├── Cargo.toml │ │ │ └── src │ │ │ └── main.rs │ │ └── helloworld.rs ├── rust_programming_lang │ ├── .gitignore │ └── guess_num │ │ ├── Cargo.lock │ │ ├── Cargo.toml │ │ └── src │ │ └── main.rs ├── rustyline_test │ ├── .idea │ │ ├── encodings.xml │ │ ├── misc.xml │ │ ├── modules.xml │ │ ├── rustyline_test.iml │ │ ├── vcs.xml │ │ └── workspace.xml │ ├── Cargo.lock │ ├── Cargo.toml │ └── src │ │ └── main.rs ├── serdejson_test │ ├── Cargo.lock │ ├── Cargo.toml │ └── src │ │ └── main.rs ├── tcp_proxy │ ├── Cargo.toml │ └── src │ │ └── main.rs ├── thrift_test │ ├── Cargo.toml │ ├── src │ │ ├── main.rs │ │ └── x.rs │ └── x.idl ├── tokio_load_test │ ├── Cargo.toml │ └── src │ │ └── main.rs └── traits │ ├── Cargo.lock │ ├── Cargo.toml │ └── src │ └── main.rs ├── scala ├── companion_can_see_private.scala ├── companion_object.scala ├── lambda │ ├── closure.scala │ ├── closure2.scala │ ├── function_as_param.scala │ ├── lambda.scala │ ├── returning_annoymous_function.scala │ └── returning_function.scala ├── lists │ ├── access_by_position.scala │ ├── create_from_range.scala │ ├── fold_left.scala │ ├── head_tail.scala │ ├── immutable.scala │ ├── list.scala │ ├── list_methods.scala │ ├── nil_compare.scala │ ├── reduce_list.scala │ ├── short_hand.scala │ ├── tail_reuse.scala │ └── use_paren.scala ├── map │ └── basic_def.scala ├── object.scala ├── object_is_singleton.scala ├── rdd │ ├── basic.scala │ └── rdd.txt ├── readme.md ├── spark │ └── test.scala └── tuple │ └── tuple.scala ├── shell ├── awk │ ├── dat.txt │ ├── fix.sh │ └── test.awk ├── build.sh ├── download.sh ├── es_delete_index.sh ├── expect ├── forloop.sh ├── lastm.sh ├── move.sh ├── multi_andloop.sh ├── simple_loop.sh └── today.sh ├── syscall ├── what_is_backlog.md ├── what_is_fork.md ├── what_is_malloc.md ├── what_is_mmap.md └── what_is_sendfile.md ├── uml ├── activity.png ├── activity.txt ├── activity_icons.png ├── activity_icons.txt ├── actor.png ├── actor.txt ├── advanced_activity.png ├── advanced_activity.txt ├── advanced_actor.png ├── advanced_actor.txt ├── advanced_sequence.png ├── advanced_sequence.txt ├── auto_dump.plantuml ├── auto_dump2.plantuml ├── more_advanced_activity.png ├── more_advanced_activity.txt ├── more_advanced_seq.png ├── more_advanced_seq.txt ├── plantuml.jar ├── sequence.png ├── sequence.txt └── ufs.plantuml ├── vagrant_files ├── Vagrantfile ├── another │ └── Vagrantfile ├── bootstrap.sh ├── init.sh ├── readme.md └── uinit.sh ├── vscode_configs ├── readme.md └── settings.json └── x.md /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | target 3 | .idea 4 | doc 5 | Cargo.lock 6 | -------------------------------------------------------------------------------- /antlr_practise/.gitignore: -------------------------------------------------------------------------------- 1 | */.antlr/* 2 | *.go 3 | *.tokens 4 | -------------------------------------------------------------------------------- /antlr_practise/calculator/t.expr: -------------------------------------------------------------------------------- 1 | 193 2 | a = 4 3 | b = 5 4 | a+b*2 5 | (1+2)*3 6 | -------------------------------------------------------------------------------- /antlr_practise/expr/readme.md: -------------------------------------------------------------------------------- 1 | ``` 2 | step 1: 3 | javac *.java 4 | 5 | step 2: 6 | grun Expr prog -gui t.expr 7 | ``` 8 | -------------------------------------------------------------------------------- /antlr_practise/expr/t.expr: -------------------------------------------------------------------------------- 1 | 193 2 | a = 4 3 | b = 5 4 | a+b*2 5 | (1+2)*3 6 | -------------------------------------------------------------------------------- /antlr_practise/grammar_import/CommonLexerRules.g4: -------------------------------------------------------------------------------- 1 | lexer grammar CommonLexerRules; // 注意开头的 lexer grammar 2 | 3 | ID : [a-zA-Z]+; 4 | INT : [0-9]+; 5 | NEWLINE:'\r'?'\n'; 6 | WS : [ \t]+ -> skip; // 丢弃空白字符 7 | -------------------------------------------------------------------------------- /antlr_practise/grammar_import/LibExpr.g4: -------------------------------------------------------------------------------- 1 | grammar LibExpr; 2 | import CommonLexerRules; // import 已经存在的语法规则 3 | /* 起始规则 */ 4 | prog : stat + ; // 程序由多个 statement 组成 5 | 6 | stat : expr NEWLINE 7 | | ID '=' expr NEWLINE 8 | | NEWLINE 9 | ; 10 | 11 | expr : expr ('*' | '/') expr 12 | | expr ('+' | '-') expr 13 | | INT 14 | | ID 15 | | '(' expr ')' 16 | ; 17 | -------------------------------------------------------------------------------- /antlr_practise/grammar_import/readme.md: -------------------------------------------------------------------------------- 1 | 主要演示如何 import 2 | 3 | 复杂语法可以分多个文件对分析器内容进行组织 4 | -------------------------------------------------------------------------------- /antlr_practise/hello/Hello.g4: -------------------------------------------------------------------------------- 1 | grammar Hello; 2 | r : 'hello' ID; 3 | ID : [a-z]+; 4 | WS : [ \t\r\n]+ -> skip; 5 | -------------------------------------------------------------------------------- /antlr_practise/readme.md: -------------------------------------------------------------------------------- 1 | build go target 2 | ----------- 3 | https://github.com/antlr/antlr4/blob/master/doc/go-target.md 4 | 5 | ``` 6 | antlr4 -Dlanguage=Go hello.g4 7 | ``` 8 | -------------------------------------------------------------------------------- /c++/c++14/constptr.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | const int a = 1; 6 | auto b = a; 7 | b = 4; 8 | auto c = &b; 9 | auto d = &a; 10 | 11 | cout << typeid(c).name() << endl; 12 | cout << typeid(d).name() << endl; 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /c++/c++14/decltype.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int a = 1, b = 2; 6 | decltype(a) c = a + b; 7 | cout << c << endl; 8 | cout << typeid(c).name() << endl; 9 | auto d = a + c; 10 | cout << d << endl; 11 | cout << typeid(d).name() << endl; 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /c++/c++14/map.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main(int argc, char * argv[]) { 6 | map m = {{"a", 1}, {"b", 2}, {"c", 3}}; 7 | cout << m.count("b") << endl; 8 | cout << m["b"] << endl; 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /c++/c++14/nullptr.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int * p = nullptr; 6 | cout << "this is nullptr in c++14 " << p < 2 | using namespace std; 3 | 4 | int main() { 5 | string raw = R"(\\a\\wqbdadfdsfsdf\dfadf\df\s\df\)"; 6 | cout << raw << endl; 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /c++/c++14/rvalue.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int && ref = 1+2; 6 | ref +=1; 7 | int a = 1; 8 | cout << "value is " << ref << " and ptr is " << &ref << endl; 9 | cout << "value is " << a << " and ptr is " << &a<< endl; 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /c++/double.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | double a = 0.57; 6 | double b = a * 100; 7 | cout << a << endl; 8 | cout << b << endl; 9 | cout << (int)b << endl; 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /c++/goto.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int a() { 4 | goto ERROR_HANDLE; 5 | return 1; 6 | ERROR_HANDLE: 7 | printf("aaa"); 8 | return 0; 9 | } 10 | 11 | int main() { 12 | goto ERROR_HANDLE; 13 | ERROR_HANDLE: 14 | printf("1"); 15 | 16 | return 0; 17 | } 18 | 19 | -------------------------------------------------------------------------------- /c++/memory_order/run.sh: -------------------------------------------------------------------------------- 1 | #!bin/bash 2 | for i in `seq 1 1000` 3 | do 4 | ./a.out 5 | done 6 | -------------------------------------------------------------------------------- /c++/parent.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class Father{ 5 | public: 6 | virtual void test(){} 7 | void tt() { 8 | test(); 9 | } 10 | }; 11 | 12 | class Son : public Father{ 13 | public: 14 | void test() { cout << "son test" << endl;} 15 | 16 | }; 17 | 18 | int main() { 19 | Father * a = new Son(); 20 | a->tt(); 21 | } 22 | 23 | -------------------------------------------------------------------------------- /c++/project_template/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=733558 3 | // for the documentation about the tasks.json format 4 | "version": "0.1.0", 5 | "command": "make", 6 | "isShellCommand": true, 7 | "args": [], 8 | "showOutput": "always" 9 | } -------------------------------------------------------------------------------- /c++/project_template/cpp/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=733558 3 | // for the documentation about the tasks.json format 4 | "version": "0.1.0", 5 | "command": "make", 6 | "isShellCommand": true, 7 | "args": [], 8 | "showOutput": "always" 9 | } -------------------------------------------------------------------------------- /c++/project_template/cpp/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | g++ src/main/a.cpp -o out/output 3 | clean: 4 | rm -rf out/* 5 | -------------------------------------------------------------------------------- /c++/signal/sigaction2.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void handle_sigint(int sig) 5 | { 6 | printf("Caught signal %d\n", sig); 7 | } 8 | 9 | int main() 10 | { 11 | struct sigaction act; 12 | act.sa_handler = handle_sigint; 13 | sigemptyset(&act.sa_mask); 14 | act.sa_flags = 0; 15 | sigaction(SIGINT, &act, NULL); 16 | while (1) ; 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /c++/signal/signal.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void handle_sigint(int sig) 5 | { 6 | printf("Caught signal %d\n", sig); 7 | } 8 | 9 | int main() 10 | { 11 | signal(SIGINT, handle_sigint); 12 | while (1) ; 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /c++/unordered_map.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | unordered_map m = {{1,2}, {3,2}}; 7 | m[12] = 1; 8 | m[14] = 1; 9 | for(auto &x: m) { 10 | cout << x.first << " " << x.second << endl; 11 | } 12 | } -------------------------------------------------------------------------------- /c/c11/noreturn.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | // c11 增加了 _Alignof _Alignas _Atomic _Generic _Noreturn _Static_assert 4 | // _Thread_local 几个新关键字 5 | 6 | _Noreturn fun() { 7 | printf("in fun\n"); 8 | } 9 | 10 | int main() { 11 | printf("start main\n"); 12 | fun(); 13 | printf("end main\n"); 14 | } 15 | -------------------------------------------------------------------------------- /c/devrandom.c: -------------------------------------------------------------------------------- 1 | #include 2 | void main() { 3 | int dev_random = open("/dev/urandom", O_RDONLY); 4 | printf("%d", dev_random); 5 | int NUMBYTES = 8; 6 | unsigned char rand_data[NUMBYTES]; 7 | int r = read(dev_random, &rand_data, NUMBYTES); 8 | printf("%d\n", r); 9 | for(int i=0;i 3 | 4 | int main() { 5 | struct Point * p = makePoint(1.1, 2.2); 6 | printf("%p", p); 7 | // printf("%f", p->x); 8 | // 这样的无法访问到 p->x 的,编译会报错 9 | return 0; 10 | } -------------------------------------------------------------------------------- /c/encapsulation/point.c: -------------------------------------------------------------------------------- 1 | #include "point.h" 2 | #include 3 | 4 | // .c 中定义的结构体,在 .h 中无法访问,且对外部不可见 5 | struct Point { 6 | double x; 7 | double y; 8 | }; 9 | 10 | struct Point * makePoint(double x, double y) { 11 | struct Point * p = malloc(sizeof(struct Point)); 12 | p->x = x; 13 | p->y = y; 14 | return p; 15 | } 16 | -------------------------------------------------------------------------------- /c/encapsulation/point.h: -------------------------------------------------------------------------------- 1 | struct Point; 2 | 3 | struct Point * makePoint(double, double); 4 | -------------------------------------------------------------------------------- /c/implicit_convertion/compare.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | printf("%d\n", 4 < '2'); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /c/implicit_convertion/compare.php: -------------------------------------------------------------------------------- 1 | >> Type ./sds-test to run the sds.c unit tests." 6 | 7 | clean: 8 | rm -f sds-test 9 | -------------------------------------------------------------------------------- /c/sds/sds.h.gch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cch123/test/8a9d3dd4fbd3eecceaf4d77eb6cb56ca4e1528b9/c/sds/sds.h.gch -------------------------------------------------------------------------------- /c/sds/sdstest.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cch123/test/8a9d3dd4fbd3eecceaf4d77eb6cb56ca4e1528b9/c/sds/sdstest.c -------------------------------------------------------------------------------- /c/setlinebuf.c: -------------------------------------------------------------------------------- 1 | #include "stdio.h" 2 | 3 | int main() { 4 | setlinebuf(stdout); 5 | printf("abc"); 6 | printf("abc"); 7 | printf("abc"); 8 | printf("abc"); 9 | sleep(10); 10 | return 1; 11 | } 12 | -------------------------------------------------------------------------------- /ch.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "time" 4 | 5 | func main() { 6 | var ch = make(chan int) 7 | go func() { 8 | time.Sleep(time.Second) 9 | ch = nil 10 | time.Sleep(time.Second) 11 | ch = make(chan int) 12 | }() 13 | 14 | for { 15 | select { 16 | case v := <-ch: 17 | println(v) 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /design_patterns/Go/readme.md: -------------------------------------------------------------------------------- 1 | Go dir 2 | -------------------------------------------------------------------------------- /design_patterns/Rust/readme.md: -------------------------------------------------------------------------------- 1 | Rust dir 2 | -------------------------------------------------------------------------------- /design_patterns/readme.md: -------------------------------------------------------------------------------- 1 | # design patterns demos in Go/Rust 2 | -------------------------------------------------------------------------------- /elasticconfigs/elasticsearch2.0/reindex.json: -------------------------------------------------------------------------------- 1 | { 2 | "source": { 3 | "index": "ark_callcenter" 4 | }, 5 | "dest": { 6 | "index": "ark_callcenter_g_service_worksheet" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /elasticconfigs/elasticsearch2.0/result_window.json: -------------------------------------------------------------------------------- 1 | { 2 | "index" : { 3 | "max_result_window" : 600000 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /github_icons/show.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/cch123/elasticsql.svg?branch=master)](https://travis-ci.org/cch123/elasticsql) 2 | [![Go Documentation](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)](https://godoc.org/github.com/cch123/elasticsql) 3 | -------------------------------------------------------------------------------- /go/1.8/db.go: -------------------------------------------------------------------------------- 1 | //cancelable queries 2 | //visible database types 3 | //multiple result sets 4 | //ping can hit server 5 | //named parameters 6 | //transaction isolation levels 7 | // https://docs.google.com/document/d/1F778e7ZSNiSmbju3jsEWzShcb8lIO4kDyfKDNm4PNd8/edit# 8 | 9 | package main 10 | 11 | func main() { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /go/1.9/syncMap.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "sync" 6 | ) 7 | 8 | var codisManager sync.Map 9 | 10 | func main() { 11 | fmt.Printf("%#v\n", codisManager) 12 | codisManager.Store("abc", "1") 13 | res, err := codisManager.Load("abc") 14 | fmt.Println(res, err) 15 | } 16 | -------------------------------------------------------------------------------- /go/algorithm/leetcode/1/1_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "testing" 4 | 5 | func BenchmarkSum1(b *testing.B) { 6 | for i := 0; i < b.N; i++ { 7 | test1() 8 | } 9 | } 10 | 11 | func BenchmarkSum2(b *testing.B) { 12 | for i := 0; i < b.N; i++ { 13 | test2() 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /go/algorithm/leetcode/27.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | fmt.Println(removeElement([]int{3, 2, 2, 3}, 3)) 7 | } 8 | 9 | func removeElement(nums []int, val int) int { 10 | var idx = 0 11 | for i := 0; i < len(nums); i++ { 12 | if nums[i] != val { 13 | nums[idx] = nums[i] 14 | idx++ 15 | } 16 | } 17 | 18 | return idx 19 | } 20 | -------------------------------------------------------------------------------- /go/algorithm/leetcode/344.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func main() { 4 | } 5 | 6 | func reverseString(s string) string { 7 | var res []byte 8 | 9 | for i := len(s) - 1; i >= 0; i-- { 10 | res = append(res, s[i]) 11 | } 12 | 13 | return string(res) 14 | } 15 | -------------------------------------------------------------------------------- /go/algorithm/leetcode/387.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func main() { 4 | firstUniqChar("abcdabc") 5 | } 6 | 7 | func firstUniqChar(s string) int { 8 | m := make(map[byte]int) 9 | for i := 0; i < len(s); i++ { 10 | m[s[i]]++ 11 | } 12 | 13 | for i := 0; i < len(s); i++ { 14 | if m[s[i]] == 1 { 15 | return i 16 | } 17 | } 18 | return -1 19 | } 20 | -------------------------------------------------------------------------------- /go/algorithm/leetcode/561.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "sort" 6 | ) 7 | 8 | func main() { 9 | fmt.Println(arrayPairSum([]int{1, 4, 3, 2})) 10 | } 11 | 12 | func arrayPairSum(nums []int) int { 13 | sort.Ints(nums) 14 | l := len(nums) 15 | sum := 0 16 | for i := 0; i < l; i++ { 17 | if i%2 == 0 { 18 | sum += nums[i] 19 | } 20 | } 21 | return sum 22 | } 23 | -------------------------------------------------------------------------------- /go/array/array2.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | var a = [10]int{1, 3, 4} 7 | var b = a[2:4:5] 8 | fmt.Println(b) 9 | } 10 | -------------------------------------------------------------------------------- /go/asm/basic_math_ops/math.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func add(a, b int) int 6 | 7 | func sub(a, b int) int 8 | 9 | func mul(a, b int) int 10 | 11 | //func div(a, b int) int 12 | 13 | func main() { 14 | fmt.Println(add(10, 11)) 15 | fmt.Println(sub(99, 15)) 16 | fmt.Println(mul(11, 12)) 17 | } 18 | -------------------------------------------------------------------------------- /go/asm/control_flow/m.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import _ "runtime" 4 | 5 | func main() 6 | -------------------------------------------------------------------------------- /go/asm/func_call/call.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import _ "strconv" 4 | 5 | func callOther() string 6 | 7 | func main() { 8 | x := callOther() 9 | println(x, len(x)) 10 | } 11 | -------------------------------------------------------------------------------- /go/asm/func_call/call.s: -------------------------------------------------------------------------------- 1 | #include "textflag.h" 2 | 3 | // func callOther() string 4 | TEXT ·callOther(SB), NOSPLIT, $24-16 5 | MOVQ $323232323, (SP) 6 | CALL strconv·Itoa(SB) 7 | MOVQ 8(SP), AX 8 | MOVQ 16(SP), BX 9 | MOVQ AX, ret+0(FP) 10 | MOVQ BX, ret+8(FP) 11 | RET 12 | -------------------------------------------------------------------------------- /go/asm/func_call/readme.md: -------------------------------------------------------------------------------- 1 | 2 | Call function in other packages by assembly. 3 | -------------------------------------------------------------------------------- /go/asm/global/global.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func output() (int, float64, int) 8 | func output2() (int, float64, int) 9 | 10 | func main() { 11 | a, b, c := output() 12 | fmt.Println(a, b, c) 13 | a, b, c =output2() 14 | fmt.Println(a, b, c) 15 | } 16 | -------------------------------------------------------------------------------- /go/asm/goid/go_tls.h: -------------------------------------------------------------------------------- 1 | #ifdef GOARCH_arm 2 | #define LR R14 3 | #endif 4 | 5 | #ifdef GOARCH_amd64 6 | #define get_tls(r) MOVQ TLS, r 7 | #define g(r) 0(r)(TLS*1) 8 | #endif 9 | 10 | #ifdef GOARCH_amd64p32 11 | #define get_tls(r) MOVL TLS, r 12 | #define g(r) 0(r)(TLS*1) 13 | #endif 14 | 15 | #ifdef GOARCH_386 16 | #define get_tls(r) MOVL TLS, r 17 | #define g(r) 0(r)(TLS*1) 18 | #endif 19 | 20 | -------------------------------------------------------------------------------- /go/asm/goid/goid.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "time" 6 | ) 7 | 8 | func getg() uint64 9 | 10 | var offset = map[string]int{} 11 | 12 | func main() { 13 | g := getg() 14 | fmt.Println(g) 15 | go func() { 16 | g := getg() 17 | fmt.Println(g) 18 | }() 19 | time.Sleep(time.Second) 20 | } 21 | -------------------------------------------------------------------------------- /go/asm/goid/goid_amd64.s: -------------------------------------------------------------------------------- 1 | #include "textflag.h" 2 | #include "go_tls.h" 3 | 4 | TEXT ·getg(SB), NOSPLIT, $0-8 5 | get_tls(CX) 6 | MOVQ g(CX), AX 7 | LEAQ 152(AX), BX // this is the offset 8 | MOVQ (BX), DX 9 | MOVQ DX, ret+0(FP) 10 | RET 11 | -------------------------------------------------------------------------------- /go/asm/hardware_or_virtual/where.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func where() (int, int, int, int) 6 | 7 | func main() { 8 | a, b, c, d := where() 9 | fmt.Println(a, b, c, d) 10 | } 11 | -------------------------------------------------------------------------------- /go/asm/hardware_or_virtual/where.s: -------------------------------------------------------------------------------- 1 | #include "textflag.h" 2 | 3 | TEXT ·where(SB), NOSPLIT, $8-32 4 | // MOVQ FP, AX 5 | MOVQ -8(SP), AX // this is hardwhere SP 6 | MOVQ x-8(SP), BX // this is the virtual register SP 7 | MOVQ 8(SP), DX 8 | MOVQ x+8(SP), CX 9 | MOVQ AX, ret+0(FP) 10 | MOVQ BX, ret+8(FP) 11 | MOVQ DX, ret+16(FP) 12 | MOVQ CX, ret+24(FP) 13 | RET 14 | -------------------------------------------------------------------------------- /go/asm/is_frame_pointer_on_stack_value_equal_to_directive_FP/global.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func output(int) (int, int) 8 | 9 | func main() { 10 | a, b := output(987654321) 11 | fmt.Println(a, b) 12 | } 13 | -------------------------------------------------------------------------------- /go/asm/is_frame_pointer_on_stack_value_equal_to_directive_FP/global.s: -------------------------------------------------------------------------------- 1 | #include "textflag.h" 2 | 3 | 4 | // func output(int) (int, int) 5 | TEXT ·output(SB),$0-24 6 | MOVQ arg0+0(FP), AX 7 | MOVQ AX, ret1+8(FP) 8 | MOVQ argx+0(SP), BX 9 | MOVQ (BX), AX 10 | MOVQ AX, ret2+16(FP) 11 | RET 12 | 13 | -------------------------------------------------------------------------------- /go/asm/leaq_test/a.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func run() int 4 | func main() { 5 | println(run()) 6 | } 7 | -------------------------------------------------------------------------------- /go/asm/local_var.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | // 注意观察这个函数的 args 和 locals 6 | // 以及生成的汇编的 $x-y 之间的关系 7 | func test(x []int) int { 8 | var a = 1 9 | var b = struct{ X int }{X: 93} 10 | fmt.Println(b) 11 | return a + b.X 12 | } 13 | 14 | func main() { 15 | } 16 | -------------------------------------------------------------------------------- /go/asm/refer_to_global_var_in_go_file/a.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | var a = 999 4 | 5 | func get() int 6 | 7 | func main() { 8 | println(get()) 9 | } 10 | -------------------------------------------------------------------------------- /go/asm/refer_to_global_var_in_go_file/a.s: -------------------------------------------------------------------------------- 1 | #include "textflag.h" 2 | 3 | TEXT ·get(SB), NOSPLIT, $0-8 4 | MOVQ ·a(SB), AX 5 | MOVQ AX, ret+0(FP) 6 | RET 7 | -------------------------------------------------------------------------------- /go/asm/registers_test/r.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func output() (int, int, int, int, int, int, int, int, int, int, int, int, int, int) 6 | 7 | func main() { 8 | a, b, c, d, e, f, g, h, i, j, k, l, m, n := output() 9 | fmt.Println(a, b, c, d, e, f, g, h, i, j, k, l, m, n) 10 | } 11 | -------------------------------------------------------------------------------- /go/asm/relative_pos_of_FP_and_SP/global.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func output(int) (int, int, int) 8 | func output2(int) (int, int, int) 9 | 10 | func main() { 11 | a, b, c := output(987654321) 12 | fmt.Println(a, b, c) 13 | a, b, c = output2(98765) 14 | fmt.Println(a, b, c) 15 | } 16 | -------------------------------------------------------------------------------- /go/asm/what_is_struct_in_asm/t.s: -------------------------------------------------------------------------------- 1 | #include "textflag.h" 2 | 3 | TEXT ·readStruct(SB), NOSPLIT, $0-64 4 | MOVQ arg0+0(FP), AX 5 | MOVQ AX, ret0+32(FP) 6 | MOVQ arg1+8(FP), AX 7 | MOVQ AX, ret1+40(FP) 8 | MOVQ arg2+16(FP), AX 9 | MOVQ AX, ret2+48(FP) 10 | MOVQ arg3+24(FP), AX 11 | MOVQ AX, ret3+56(FP) 12 | RET 13 | -------------------------------------------------------------------------------- /go/asm/where_is_fp_sp/where.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func where(a int, b int) (int, int) 6 | 7 | func main() { 8 | a, b := where(1, 2) 9 | fmt.Println(a, b) 10 | } 11 | -------------------------------------------------------------------------------- /go/asm/where_is_fp_sp/where.s: -------------------------------------------------------------------------------- 1 | #include "textflag.h" 2 | 3 | TEXT ·where(SB), NOSPLIT, $8-32 4 | // MOVQ FP, AX 5 | MOVQ -8(SP), AX // this is hardwhere SP 6 | MOVQ x-8(SP), BX // this is the virtual register SP 7 | MOVQ AX, ret+16(FP) 8 | MOVQ BX, ret+24(FP) 9 | RET 10 | 11 | -------------------------------------------------------------------------------- /go/assert/assert.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "encoding/json" 4 | import "fmt" 5 | 6 | func main() { 7 | a := `{"a" : {"b" : 1}}` 8 | var b map[string](map[string]interface{}) 9 | json.Unmarshal([]byte(a), &b) 10 | // var bb interface{} 11 | //json.Unmarshal([]byte(a), &bb) 12 | fmt.Println(b) 13 | fmt.Println(b["a"]["b"]) 14 | // var c = bb.(map[string](map[string]interface{})) 15 | // 这样做断言是不行的 16 | } 17 | -------------------------------------------------------------------------------- /go/assert/bench/assert_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "testing" 4 | 5 | func BenchmarkAssert(b *testing.B) { 6 | for i := 0; i < b.N; i++ { 7 | asx() 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /go/ast/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | // Place your settings in this file to overwrite default and user settings. 2 | { 3 | } -------------------------------------------------------------------------------- /go/ast/example.go: -------------------------------------------------------------------------------- 1 | package lp 2 | 3 | type person struct { 4 | age, aaa int `json:"age" form:"age"` 5 | name int `json:"name" form:"name"` 6 | info struct { 7 | detail int `json:"detail"` 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /go/ast/example.go.bak2: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | // for api @post @/user/create 4 | type createAccountRequest struct { 5 | Age int `form:"age" validation:"gte=18"` 6 | Name string `form:"name" validation:"length>0"` 7 | } 8 | -------------------------------------------------------------------------------- /go/ast/example.go.bakk: -------------------------------------------------------------------------------- 1 | package lp 2 | 3 | var a = 1 4 | 5 | const a = 1 6 | 7 | type p struct { 8 | } 9 | 10 | func main() { 11 | } 12 | -------------------------------------------------------------------------------- /go/ast/example2.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | // Person is 4 | type Person struct { 5 | age int `json:"age"` //ffff 6 | } 7 | 8 | func main() { 9 | 10 | var i int 11 | for { 12 | if true { 13 | i++ 14 | } else { 15 | i-- 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /go/atomic/uber_atomic.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | 6 | atomicex "go.uber.org/atomic" 7 | ) 8 | 9 | func main() { 10 | var a atomicex.Uint32 11 | fmt.Println(a.Load()) 12 | a.Store(23) 13 | fmt.Println(a.Load()) 14 | } 15 | -------------------------------------------------------------------------------- /go/atomic_bench/atomic.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "sync/atomic" 4 | 5 | var a int64 6 | 7 | func atomicStore(i int) { 8 | atomic.StoreInt64(&a, int64(i)) 9 | } -------------------------------------------------------------------------------- /go/atomic_bench/atomic_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "testing" 4 | 5 | func BenchmarkAtomic(b * testing.B) { 6 | b.SetParallelism(100) 7 | b.RunParallel(func(pb *testing.PB) { 8 | for pb.Next() { 9 | atomicStore(0) 10 | } 11 | }) 12 | } 13 | -------------------------------------------------------------------------------- /go/badcode/badcode.go: -------------------------------------------------------------------------------- 1 | if a { 2 | } else { 3 | if b { 4 | if c { 5 | } else { 6 | if d { 7 | } else { 8 | if e { 9 | } else { 10 | } 11 | } 12 | } 13 | } else { 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /go/beanstalkDemo/producer.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "time" 7 | 8 | "github.com/kr/beanstalk" 9 | ) 10 | 11 | func main() { 12 | c, err := beanstalk.Dial("tcp", "127.0.0.1:11300") 13 | if err != nil { 14 | fmt.Println("beanstakd not started") 15 | os.Exit(1) 16 | } 17 | id, err := c.Put([]byte("hello"), 1, 0, 120*time.Second) 18 | fmt.Println(id, err) 19 | } 20 | -------------------------------------------------------------------------------- /go/black_magic/a.s: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cch123/test/8a9d3dd4fbd3eecceaf4d77eb6cb56ca4e1528b9/go/black_magic/a.s -------------------------------------------------------------------------------- /go/black_magic/linkname.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | _ "runtime" 5 | _ "time" 6 | _ "unsafe" 7 | ) 8 | 9 | //go:linkname throw runtime.throw 10 | func throw(s string) 11 | 12 | //go:nosplit 应该是没啥用 13 | 14 | func main() { 15 | throw("abc") 16 | 17 | // cannot reach here 18 | println("ooo") 19 | } 20 | -------------------------------------------------------------------------------- /go/broadcast/src/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "broadcast" 5 | "fmt" 6 | ) 7 | 8 | var b = broadcast.NewBroadcaster() 9 | 10 | func main() { 11 | //b.Write("abc") 12 | r := b.Listen() 13 | b.Write("a") 14 | b.Write("b") 15 | b.Write("c") 16 | b.Write("d") 17 | fmt.Println(r.Read()) 18 | fmt.Println(r.Read()) 19 | fmt.Println(r.Read()) 20 | fmt.Println(r.Read()) 21 | fmt.Println(r) 22 | } 23 | -------------------------------------------------------------------------------- /go/buffer_chain/buf_test.go: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cch123/test/8a9d3dd4fbd3eecceaf4d77eb6cb56ca4e1528b9/go/buffer_chain/buf_test.go -------------------------------------------------------------------------------- /go/builtin/readme.md: -------------------------------------------------------------------------------- 1 | go run -gcflags "-N -l" xxx.go -------------------------------------------------------------------------------- /go/builtin/slice.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func p(s []int) { 4 | panic(1) 5 | } 6 | 7 | func main() { 8 | var s = []int{1, 2, 3} 9 | p(s) 10 | } 11 | -------------------------------------------------------------------------------- /go/builtin/str.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func p(s string) { 4 | panic(1) 5 | } 6 | 7 | func main() { 8 | var s = "hello" 9 | p(s) 10 | } 11 | -------------------------------------------------------------------------------- /go/channel/channelLen.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func main() { 4 | ch := make(chan int, 100) 5 | ch <- 1 6 | ch <- 1 7 | for i := 0; i < 100; i++ { 8 | 9 | go func() { 10 | <-ch 11 | }() 12 | } 13 | ch <- 1 14 | ch <- 1 15 | println(len(ch)) 16 | println(cap(ch)) 17 | <-ch 18 | println(len(ch)) 19 | println(cap(ch)) 20 | } 21 | -------------------------------------------------------------------------------- /go/channel/writeToClosedChannel.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func main() { 4 | var a = make(chan int, 4) 5 | close(a) 6 | // 直接panic,思考一下why 7 | a <- 4 8 | } 9 | -------------------------------------------------------------------------------- /go/circular_dependency/a/a.go: -------------------------------------------------------------------------------- 1 | package a 2 | 3 | import "../b" 4 | 5 | func Test() { 6 | b.FormatB() 7 | println("test a") 8 | } 9 | 10 | func FormatA() { 11 | println("format a") 12 | } 13 | -------------------------------------------------------------------------------- /go/circular_dependency/b/b.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "../a" 4 | 5 | func Test() { 6 | a.FormatA() 7 | println("test b") 8 | } 9 | 10 | func FormatB() { 11 | println("format b") 12 | } 13 | -------------------------------------------------------------------------------- /go/circular_dependency/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "./a" 4 | 5 | func main() { 6 | a.Test() 7 | } 8 | -------------------------------------------------------------------------------- /go/closure/closure.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func main() { 4 | var x = func() func() int { 5 | var idx = 0 6 | return func() int { 7 | idx++ 8 | return idx 9 | } 10 | } 11 | var z = x() 12 | println(z()) 13 | println(z()) 14 | println(z()) 15 | y := x() 16 | println(y()) 17 | println(y()) 18 | println(y()) 19 | println(y()) 20 | } 21 | -------------------------------------------------------------------------------- /go/closure/closure2.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func main() { 4 | var x = func() func() int { 5 | var idx = 0 6 | return func() int { 7 | idx++ 8 | return idx 9 | } 10 | }() 11 | var z = x 12 | println(z()) 13 | println(z()) 14 | println(z()) 15 | y := x 16 | println(y()) 17 | println(y()) 18 | println(y()) 19 | println(y()) 20 | } 21 | -------------------------------------------------------------------------------- /go/comparable/str.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func main() { 4 | var a string 5 | a = "abc" 6 | a = a + "def" 7 | } 8 | -------------------------------------------------------------------------------- /go/concurrent/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cch123/test/8a9d3dd4fbd3eecceaf4d77eb6cb56ca4e1528b9/go/concurrent/readme.md -------------------------------------------------------------------------------- /go/concurrent_map_write_iter/readme.md: -------------------------------------------------------------------------------- 1 | https://github.com/golang/go/issues/26703 2 | 3 | 不打开 -race 的选项的话,有可能 race 的栈显示不全,如两个 goroutine 发生 race,而实际上只显示其中的一个。 4 | 5 | 但线上显然是没法打开的。 6 | 7 | 可以在压力测试中开 -race 进行单独的并发测试 8 | 9 | -------------------------------------------------------------------------------- /go/crawler/z.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "net/url" 6 | ) 7 | 8 | func main() { 9 | 10 | u, err := url.Parse("http://www.abc.com/afdsaf") 11 | fmt.Println(u.Hostname(), err) 12 | } 13 | -------------------------------------------------------------------------------- /go/cryptoBench/md4/md4.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "golang.org/x/crypto/md4" 4 | 5 | var hash []byte 6 | 7 | func test() { 8 | 9 | s1 := "Hello, MD4 test text" 10 | ctx := md4.New() 11 | ctx.Write([]byte(s1)) 12 | hash = ctx.Sum(nil) 13 | 14 | } 15 | -------------------------------------------------------------------------------- /go/cryptoBench/md4/md4_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "testing" 4 | 5 | func BenchmarkUUID(b *testing.B) { 6 | for i := 0; i < b.N; i++ { 7 | test() 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /go/cryptoBench/sha1/sha1.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | //Go 在多个 crypto/* 包中实现了一系列散列函数。 4 | import "crypto/sha1" 5 | 6 | var bs []byte 7 | 8 | func test() { 9 | s := "Hello, MD4 test text" 10 | h := sha1.New() 11 | h.Write([]byte(s)) 12 | bs = h.Sum(nil) 13 | } 14 | -------------------------------------------------------------------------------- /go/cryptoBench/sha1/sha1_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "testing" 4 | 5 | func BenchmarkSHA1(t *testing.B) { 6 | for i := 0; i < t.N; i++ { 7 | test() 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /go/dataStructs/annoymous_struct.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | var str = struct { 7 | settings struct { 8 | name string 9 | } 10 | }{ 11 | settings: struct{ name string }{ 12 | name: "fuck", 13 | }, 14 | } 15 | fmt.Printf("%+v\n", str) 16 | } 17 | -------------------------------------------------------------------------------- /go/dataStructs/arrtest.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func main() { 4 | var arr = []int{1, 2, 3} 5 | for k, v := range arr { 6 | println(k, v) 7 | } 8 | arr = append(arr, 4, 5, 6) 9 | } 10 | -------------------------------------------------------------------------------- /go/dataStructs/complextest.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | var c complex64 = 5i 7 | fmt.Println(c * c) 8 | } 9 | -------------------------------------------------------------------------------- /go/dataStructs/listtest.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "container/list" 4 | import "fmt" 5 | 6 | func main() { 7 | l := list.New() 8 | l.PushBack(1) 9 | l.PushBack(2) 10 | l.PushBack(3) 11 | l.PushBack(4) 12 | for elem := l.Front(); elem != nil; elem = elem.Next() { 13 | fmt.Println(elem.Value) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /go/dataStructs/maptest.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | var m map[string]int 7 | //下面这句是必须的 8 | m = make(map[string]int) 9 | m["one"] = 1 10 | m["two"] = 2 11 | fmt.Printf("%+v", m) 12 | delete(m, "x") 13 | delete(m, "one") 14 | 15 | ma := make(map[string]int) 16 | ma["x"] = 1 17 | fmt.Printf("%+v", ma) 18 | } 19 | -------------------------------------------------------------------------------- /go/dataStructs/typeEqualTest/a/sss.go: -------------------------------------------------------------------------------- 1 | package a 2 | 3 | type A int 4 | -------------------------------------------------------------------------------- /go/deepl/md.md: -------------------------------------------------------------------------------- 1 | # abc 2 | 3 | sdfadf 4 | 5 | -------------------------------------------------------------------------------- /go/dependency-experiment/func_based/test_funcs.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func testGetUserID(userID int) int64 { 4 | return 1 5 | } 6 | 7 | func testPushMSG(userID int64) error { 8 | println("push to user(online)", userID) 9 | return nil 10 | } 11 | 12 | func testGetLimited(driverID int64) bool { 13 | return false 14 | } 15 | 16 | func testGetWhiteList(date string) map[int]int64 { 17 | return nil 18 | } 19 | -------------------------------------------------------------------------------- /go/dependency-experiment/injection_based/codis.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type codisService struct { 6 | connOptions []string 7 | } 8 | 9 | func initCodis() (*codisService, error) { 10 | fmt.Println("init codis") 11 | return &codisService{ 12 | connOptions: []string{"yyy", "zzz"}, 13 | }, nil 14 | } 15 | -------------------------------------------------------------------------------- /go/dependency-experiment/interface_based/order_service.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | type orderService interface{} 4 | -------------------------------------------------------------------------------- /go/dependency-experiment/interface_based/user_service.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | type userService interface { 4 | UserID(phone string) int64 5 | } 6 | 7 | type onlineUserService struct{} 8 | 9 | func (ous onlineUserService) UserID(phone string) int64 { 10 | return 1 11 | } 12 | 13 | type testUserService struct{} 14 | 15 | func (tus testUserService) UserID(phone string) int64 { 16 | return 2 17 | } 18 | -------------------------------------------------------------------------------- /go/dependency-experiment/nested_struct_based/order_service.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | type orderService struct{} 4 | -------------------------------------------------------------------------------- /go/dependency-experiment/nested_struct_based/price_service.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func onlineGetPrice(orderID int) float64 { 4 | return 0 5 | } 6 | 7 | func testGetPrice(orderID int) float64 { 8 | return 0.11 9 | } 10 | -------------------------------------------------------------------------------- /go/dependency-experiment/nested_struct_based/user_service.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | type userService struct { 4 | UserID func(phone string) int64 5 | } 6 | 7 | type onlineUserService struct{} 8 | 9 | func (ous onlineUserService) UserID(phone string) int64 { 10 | return 1 11 | } 12 | 13 | type testUserService struct{} 14 | 15 | func (tus testUserService) UserID(phone string) int64 { 16 | return 2 17 | } 18 | -------------------------------------------------------------------------------- /go/double_buffer/readme.md: -------------------------------------------------------------------------------- 1 | # Overview 2 | 3 | -------------------------------------------------------------------------------- /go/elasticsearch/elastic.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func main() { 4 | } 5 | -------------------------------------------------------------------------------- /go/elasticsearch/elasticsql_example.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | 7 | "github.com/cch123/elasticsql" 8 | ) 9 | 10 | func main() { 11 | if len(os.Args) != 2 { 12 | fmt.Println("参数数目错误") 13 | os.Exit(1) 14 | } 15 | var sql = os.Args[1] 16 | dsl, esType, err := elasticsql.Convert(sql) 17 | fmt.Println(dsl) 18 | fmt.Println(esType) 19 | fmt.Println(err) 20 | } 21 | -------------------------------------------------------------------------------- /go/encrypt/readme.md: -------------------------------------------------------------------------------- 1 | https://cyberspy.io/articles/crypto101/ 2 | -------------------------------------------------------------------------------- /go/epoll/easygo/go.mod: -------------------------------------------------------------------------------- 1 | module easygo 2 | 3 | go 1.14 4 | 5 | require ( 6 | github.com/mailru/easygo v0.0.0-20190618140210-3c14a0dc985f 7 | golang.org/x/sys v0.1.0 // indirect 8 | ) 9 | -------------------------------------------------------------------------------- /go/epoll/easygo/go.sum: -------------------------------------------------------------------------------- 1 | github.com/mailru/easygo v0.0.0-20190618140210-3c14a0dc985f h1:4+gHs0jJFJ06bfN8PshnM6cHcxGjRUVRLo5jndDiKRQ= 2 | github.com/mailru/easygo v0.0.0-20190618140210-3c14a0dc985f/go.mod h1:tHCZHV8b2A90ObojrEAzY0Lb03gxUxjDHr5IJyAh4ew= 3 | golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U= 4 | golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 5 | -------------------------------------------------------------------------------- /go/epoll/evio/evio.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/tidwall/evio" 4 | 5 | func main() { 6 | var events evio.Events 7 | events.Data = func(c evio.Conn, in []byte) (out []byte, action evio.Action) { 8 | // out 其实就是写出的数据,这里 out = in,实现的其实是一个 echo server 9 | out = in 10 | return 11 | } 12 | if err := evio.Serve(events, "tcp://localhost:5000"); err != nil { 13 | panic(err) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /go/errcheck/errcheck.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | ) 7 | 8 | func main() { 9 | // 这种场景可以用 gas/gometalinter 检查出来 10 | req, _ := http.NewRequest("GET", "http://www.baidu.com", nil) 11 | fmt.Println(req) 12 | } 13 | -------------------------------------------------------------------------------- /go/error/err_print.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type P struct { 6 | Age int 7 | Name int 8 | } 9 | 10 | func (p P) Error() string { 11 | return "fuck" 12 | } 13 | 14 | func main() { 15 | var err P 16 | fmt.Printf("%#v\n", err) // main.P{Age:0, Name:0} 17 | fmt.Printf("%v\n", err) // fuck 18 | fmt.Printf("%s\n", err) // fuck 19 | } 20 | 21 | -------------------------------------------------------------------------------- /go/error/internal_err.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "errors" 5 | "fmt" 6 | ) 7 | 8 | func main() { 9 | err := errors.New("oh no") 10 | fmt.Println(err) 11 | fmt.Printf("%+v", err) 12 | } 13 | -------------------------------------------------------------------------------- /go/error/juju_err/juju_err.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func main() { 4 | } 5 | -------------------------------------------------------------------------------- /go/error/pkg_err/printf.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/pkg/errors" 7 | ) 8 | 9 | func main() { 10 | err := errors.New("whoops") 11 | fmt.Println(err) 12 | fmt.Printf("%+v", err) 13 | } 14 | -------------------------------------------------------------------------------- /go/escape_analysis/a.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func t(a *int) { 8 | } 9 | 10 | func main() { 11 | var a [1]int 12 | c := a[:] 13 | fmt.Println(c) 14 | var b int 15 | t(&b) 16 | } 17 | -------------------------------------------------------------------------------- /go/escape_analysis/a.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cch123/test/8a9d3dd4fbd3eecceaf4d77eb6cb56ca4e1528b9/go/escape_analysis/a.o -------------------------------------------------------------------------------- /go/expand/channel.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func testChan(ch chan int) { 6 | ch = make(chan int, 10) 7 | fmt.Println("ch == nil : ", ch == nil) 8 | } 9 | func main() { 10 | var ch chan int 11 | testChan(ch) 12 | fmt.Println("ch == nil : ", ch == nil) 13 | } 14 | -------------------------------------------------------------------------------- /go/expand/map.go: -------------------------------------------------------------------------------- 1 | // map 即使在数组内部扩容了,也不会生成新的局部变量 2 | package main 3 | 4 | import "fmt" 5 | 6 | func testMap(m map[int]int) { 7 | for i := 0; i < 1000; i++ { 8 | m[i] = i 9 | } 10 | } 11 | 12 | func main() { 13 | var m = map[int]int{} 14 | testMap(m) 15 | fmt.Println(m) 16 | } 17 | -------------------------------------------------------------------------------- /go/expand/readme.md: -------------------------------------------------------------------------------- 1 | # 内置结构扩容 2 | 3 | 需要注意的是,虽然很多人说 slice 是引用传递,但这种说法是不精确的。 4 | 5 | 如果传入函数的 slice 在函数内发生了扩容,那么扩容之后的 slice 就是该函数中新的局部 slice 了,任何修改不会影响到 caller 的 slice。 6 | 7 | 因为本质上传入 callee 的是 caller 中 slice 的地址值,这个地址值还是一个副本,只是值与 caller 中的 slice 的一样。但一旦存储该地址值本身的变量发生了变化,那就和原来没什么关系了。 8 | -------------------------------------------------------------------------------- /go/expand/slice.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func testSlice(sl []int) { 6 | for i := 0; i < 1000; i++ { 7 | sl = append(sl, i) 8 | } 9 | fmt.Println(sl) 10 | } 11 | 12 | func main() { 13 | var a = []int{} 14 | testSlice(a) 15 | fmt.Println(a) 16 | } 17 | -------------------------------------------------------------------------------- /go/file/filetest.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | ) 7 | 8 | func exit_this(f os.File) { 9 | f.Close() 10 | println("file closed") 11 | } 12 | 13 | func main() { 14 | f, _ := os.Open("./arrtest.go") 15 | fmt.Printf("%+v\n", f) 16 | fmt.Printf("%+v\n", *f) 17 | defer exit_this(*f) 18 | } 19 | -------------------------------------------------------------------------------- /go/file/get_file_list.go: -------------------------------------------------------------------------------- 1 | package main 2 | import "io/ioutil" 3 | 4 | import "fmt" 5 | func main() { 6 | //ioutil.ReadFile(filenamoe) 7 | filePathList, _:=ioutil.ReadDir("./") 8 | for _, p := range filePathList { 9 | fmt.Println(p.Name()) 10 | } 11 | } -------------------------------------------------------------------------------- /go/file/list_all_file.go: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cch123/test/8a9d3dd4fbd3eecceaf4d77eb6cb56ca4e1528b9/go/file/list_all_file.go -------------------------------------------------------------------------------- /go/file/merged: -------------------------------------------------------------------------------- 1 | {"from" : 0,"size" : 15,"query" : {"bool": {"must" : [{"term" : {"phone" : "1866666666"}}]}},"sort" : [{"id" : "desc"}],"highlight" : {}} 2 | -------------------------------------------------------------------------------- /go/file/read_all.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "io/ioutil" 6 | "strings" 7 | ) 8 | 9 | func main() { 10 | contentBytes, err := ioutil.ReadFile("./list.txt") 11 | if err != nil { 12 | println(err) 13 | return 14 | } 15 | lines := strings.Split(string(contentBytes), "\n") 16 | for _, l := range lines { 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /go/flag/parse.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | ) 7 | 8 | var a = flag.String("c", "", "flag a ") 9 | 10 | func main() { 11 | // 不parse不出结果 12 | flag.Parse() 13 | fmt.Println(*a) 14 | } 15 | -------------------------------------------------------------------------------- /go/flowControl/addaddtest.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func main() { 4 | var x = 1 5 | x++ 6 | println(x) 7 | //var y = x++ syntax error! 8 | //println(y++) syntax error! 9 | } 10 | -------------------------------------------------------------------------------- /go/flowControl/defertest.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func main() { 4 | for i := 0; i < 5; i++ { 5 | defer println(i) 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /go/flowControl/for.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | v := []int{1, 2, 3} 7 | for i := range v { 8 | v = append(v, i) 9 | } 10 | fmt.Println(v) 11 | /* 12 | it is the same with len = len(v) 13 | for i:=0;i 0 { 14 | } 15 | 16 | fmt.Println(i) 17 | } 18 | -------------------------------------------------------------------------------- /go/goevaluate/m.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "reflect" 6 | 7 | "github.com/Knetic/govaluate" 8 | ) 9 | 10 | func main() { 11 | expr, err := govaluate.NewEvaluableExpression("1+2+3") 12 | v, err := expr.Eval(nil) 13 | fmt.Println(reflect.TypeOf(v), v, err) 14 | } 15 | -------------------------------------------------------------------------------- /go/gomod/go.mod: -------------------------------------------------------------------------------- 1 | module xargin.com/test 2 | 3 | go 1.13 4 | 5 | require github.com/cch123/gomodexp v0.0.0-20200417090903-1acabdcf6c87 6 | -------------------------------------------------------------------------------- /go/gomod/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/cch123/gomodexp/esutil" 4 | 5 | func main() { 6 | esutil.OhES() 7 | } 8 | -------------------------------------------------------------------------------- /go/gomod/vendor/github.com/cch123/elasticsql/.gitignore: -------------------------------------------------------------------------------- 1 | vendor 2 | -------------------------------------------------------------------------------- /go/gomod/vendor/github.com/cch123/elasticsql/glide.yaml: -------------------------------------------------------------------------------- 1 | package: github.com/cch123/elasticsql 2 | import: 3 | - package: github.com/xwb1989/sqlparser 4 | -------------------------------------------------------------------------------- /go/gomod/vendor/github.com/cch123/gomodexp/esutil/main.go: -------------------------------------------------------------------------------- 1 | package esutil 2 | 3 | import "fmt" 4 | import "github.com/cch123/elasticsql" 5 | 6 | func init() { 7 | fmt.Println("init function in etcdcli") 8 | } 9 | 10 | func OhES() { 11 | fmt.Println("OhETCD") 12 | elasticsql.Convert("select * from a") 13 | } 14 | -------------------------------------------------------------------------------- /go/gomod/vendor/github.com/xwb1989/sqlparser/.gitignore: -------------------------------------------------------------------------------- 1 | y.output 2 | -------------------------------------------------------------------------------- /go/gomod/vendor/github.com/xwb1989/sqlparser/CONTRIBUTORS.md: -------------------------------------------------------------------------------- 1 | This project is originally a fork of [https://github.com/youtube/vitess](https://github.com/youtube/vitess) 2 | Copyright Google Inc 3 | 4 | # Contributors 5 | Wenbin Xiao 2015 6 | Started this project and maintained it. 7 | 8 | Andrew Brampton 2017 9 | Merged in multiple upstream fixes/changes. -------------------------------------------------------------------------------- /go/gopacket/readme.md: -------------------------------------------------------------------------------- 1 | https://www.devdungeon.com/content/packet-capture-injection-and-analysis-gopacket 2 | 3 | loop 拿不到 link layer,需要再改改 4 | 5 | https://stackoverflow.com/questions/59985676/sending-udp-packets-to-127-0-0-1-with-gopacket 6 | -------------------------------------------------------------------------------- /go/gopsutil/.gitignore: -------------------------------------------------------------------------------- 1 | vendor 2 | -------------------------------------------------------------------------------- /go/gopsutil/go.mod: -------------------------------------------------------------------------------- 1 | module t 2 | 3 | go 1.13 4 | 5 | require ( 6 | github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect 7 | github.com/go-ole/go-ole v1.2.4 // indirect 8 | github.com/shirou/gopsutil v2.20.5+incompatible 9 | github.com/stretchr/testify v1.6.1 // indirect 10 | golang.org/x/sys v0.1.0 // indirect 11 | ) 12 | -------------------------------------------------------------------------------- /go/goroutine/channel.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func sum(arr []int, ch chan int) { 4 | sum := 0 5 | for _, v := range arr { 6 | sum += v 7 | } 8 | ch <- sum 9 | } 10 | 11 | func main() { 12 | var ch = make(chan int) 13 | var arr = [10]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 0} 14 | go sum(arr[0:len(arr)/2], ch) 15 | go sum(arr[len(arr)/2:], ch) 16 | var x, y = <-ch, <-ch 17 | println(x, y) 18 | } 19 | -------------------------------------------------------------------------------- /go/goroutine/channelmakeandchannelnotmake.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func main() { 4 | var a chan int 5 | var b = make(chan int) 6 | //注意,只声明不初始化的话,a的值是空,没法直接使用 7 | //go里的三种特殊数据结构都是需要初始化的 8 | println(a) 9 | println(b) 10 | a = make(chan int) 11 | println(a) 12 | } 13 | -------------------------------------------------------------------------------- /go/goroutine/chantest.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | import "time" 5 | 6 | func worker(done chan bool) { 7 | fmt.Print("working...") 8 | time.Sleep(time.Second) 9 | fmt.Println("done") 10 | done <- true 11 | } 12 | 13 | func main() { 14 | done := make(chan bool, 1) 15 | go worker(done) 16 | <-done 17 | } 18 | -------------------------------------------------------------------------------- /go/goroutine/goForPrint.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "runtime" 4 | import "time" 5 | 6 | func main() { 7 | 8 | runtime.GOMAXPROCS(1) 9 | for i := 0; i < 10; i++ { 10 | go println(i) 11 | } 12 | time.Sleep(2 * time.Second) 13 | } 14 | -------------------------------------------------------------------------------- /go/goroutine/goroutine.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "runtime" 5 | "time" 6 | ) 7 | 8 | func main() { 9 | runtime.GOMAXPROCS(1) 10 | //runtime.GOMAXPROCS(1) 11 | for i := 0; i < 10; i++ { 12 | go func(i int) { 13 | println(i) 14 | }(i) 15 | } 16 | time.Sleep(time.Second * 2) 17 | } 18 | -------------------------------------------------------------------------------- /go/goroutine/goroutinetest.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "runtime" 4 | 5 | func say(str string) { 6 | for i := 0; i < 5; i++ { 7 | runtime.Gosched() 8 | println(str) 9 | } 10 | } 11 | func main() { 12 | go say("hello") 13 | say("yess") 14 | } 15 | -------------------------------------------------------------------------------- /go/goroutine/nilfuncgo.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func main() { 4 | var a func() 5 | go a() 6 | } 7 | -------------------------------------------------------------------------------- /go/goyacc/prac/parse.y: -------------------------------------------------------------------------------- 1 | %{ 2 | package main 3 | import ( 4 | "fmt" 5 | "text/scanner" 6 | ) 7 | 8 | type Expression struct {} 9 | %} -------------------------------------------------------------------------------- /go/goyacc/readme.md: -------------------------------------------------------------------------------- 1 | https://zhuanlan.zhihu.com/p/34770765 2 | 3 | https://github.com/vitessio/vitess/blob/dbdb3a1d6c2075edac0e0f11b93a63668f6e4559/go/vt/sqlparser/sql.y 4 | -------------------------------------------------------------------------------- /go/grpc/hello.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package helloworld; 4 | // 服务端定义 5 | service Greeter { 6 | // 服务端返馈信息方法 7 | rpc SayHello (HelloRequest) returns (HelloReply) {} 8 | } 9 | 10 | // 包含用户名的请求信息 11 | message HelloRequest { 12 | string name = 1; 13 | } 14 | 15 | // 服务端响应信息 16 | message HelloReply { 17 | string message = 1; 18 | } 19 | -------------------------------------------------------------------------------- /go/grpc/readme.md: -------------------------------------------------------------------------------- 1 | brew install protoc-gen-go 2 | 3 | protoc --proto_path=./ --go_out=plugins=grpc:./ ./hello.proto 4 | -------------------------------------------------------------------------------- /go/hex/decode.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/hex" 5 | "fmt" 6 | ) 7 | 8 | func main() { 9 | res, err := hex.DecodeString("ff") 10 | fmt.Println(res, err) 11 | fmt.Println(string(res)) 12 | 13 | ch := 'a' 14 | fmt.Println(int(ch)) 15 | bytes := []byte{123, 123, 11, 23, 0, 23, 12} 16 | fmt.Println(string(bytes)) 17 | } 18 | -------------------------------------------------------------------------------- /go/html-to-markdown/go.mod: -------------------------------------------------------------------------------- 1 | module fu 2 | 3 | go 1.14 4 | 5 | require github.com/JohannesKaufmann/html-to-markdown v1.2.0 6 | -------------------------------------------------------------------------------- /go/http/handlerLeak.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "net/http" 4 | 5 | func main() { 6 | for { 7 | go func() { 8 | req, _ := http.NewRequest("GET", "www.baidu.com", nil) 9 | client := http.DefaultClient 10 | client.Do(req) 11 | // should be resp, _ := client.Do(req 12 | // defer resp.Body.Close 13 | }() 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /go/http/http2/readme.md: -------------------------------------------------------------------------------- 1 | ``` 2 | ~ ❯❯❯ curl -i https://localhost:9090 -k 3 | HTTP/2 200 4 | content-type: application/json 5 | content-length: 5 6 | date: Thu, 23 Apr 2020 07:40:12 GMT 7 | 8 | hello 9 | 10 | ``` 11 | -------------------------------------------------------------------------------- /go/http/httpclient.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "io/ioutil" 6 | "net/http" 7 | ) 8 | 9 | func main() { 10 | resp, err := http.Get("http://baidu.com") 11 | fmt.Println(resp) 12 | fmt.Println(err) 13 | bodyBytes, err := ioutil.ReadAll(resp.Body) 14 | fmt.Println(string(bodyBytes)) 15 | fmt.Println(err) 16 | } 17 | -------------------------------------------------------------------------------- /go/http/panic/readme.md: -------------------------------------------------------------------------------- 1 | 虽然 http 库里有对 handlerFunc 的 panic 进行处理, 2 | 3 | 但实际开发中,如果在 handler 中需要再启动 goroutine,那么新启动的 goroutine 中 panic 还是会导致程序挂掉的。 4 | -------------------------------------------------------------------------------- /go/import_cycle/break_cycle/action/act.go: -------------------------------------------------------------------------------- 1 | package action 2 | 3 | type ActionTarget interface { 4 | Do() int 5 | } 6 | -------------------------------------------------------------------------------- /go/import_cycle/break_cycle/character/cha.go: -------------------------------------------------------------------------------- 1 | package character 2 | 3 | type Character struct { 4 | Inventory []item.Item 5 | } 6 | 7 | // Do implement the interface ActionTarget 8 | func (c Character) Do() int { 9 | } 10 | -------------------------------------------------------------------------------- /go/import_cycle/break_cycle/item/item.go: -------------------------------------------------------------------------------- 1 | package item 2 | 3 | type Item struct { 4 | Name string 5 | Actions []action.Action 6 | } 7 | -------------------------------------------------------------------------------- /go/import_cycle/original/action/action.go: -------------------------------------------------------------------------------- 1 | // Package action provides ... 2 | package action 3 | 4 | type Action struct { 5 | Names []string 6 | Action func(character.Character) int 7 | } 8 | -------------------------------------------------------------------------------- /go/import_cycle/original/character/cha.go: -------------------------------------------------------------------------------- 1 | package character 2 | 3 | type Character struct { 4 | Inventory []item.Item 5 | } 6 | -------------------------------------------------------------------------------- /go/import_cycle/original/item/item.go: -------------------------------------------------------------------------------- 1 | package item 2 | 3 | type Item struct { 4 | Name string 5 | Actions []action.Action 6 | } 7 | -------------------------------------------------------------------------------- /go/interface/inter.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "reflect" 6 | ) 7 | 8 | type Person struct { 9 | name string 10 | } 11 | 12 | func (p Person) BB() { 13 | fmt.Println(p.name) 14 | } 15 | 16 | type Speaker interface { 17 | BB() 18 | } 19 | 20 | func main() { 21 | var alex interface{} = Person{"fuck"} 22 | var x = reflect.ValueOf(alex).Interface().(Speaker) 23 | x.BB() 24 | } 25 | -------------------------------------------------------------------------------- /go/interface/interfaceReflect.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "reflect" 6 | ) 7 | 8 | func main() { 9 | var val interface{} = int64(58) 10 | fmt.Println(reflect.TypeOf(val)) 11 | val = 50 12 | fmt.Println(reflect.TypeOf(val)) 13 | val = "abc" 14 | fmt.Println(reflect.TypeOf(val)) 15 | } 16 | -------------------------------------------------------------------------------- /go/interface/multi_instance.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | type Printer interface { 4 | Print() 5 | } 6 | 7 | type person struct{} 8 | 9 | func (p person) Print() {} 10 | 11 | type gogo struct{} 12 | 13 | func (g gogo) Print() {} 14 | 15 | func main() { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /go/interface/readme.md: -------------------------------------------------------------------------------- 1 | go build -gcflags "-N -l" xxx.go 2 | 3 | gdb xxx 4 | 5 | l=>列出代码 6 | 7 | b `line_number` 列出行号 8 | 9 | r 运行程序,在断点处会自动停止 10 | 11 | i locals 12 | -------------------------------------------------------------------------------- /go/interface_unmsarshal.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "reflect" 7 | ) 8 | 9 | var a struct { 10 | A interface{} `json:"a"` 11 | } 12 | 13 | func main() { 14 | jsonStr := `{"a" : false}` 15 | json.Unmarshal([]byte(jsonStr), &a) 16 | fmt.Println(a) 17 | fmt.Println(a.A == nil) 18 | fmt.Println(reflect.TypeOf(a.A)) 19 | fmt.Println(reflect.ValueOf(a.A)) 20 | } 21 | -------------------------------------------------------------------------------- /go/internal/copytest.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type person struct { 6 | age int 7 | } 8 | 9 | func (p person) printAge() { 10 | fmt.Printf("%p\n", &p) 11 | } 12 | 13 | func main() { 14 | p := person{age: 10} 15 | fmt.Printf("%p\n", &p) 16 | p.printAge() 17 | } 18 | -------------------------------------------------------------------------------- /go/internal/copytest2.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type integer int 6 | 7 | func (i integer) printAge() { 8 | fmt.Printf("%p\n", &i) 9 | } 10 | 11 | func main() { 12 | i := integer(1) 13 | fmt.Printf("%p\n", &i) 14 | i.printAge() 15 | } 16 | -------------------------------------------------------------------------------- /go/json/djsontest.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | //这个库似乎只支持未知json格式的解析 4 | //不支持decode到struct 5 | import ( 6 | "fmt" 7 | 8 | "github.com/a8m/djson" 9 | ) 10 | 11 | type Person struct { 12 | name string 13 | age int 14 | } 15 | 16 | func main() { 17 | //var p Person 18 | x, err := djson.Decode([]byte(`123`)) 19 | fmt.Println(x, err) 20 | fmt.Printf("%q", x) 21 | } 22 | -------------------------------------------------------------------------------- /go/json/ffjs.go: -------------------------------------------------------------------------------- 1 | package cch 2 | 3 | //ffjson这个是用已有的struct自动生成Marshal和Unmarshal的代码的库 4 | //必须得把代码放到GOPATH下才能正常运行。。 5 | //执行ffjson xxxxx.go,然后可以生成编解码代码 6 | 7 | type Person struct { 8 | name string 9 | age int 10 | } 11 | -------------------------------------------------------------------------------- /go/json/ffjsontest.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | type Person struct { 4 | name string 5 | age int 6 | } 7 | -------------------------------------------------------------------------------- /go/left_recursion_detect/main.go: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cch123/test/8a9d3dd4fbd3eecceaf4d77eb6cb56ca4e1528b9/go/left_recursion_detect/main.go -------------------------------------------------------------------------------- /go/line_feed.go: -------------------------------------------------------------------------------- 1 | // in nginx, it append a line feed to each log line 2 | //http://www.perlmonks.org/?node_id=264431 3 | package main 4 | 5 | func main() { 6 | var a = "\x0a" 7 | var b = "\n" 8 | println(a == b) 9 | println([]byte(b)[0]) 10 | } 11 | -------------------------------------------------------------------------------- /go/linux_processes/pidtest.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "os" 4 | 5 | func main() { 6 | println(os.Getpid()) 7 | } 8 | -------------------------------------------------------------------------------- /go/linux_processes/ppidtest.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "os" 4 | 5 | func main() { 6 | println(os.Getppid()) 7 | } 8 | -------------------------------------------------------------------------------- /go/lock/local_lock.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "sync" 5 | ) 6 | 7 | // 全局变量 8 | var counter int 9 | 10 | func main() { 11 | var wg sync.WaitGroup 12 | var l sync.Mutex 13 | for i := 0; i < 1000; i++ { 14 | wg.Add(1) 15 | go func() { 16 | defer wg.Done() 17 | l.Lock() 18 | counter++ 19 | l.Unlock() 20 | }() 21 | } 22 | 23 | wg.Wait() 24 | println(counter) 25 | } 26 | -------------------------------------------------------------------------------- /go/lock/redlock.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func main() { 4 | } 5 | -------------------------------------------------------------------------------- /go/map/isMapOrdered.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | 7 | var a = map[string]int{ 8 | "1": 1, 9 | "2": 2, 10 | } 11 | 12 | var counter int 13 | for counter < 100 { 14 | for key, _ := range a { 15 | fmt.Printf("%s ", key) 16 | } 17 | println() 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /go/map/range.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "time" 6 | ) 7 | 8 | func main() { 9 | m := map[string]string{ 10 | "a": "1", 11 | "b": "2", 12 | "c": "3", 13 | "d": "4", 14 | } 15 | 16 | // 会把所有的 k, v 输出出来 17 | for k, v := range m { 18 | fmt.Println(k, v) 19 | m = nil 20 | } 21 | 22 | time.Sleep(time.Hour) 23 | 24 | } 25 | -------------------------------------------------------------------------------- /go/map/readme.md: -------------------------------------------------------------------------------- 1 | res.txt 2 | 3 | 是 go tool compile -S range.go 的结果 4 | -------------------------------------------------------------------------------- /go/map/structmap.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | //map的key可以是string以外的值 6 | //所以也可以用来做指针和对应状态的记录 7 | //不过如果是和json相关的工作时,需要考虑到rfc的json定义里object的key只能是string 8 | //int类型做key的map会出错 9 | 10 | type Node struct { 11 | length int 12 | next *Node 13 | } 14 | 15 | func main() { 16 | var a = make(map[*Node]bool) 17 | n := Node{} 18 | a[&n] = true 19 | fmt.Println(a) 20 | } 21 | -------------------------------------------------------------------------------- /go/mapexpr/readme.md: -------------------------------------------------------------------------------- 1 | # Overview 2 | 3 | 支持在 map 数据类型上进行 bool 操作,输出为 true/false。 4 | 5 | # 现状 6 | 7 | WIP 8 | -------------------------------------------------------------------------------- /go/math/accurance.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | import "reflect" 5 | 6 | func main() { 7 | var a = 0.57 8 | var b = a * 100 9 | fmt.Println(reflect.TypeOf(a).Kind()) 10 | fmt.Println(b) 11 | fmt.Println(int(b)) 12 | } 13 | -------------------------------------------------------------------------------- /go/math/nan.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "math" 6 | ) 7 | 8 | func main() { 9 | n1 := math.NaN() 10 | n2 := math.NaN() 11 | fmt.Println(n1, n2) 12 | fmt.Println(n1 == n2) 13 | } 14 | -------------------------------------------------------------------------------- /go/math/rand.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "math/rand" 4 | import "time" 5 | 6 | func main() { 7 | src := rand.NewSource(time.Now().UnixNano()) 8 | random := rand.New(src) 9 | for i := 0; i < 100; i++ { 10 | // 伪随机 11 | x := rand.Intn(100) 12 | println("fake", x) 13 | 14 | // 真随机 15 | y := random.Intn(100) 16 | println("true", y) 17 | } 18 | 19 | // 如果为 0,会 panic 20 | rand.Intn(0) 21 | } 22 | -------------------------------------------------------------------------------- /go/memmap/demo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cch123/test/8a9d3dd4fbd3eecceaf4d77eb6cb56ca4e1528b9/go/memmap/demo.jpg -------------------------------------------------------------------------------- /go/memmap/memmap.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "os" 5 | "sync/atomic" 6 | "unsafe" 7 | 8 | "github.com/bradleyjkemp/memviz" 9 | "github.com/sitano/gsysint" 10 | ) 11 | 12 | func main() { 13 | var gp unsafe.Pointer 14 | 15 | atomic.StorePointer(&gp, gsysint.GetG()) 16 | 17 | gg := (*gsysint.G)(gp) 18 | memviz.Map(os.Stdout, gg) 19 | } 20 | -------------------------------------------------------------------------------- /go/net/iptest.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "net" 4 | import "fmt" 5 | 6 | func main() { 7 | var host = "www.google.com" 8 | var ip = net.ParseIP(host) 9 | var ip2, _ = net.ResolveIPAddr("ip", host) 10 | fmt.Println(ip) 11 | fmt.Println(ip2.Zone) 12 | fmt.Println(ip2.IP) 13 | var ip3, _ = net.ResolveIPAddr("ip", "127.0.0.1") 14 | fmt.Println(ip3.IP) 15 | } 16 | -------------------------------------------------------------------------------- /go/net/sockettest.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "net" 6 | ) 7 | 8 | func main() { 9 | //exit := make(chan bool) 10 | ip := net.ParseIP("127.0.0.1") 11 | port := 81 12 | tcp_addr := net.TCPAddr{ip, port, ""} 13 | udp_addr := net.UDPAddr{ip, port, ""} 14 | fmt.Println(tcp_addr) 15 | fmt.Println(udp_addr) 16 | fmt.Println(tcp_addr.Network()) 17 | fmt.Println(udp_addr.Network()) 18 | } 19 | -------------------------------------------------------------------------------- /go/offheap/main.go: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cch123/test/8a9d3dd4fbd3eecceaf4d77eb6cb56ca4e1528b9/go/offheap/main.go -------------------------------------------------------------------------------- /go/os/net_proc.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "syscall" 6 | ) 7 | 8 | func main() { 9 | res, err := syscall.Sysctl("security.mac.device_enforce") 10 | fmt.Printf("%#v\n", res) 11 | fmt.Println(err) 12 | } 13 | -------------------------------------------------------------------------------- /go/os/ostest.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "os/exec" 4 | import "reflect" 5 | 6 | import "fmt" 7 | import "bytes" 8 | 9 | func main() { 10 | dateCmd := exec.Command("date") 11 | dateOut, _ := dateCmd.Output() 12 | println(dateOut) 13 | println(string(dateOut)) 14 | buf1 := bytes.NewBufferString("fuck") 15 | fmt.Println(reflect.TypeOf(buf1)) 16 | } 17 | -------------------------------------------------------------------------------- /go/os/pidtest.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "os" 4 | 5 | func main() { 6 | println(os.Getpid()) 7 | } 8 | -------------------------------------------------------------------------------- /go/os/sysinfo.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "log" 7 | 8 | "github.com/zcalusic/sysinfo" 9 | ) 10 | 11 | func main() { 12 | var si sysinfo.SysInfo 13 | 14 | si.GetSysInfo() 15 | 16 | data, err := json.MarshalIndent(&si, "", " ") 17 | if err != nil { 18 | log.Fatal(err) 19 | } 20 | 21 | fmt.Println(string(data)) 22 | } 23 | -------------------------------------------------------------------------------- /go/os/test/www_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "os/exec" 7 | "testing" 8 | ) 9 | 10 | func TestSymbol(t *testing.T) { 11 | cmd := exec.Command("nm", os.Args[0]) 12 | contentBytes, err := cmd.Output() 13 | if err != nil { 14 | println(err) 15 | t.Fail() 16 | } 17 | 18 | fmt.Println(string(contentBytes)) 19 | fmt.Println(os.Args[0]) 20 | } 21 | -------------------------------------------------------------------------------- /go/panic/before_1-9-2-bug.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "reflect" 5 | "runtime" 6 | ) 7 | 8 | func main() { 9 | fv := reflect.ValueOf(func(int) struct{} { return struct{}{} }) 10 | args := []reflect.Value{reflect.ValueOf(0)} 11 | 12 | go func() { 13 | runtime.GC() 14 | }() 15 | 16 | for { 17 | fv.Call(args) 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /go/panic/panic_or_not.go: -------------------------------------------------------------------------------- 1 | // 还是会 panic 的,请注意 2 | package main 3 | 4 | import "fmt" 5 | 6 | func main() { 7 | var ch = make(chan int) 8 | var ch2 = make(chan int, 1) 9 | ch2 <- 1 10 | close(ch) 11 | select { 12 | case ch <- 1: 13 | case n := <-ch2: 14 | fmt.Println("not panic", n) 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /go/panic/panic_recover_and_return.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func test(output *int) (output2 int) { 6 | defer func() { 7 | if err := recover(); err != nil { 8 | *output = 444 9 | output2 = 23323 10 | } 11 | }() 12 | *output = 2 13 | panic(1) 14 | } 15 | 16 | func main() { 17 | x := 0 18 | y := test(&x) 19 | fmt.Println(x, y) 20 | } 21 | -------------------------------------------------------------------------------- /go/panic/readme.md: -------------------------------------------------------------------------------- 1 | 如何在 panic 的同时把结果返回,参考 `panic_recover_and_return.go` 2 | -------------------------------------------------------------------------------- /go/peg/readme.md: -------------------------------------------------------------------------------- 1 | peglint -ast -s '1 + 2 + 32' ./grammar.peg 2 | -------------------------------------------------------------------------------- /go/pipe/pipe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cch123/test/8a9d3dd4fbd3eecceaf4d77eb6cb56ca4e1528b9/go/pipe/pipe -------------------------------------------------------------------------------- /go/pkgerror/demo.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/pkg/errors" 7 | ) 8 | 9 | func main() { 10 | var err = errors.New("fuck") 11 | err = errors.Wrap(err, "this **** happened here") 12 | fmt.Printf("%+v\n", err) 13 | err = errors.WithStack(err) 14 | fmt.Printf("%+v\n", err) 15 | 16 | x := fmt.Sprintf("%+v", err) 17 | fmt.Println(x) 18 | } 19 | -------------------------------------------------------------------------------- /go/pool/redigo_with_pool/Godeps/Readme: -------------------------------------------------------------------------------- 1 | This directory tree is generated automatically by godep. 2 | 3 | Please do not edit. 4 | 5 | See https://github.com/tools/godep for more information. 6 | -------------------------------------------------------------------------------- /go/pool/redigo_with_pool/vendor/golang.org/x/net/AUTHORS: -------------------------------------------------------------------------------- 1 | # This source code refers to The Go Authors for copyright purposes. 2 | # The master list of authors is in the main Go distribution, 3 | # visible at http://tip.golang.org/AUTHORS. 4 | -------------------------------------------------------------------------------- /go/pool/redigo_with_pool/vendor/golang.org/x/net/CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | # This source code was written by the Go contributors. 2 | # The master list of contributors is in the main Go distribution, 3 | # visible at http://tip.golang.org/CONTRIBUTORS. 4 | -------------------------------------------------------------------------------- /go/pprof/pprof.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "net/http" 5 | _ "net/http/pprof" 6 | ) 7 | 8 | var quit chan struct{} = make(chan struct{}) 9 | 10 | func f() { 11 | <-quit 12 | } 13 | 14 | func main() { 15 | for i := 0; i < 10000; i++ { 16 | go f() 17 | } 18 | 19 | http.ListenAndServe(":8080", nil) 20 | } 21 | -------------------------------------------------------------------------------- /go/pprof/producer_consumer_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | _ "net/http/pprof" 5 | "testing" 6 | ) 7 | 8 | func Test_main(t *testing.T) { 9 | tests := []struct { 10 | name string 11 | }{ 12 | // TODO: Add test cases. 13 | } 14 | for range tests { 15 | t.Run(tt.name, func(t *testing.T) { 16 | main() 17 | }) 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /go/pprof/readme.md: -------------------------------------------------------------------------------- 1 | 只要简单的import _ "net/http/pprof" 2 | 3 | 然后就可以localhost:port/debug/pprof来看了 4 | 5 | 6 | // cpu gvz 7 | go tool pprof ../producer_consumer ./cpu.prof 8 | -------------------------------------------------------------------------------- /go/race/g.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "runtime" 4 | 5 | var a int 6 | 7 | func calc() { 8 | for i := 0; i < 10; i++ { 9 | go func() { 10 | for { 11 | runtime.RaceDisable() 12 | a++ 13 | runtime.RaceEnable() 14 | } 15 | }() 16 | 17 | } 18 | } 19 | 20 | func main() { 21 | calc() 22 | } 23 | -------------------------------------------------------------------------------- /go/race/g2.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "runtime" 4 | 5 | var a int 6 | 7 | func calc() { 8 | for i := 0; i < 10; i++ { 9 | go func() { 10 | for { 11 | runtime.RaceDisable() 12 | a++ 13 | runtime.RaceEnable() 14 | } 15 | }() 16 | 17 | } 18 | } 19 | 20 | func main() { 21 | calc() 22 | } 23 | -------------------------------------------------------------------------------- /go/race/g_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "testing" 4 | 5 | func BenchCalc(b *testing.B) { 6 | for i := 0; i < b.N; i++ { 7 | calc() 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /go/raft/hashicorp.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/hashicorp/raft" 4 | 5 | func main() { 6 | conf := raft.Config{} 7 | logs := raft.Log{} 8 | stable := raft.StableStore{} 9 | raft.BootstrapCluster(conf, logs, stable, snaps, trans, configuration) 10 | } 11 | -------------------------------------------------------------------------------- /go/raft/hashicorp/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "net/http" 4 | 5 | func main() { 6 | config(3) 7 | 8 | http.HandleFunc("/", Handler) 9 | err := http.ListenAndServe(":3333", nil) 10 | panic(err) 11 | } 12 | -------------------------------------------------------------------------------- /go/rand/1.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "math/rand" 6 | ) 7 | 8 | func main() { 9 | for i := 0; i < 1000; i++ { 10 | x := rand.Intn(10) 11 | fmt.Println(x) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /go/receiver/normal.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type T struct { 6 | name string 7 | age int 8 | } 9 | 10 | func (t *T) getName() string { 11 | return t.name 12 | } 13 | 14 | func (t T) getAge() int { 15 | return t.age 16 | } 17 | 18 | func main() { 19 | var t T 20 | t.age = 99 21 | t.name = "seth" 22 | fmt.Println(t.getName()) 23 | fmt.Println(t.getAge()) 24 | } 25 | -------------------------------------------------------------------------------- /go/receiver/pointer_rec.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type person struct{ age int } 6 | 7 | func (p *person) prin() { 8 | fmt.Printf("%p\n", p) 9 | p.age = 2 10 | } 11 | 12 | func main() { 13 | var p person 14 | // 会自动取地址 15 | p.prin() 16 | println(&p) 17 | fmt.Println(p) 18 | } 19 | -------------------------------------------------------------------------------- /go/redis/readme.md: -------------------------------------------------------------------------------- 1 | go run -race redis-go.go 2 | -------------------------------------------------------------------------------- /go/redis/redisTest.php: -------------------------------------------------------------------------------- 1 | connect("localhost", "6379",0); 4 | echo time(); 5 | echo "\n"; 6 | for ($i =0;$i<10000;$i++) { 7 | $r = $a->get("foo".$i); 8 | } 9 | echo time(); 10 | -------------------------------------------------------------------------------- /go/reflect/field_offset.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "reflect" 6 | ) 7 | 8 | type Person struct { 9 | A struct { 10 | Age int64 11 | Height int64 12 | a *int64 13 | } 14 | low int64 15 | aa int 16 | dd int 17 | } 18 | 19 | func main() { 20 | var p Person 21 | t, err := reflect.TypeOf(p).FieldByName("aa") 22 | fmt.Println(t, err) 23 | println(t.Offset) 24 | } 25 | -------------------------------------------------------------------------------- /go/reflect/reflecttest.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "reflect" 4 | import "fmt" 5 | 6 | func main() { 7 | var i = 1 8 | fmt.Println(reflect.TypeOf(i)) 9 | fmt.Println(reflect.ValueOf(i)) 10 | fmt.Println(reflect.ValueOf(i).Type()) 11 | fmt.Println(reflect.ValueOf(i).Kind()) 12 | fmt.Println(reflect.ValueOf(i).Int()) 13 | } 14 | -------------------------------------------------------------------------------- /go/reflect/struct_type.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "reflect" 6 | ) 7 | 8 | type Person struct { 9 | age int 10 | } 11 | 12 | func main() { 13 | var a Person 14 | fmt.Println(reflect.TypeOf(a)) 15 | } 16 | -------------------------------------------------------------------------------- /go/reflect/time_type.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "reflect" 6 | "time" 7 | ) 8 | 9 | func main() { 10 | var a time.Time 11 | var struc struct{} 12 | fmt.Println(reflect.TypeOf(a).Kind()) 13 | fmt.Println(reflect.TypeOf(a)) 14 | fmt.Println(reflect.TypeOf(a) == reflect.TypeOf(time.Time{})) 15 | fmt.Println(reflect.TypeOf(a) == reflect.TypeOf(struc)) 16 | } 17 | -------------------------------------------------------------------------------- /go/reflect/zero_is_what.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "reflect" 6 | ) 7 | 8 | func main() { 9 | fmt.Println(reflect.ValueOf(1).Kind()) 10 | var a = 0.0 11 | fmt.Println(reflect.ValueOf(a).Kind()) 12 | var b = 0 13 | fmt.Println(reflect.ValueOf(b).Kind()) 14 | } 15 | -------------------------------------------------------------------------------- /go/ringbuffer/readme.md: -------------------------------------------------------------------------------- 1 | go build t.go 2 | 3 | go build t2.go 4 | 5 | time ./t 6 | 7 | time ./t2 8 | -------------------------------------------------------------------------------- /go/runtime/forloopinline.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "time" 4 | 5 | func main() { 6 | var a []string 7 | for { 8 | var d = len(a) 9 | 10 | time.Sleep(time.Second) 11 | println(d) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /go/runtime/gotoolobjdump.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | //go tool objdump可以看生成的汇编代码, 4 | //然后在汇编内容里搜索gotoolobjdump.go 5 | //可以找到对应的行数和汇编代码的关系 6 | 7 | func main() { 8 | a := []int{1, 2, 3} 9 | b := len(a) 10 | println(b) 11 | } 12 | -------------------------------------------------------------------------------- /go/runtime/inline.go: -------------------------------------------------------------------------------- 1 | // go build -gcflags "-m" 2 | // 可以看到编译器会做哪些内联优化 3 | package main 4 | 5 | import "fmt" 6 | 7 | func test() { 8 | } 9 | 10 | func main() { 11 | test() 12 | var a []string 13 | fmt.Println(len(a)) 14 | } 15 | -------------------------------------------------------------------------------- /go/runtime/monitor/memstats.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func main() { 4 | } 5 | -------------------------------------------------------------------------------- /go/runtime/runtimeCaller.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "runtime" 6 | ) 7 | 8 | func test() { 9 | if pc, _, _, ok := runtime.Caller(0); ok { 10 | f := runtime.FuncForPC(pc) 11 | fmt.Println(f.Name()) 12 | if f.Name() != "main.test" { 13 | println("inline") 14 | } 15 | } 16 | } 17 | 18 | func main() { 19 | test() 20 | } 21 | -------------------------------------------------------------------------------- /go/slice/append_when_under_array_has_capacity.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | var a = [...]int{1, 2, 3, 4, 5} 7 | // will use the cap of array underneath 8 | b := a[1:3] 9 | fmt.Println(len(b), cap(b)) 10 | } 11 | -------------------------------------------------------------------------------- /go/slice/del_elem.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | var a = []int{0, 1, 2, 3, 4, 5, 6, 7} 7 | fmt.Println(a, "cap", cap(a), "len", len(a)) 8 | a = append(a[:5], a[6:]...) 9 | fmt.Println(a, "cap", cap(a), "len", len(a)) 10 | } 11 | -------------------------------------------------------------------------------- /go/slice/merge_slices.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | var a = []int{0, 1, 2, 3, 4, 5, 6, 7} 7 | merged := append([]int{}, a[:5]...) 8 | merged = append(merged, a[6:]...) 9 | fmt.Println(merged) 10 | } 11 | -------------------------------------------------------------------------------- /go/slice/nil_and_empty_slice.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | var a []int 7 | var b = make([]int, 0) 8 | fmt.Println(a == nil) 9 | fmt.Println(b == nil) 10 | fmt.Println(a) 11 | fmt.Println(b) 12 | fmt.Printf("%p\n", &a) 13 | fmt.Printf("%p\n", &b) 14 | } 15 | -------------------------------------------------------------------------------- /go/slice/nil_slice_empty_slice.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "reflect" 6 | "unsafe" 7 | ) 8 | 9 | func main() { 10 | var a = []int{} 11 | var b []int = nil 12 | 13 | pa := (*reflect.SliceHeader)(unsafe.Pointer(&a)) 14 | pb := (*reflect.SliceHeader)(unsafe.Pointer(&b)) 15 | 16 | fmt.Printf("a: %#v\n", *pa) 17 | fmt.Printf("b: %#v\n", *pb) 18 | } 19 | -------------------------------------------------------------------------------- /go/slice/reverse.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "sort" 6 | ) 7 | 8 | func main() { 9 | var a = []int{43, 32, 12, 32, 44} 10 | 11 | sort.Sort(sort.Reverse(sort.IntSlice(a))) 12 | fmt.Println(a) 13 | } 14 | -------------------------------------------------------------------------------- /go/snowflake/maxInt.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "math" 6 | ) 7 | 8 | func main() { 9 | fmt.Println(math.MaxInt64) 10 | } 11 | -------------------------------------------------------------------------------- /go/snowflake/snow.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/zheng-ji/goSnowFlake" 7 | ) 8 | 9 | func main() { 10 | iw, err := goSnowFlake.NewIdWorker(1) 11 | if err != nil { 12 | fmt.Println(err) 13 | } 14 | 15 | for i := 0; i < 10; i++ { 16 | if id, err := iw.NextId(); err != nil { 17 | fmt.Println(err) 18 | } else { 19 | fmt.Println(id) 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /go/strconv/formatFloat.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "strconv" 6 | ) 7 | 8 | func main() { 9 | val := 0.00000001 10 | f := byte('e') 11 | fmt.Println(strconv.FormatFloat(float64(val), f, -1, 64)) 12 | } 13 | -------------------------------------------------------------------------------- /go/string/alloc_or_not_alloc/a_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "testing" 4 | 5 | func BenchmarkA(b *testing.B) { 6 | for i := 0; i < b.N; i++ { 7 | TestA() 8 | } 9 | } 10 | 11 | func BenchmarkB(b *testing.B) { 12 | for i := 0; i < b.N; i++ { 13 | TestB() 14 | } 15 | } 16 | 17 | func BenchmarkC(b *testing.B) { 18 | for i := 0; i < b.N; i++ { 19 | TestC() 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /go/string/alloc_or_not_alloc/readme.md: -------------------------------------------------------------------------------- 1 | go test -bench=. -benchmem 2 | -------------------------------------------------------------------------------- /go/string/b.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func main() { 4 | var a = map[string]int{"abc": 1} 5 | var b = []byte{'a', 'b', 'c'} 6 | // runtime.slicebytetostring 7 | var c = string(b) 8 | _ = a[c] 9 | 10 | // 这里会被优化掉 11 | // 不会出现runtime.slicebytetostring 12 | _ = a[string(b)] 13 | } 14 | -------------------------------------------------------------------------------- /go/string/convert.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | fmt.Println(string("11")) 7 | fmt.Println(string('a')) 8 | fmt.Printf("%#v\n", string(49)) 9 | } 10 | -------------------------------------------------------------------------------- /go/string/hasPrefix.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | ) 7 | 8 | func main() { 9 | var a = "g_qc_source_0" 10 | fmt.Println(strings.HasPrefix(a, "g_qc_source")) 11 | fmt.Println(strings.HasPrefix(a, "g_qc_sourcw")) 12 | fmt.Println(fmt.Sprintf("%v_%v", 1, "1")) 13 | } 14 | -------------------------------------------------------------------------------- /go/string/joinAndConcatBench/readme.md: -------------------------------------------------------------------------------- 1 | go test -bench=. -benchmem 2 | 3 | sprintf is a disaster! 4 | -------------------------------------------------------------------------------- /go/string/replaceNums.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | "unicode" 7 | ) 8 | 9 | func main() { 10 | var a = `g_service_1323` 11 | a = strings.TrimRightFunc(a, unicode.IsDigit) 12 | a = strings.TrimRight(a, "_") 13 | fmt.Println(a) 14 | } 15 | -------------------------------------------------------------------------------- /go/string/replaceTest.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | ) 7 | 8 | func main() { 9 | var a = `('a','b','c')` 10 | fmt.Println(strings.Replace(a, `'`, `"`, -1)) 11 | } 12 | -------------------------------------------------------------------------------- /go/string/searchStr.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "sort" 4 | 5 | func main() { 6 | arr := []string{"iOS/0.9.4", "dafafa"} 7 | sort.Strings(arr) 8 | println(sort.SearchStrings(arr, "ANDROID/0.9w")) 9 | } 10 | -------------------------------------------------------------------------------- /go/string/splintN.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | ) 7 | 8 | func main() { 9 | var a = "abc@def@gh" 10 | res := strings.SplitN(a, "@", 2) 11 | fmt.Println(res) 12 | } 13 | -------------------------------------------------------------------------------- /go/string/splitTest.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "regexp" 6 | "strings" 7 | ) 8 | 9 | // golang里的split和java里的不一样 10 | // java里的String str; str.split("\\.")需要转义,默认是正则 11 | // 但在go里,如果需要正则形式split的话,需要用到regexp包 12 | func main() { 13 | fmt.Println(strings.Split("a.b.c", `.`)) 14 | reg := regexp.MustCompile("\\.") // 和java的split等价 15 | fmt.Println(reg.Split("a.b.c", -1)) 16 | } 17 | -------------------------------------------------------------------------------- /go/string/split_and_same_under_array/ben_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "testing" 4 | 5 | func BenchmarkA(b *testing.B) { 6 | for i := 0; i < b.N; i++ { 7 | A() 8 | } 9 | } 10 | 11 | func BenchmarkB(b *testing.B) { 12 | for i := 0; i < b.N; i++ { 13 | B() 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /go/string/split_and_same_under_array/readme.md: -------------------------------------------------------------------------------- 1 | go test -bench=. -benchmem 2 | 3 | strings.Replace is a disaster! 4 | -------------------------------------------------------------------------------- /go/string/string_display_same_but_not_euqal.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | var a = []byte{49, 0, 50} 7 | var b = []byte{49, 50, 0} 8 | fmt.Println(string(a), string(b)) 9 | fmt.Printf("%s\n", a) 10 | fmt.Printf("%s\n", b) 11 | fmt.Println(len(a), len(b)) 12 | fmt.Println(string(a) == string(b)) 13 | } 14 | -------------------------------------------------------------------------------- /go/suffix/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "index/suffixarray" 6 | ) 7 | 8 | func main() { 9 | idx := suffixarray.New([]byte("abcdbcbcbcefg")) 10 | res := idx.Lookup([]byte("bc"), -1) 11 | fmt.Println(res) 12 | } 13 | -------------------------------------------------------------------------------- /go/sync/structLock.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "sync" 4 | 5 | type Person struct { 6 | age int 7 | lock sync.Mutex 8 | } 9 | 10 | // 考虑一下这里为什么不能用p Person? 11 | func (p *Person) changeAge(newAge int) { 12 | p.lock.Lock() 13 | p.age = newAge 14 | p.lock.Unlock() 15 | } 16 | 17 | func main() { 18 | p := new(Person) 19 | p.changeAge(5) 20 | } 21 | -------------------------------------------------------------------------------- /go/syscall/file.dat: -------------------------------------------------------------------------------- 1 | 3dfjasdkf9lafs 2 | adsjfkasdjf 3 | adsjfkasdjfa 4 | djf 5 | adsjfkasdjfsdfjsaf 6 | -------------------------------------------------------------------------------- /go/syscall/test.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cch123/test/8a9d3dd4fbd3eecceaf4d77eb6cb56ca4e1528b9/go/syscall/test.dat -------------------------------------------------------------------------------- /go/test_fail_in_1.13/lib.go: -------------------------------------------------------------------------------- 1 | package lib 2 | 3 | import "flag" 4 | 5 | func init() { 6 | flag.Parse() 7 | } 8 | 9 | func Yes() { 10 | } 11 | -------------------------------------------------------------------------------- /go/test_fail_in_1.13/lib_test.go: -------------------------------------------------------------------------------- 1 | package lib 2 | 3 | import "testing" 4 | 5 | func TestYes(t *testing.T) { 6 | Yes() 7 | } 8 | -------------------------------------------------------------------------------- /go/test_with_tags/m.go: -------------------------------------------------------------------------------- 1 | package xxx 2 | 3 | import "fmt" 4 | 5 | var ( 6 | getUserFunc func() bool 7 | validateFunc func() bool 8 | createOrderFunc func() bool 9 | ) 10 | 11 | // Process ... 12 | func Process() { 13 | fmt.Println(getUserFunc()) 14 | fmt.Println(validateFunc()) 15 | fmt.Println(createOrderFunc()) 16 | } 17 | -------------------------------------------------------------------------------- /go/test_with_tags/m_test.go: -------------------------------------------------------------------------------- 1 | package xxx 2 | 3 | import "testing" 4 | 5 | func TestProcess(t *testing.T) { 6 | Process() 7 | } 8 | -------------------------------------------------------------------------------- /go/test_with_tags/production.go: -------------------------------------------------------------------------------- 1 | // +build !test 2 | 3 | package xxx 4 | 5 | func init() { 6 | getUserFunc = func() bool { return true } 7 | validateFunc = func() bool { return true } 8 | createOrderFunc = func() bool { return true } 9 | } 10 | -------------------------------------------------------------------------------- /go/test_with_tags/readme.md: -------------------------------------------------------------------------------- 1 | # how to test with tags and mock your function when test 2 | 3 | ```shell 4 | go test 5 | 6 | go test -tags=test 7 | ``` -------------------------------------------------------------------------------- /go/test_with_tags/test_fakes.go: -------------------------------------------------------------------------------- 1 | // +build test 2 | 3 | package xxx 4 | 5 | func init() { 6 | getUserFunc = func() bool { return false } 7 | validateFunc = func() bool { return false } 8 | createOrderFunc = func() bool { return false } 9 | } 10 | -------------------------------------------------------------------------------- /go/thrift/GoUnusedProtection__.go: -------------------------------------------------------------------------------- 1 | // Autogenerated by Thrift Compiler (0.13.0) 2 | // DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 3 | 4 | package main 5 | 6 | var GoUnusedProtection__ int 7 | -------------------------------------------------------------------------------- /go/thrift/hello.thrift: -------------------------------------------------------------------------------- 1 | namespace go echo 2 | 3 | struct EchoReq { 4 | 1: string msg; 5 | } 6 | 7 | struct EchoRes { 8 | 1: string msg; 9 | } 10 | 11 | service Echo { 12 | EchoRes echo(1: EchoReq req); 13 | } 14 | -------------------------------------------------------------------------------- /go/time/timeunmarshal.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "time" 7 | ) 8 | 9 | func main() { 10 | var a = `{"time" : "2015-01-01 00:00:00"}` 11 | var b struct { 12 | Time time.Time 13 | } 14 | err := json.Unmarshal([]byte(a), &b) 15 | fmt.Println(b, err) 16 | } 17 | -------------------------------------------------------------------------------- /go/trace/readme.md: -------------------------------------------------------------------------------- 1 | ~/t/g/trace ❯❯❯ go run trace.go 2>res 2 | ~/t/g/trace ❯❯❯ go tool trace -http=0.0.0.0:8888 ./res 3 | 4 | -------------------------------------------------------------------------------- /go/trace/trace.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "os" 5 | "runtime/trace" 6 | ) 7 | 8 | func main() { 9 | trace.Start(os.Stderr) 10 | defer trace.Stop() 11 | // create new channel of type int 12 | ch := make(chan int) 13 | 14 | // start new anonymous goroutine 15 | go func() { 16 | // send 42 to channel 17 | ch <- 42 18 | }() 19 | // read from channel 20 | <-ch 21 | } 22 | -------------------------------------------------------------------------------- /go/types/aliasTypeConvert.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "reflect" 6 | ) 7 | 8 | type aaa string 9 | 10 | func main() { 11 | var a aaa 12 | a = aaa("oh no") 13 | fmt.Println(a) 14 | var b string 15 | b = string(a) 16 | fmt.Println(b) 17 | fmt.Println(reflect.TypeOf(a)) 18 | fmt.Println(reflect.TypeOf(b)) 19 | } 20 | -------------------------------------------------------------------------------- /go/types/intConvert.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | var a int64 = 1 7 | var b = int32(a) 8 | fmt.Println(b) 9 | } 10 | -------------------------------------------------------------------------------- /go/unicode/encod.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func main() { 4 | var a = "\346\265\213\350\257\225" 5 | var b = []rune(a) 6 | println(a) 7 | println(len(a), len(b)) 8 | for i := 0; i < len(b); i++ { 9 | println(string(b[i])) 10 | } 11 | 12 | var c = []rune("呵呵") 13 | for i := 0; i < len(c); i++ { 14 | println(c[i]) 15 | } 16 | 17 | var d = "\u77e5" 18 | println(d) 19 | } 20 | -------------------------------------------------------------------------------- /go/unicode/utest.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "unicode" 6 | ) 7 | 8 | func main() { 9 | fmt.Println(unicode.IsDigit('2')) 10 | } 11 | -------------------------------------------------------------------------------- /go/unicorn/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cch123/test/8a9d3dd4fbd3eecceaf4d77eb6cb56ca4e1528b9/go/unicorn/readme.md -------------------------------------------------------------------------------- /go/unsafe/readme.md: -------------------------------------------------------------------------------- 1 | 32位系统和64位系统对齐规则不一样 2 | 3 | 所以在对struct做指针移动修改存储值时可能会在不同平台得到不同的结果 4 | -------------------------------------------------------------------------------- /go/uuidtest/useUUIDGEN/util.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "os/exec" 4 | 5 | var uuid []byte 6 | 7 | func test() { 8 | uuid, _ = exec.Command("uuidgen").Output() 9 | } 10 | -------------------------------------------------------------------------------- /go/uuidtest/useUUIDGEN/uuid_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "testing" 4 | 5 | func BenchmarkUUID(b *testing.B) { 6 | for i := 0; i < b.N; i++ { 7 | test() 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /go/uuidtest/uselib/util.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import uuid "github.com/satori/go.uuid" 4 | 5 | var u1 uuid.UUID 6 | 7 | func test() { 8 | u1 = uuid.NewV4() 9 | } 10 | -------------------------------------------------------------------------------- /go/uuidtest/uselib/uuid_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "testing" 4 | 5 | func BenchmarkUUID(b *testing.B) { 6 | for i := 0; i < b.N; i++ { 7 | test() 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /go/version/v.go: -------------------------------------------------------------------------------- 1 | package main 2 | import "runtime" 3 | import "fmt" 4 | 5 | func main() { 6 | fmt.Println(runtime.Version()) 7 | } 8 | 9 | -------------------------------------------------------------------------------- /go_web/chi_with_doc.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "net/http" 5 | 6 | "github.com/pressly/chi" 7 | "github.com/pressly/chi/docgen" 8 | "io" 9 | ) 10 | 11 | func main() { 12 | r := chi.NewRouter() 13 | r.Get("/", func(w http.ResponseWriter, req *http.Request) { 14 | io.WriteString(w,docgen.JSONRoutesDoc(r)) 15 | }) 16 | http.ListenAndServe(":3000", r) 17 | } 18 | -------------------------------------------------------------------------------- /go_web/echo.go: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cch123/test/8a9d3dd4fbd3eecceaf4d77eb6cb56ca4e1528b9/go_web/echo.go -------------------------------------------------------------------------------- /go_web/form/ben_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "testing" 4 | 5 | func BenchmarkTest(b *testing.B) { 6 | for i := 0; i < b.N; i++ { 7 | test() 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /go_web/gin/templates/index.tmpl: -------------------------------------------------------------------------------- 1 | 2 |

3 | {{ .title }} 4 |

5 | 6 | -------------------------------------------------------------------------------- /go_web/martini.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/go-martini/martini" 4 | 5 | func hello() string { 6 | return "Hello world" 7 | } 8 | 9 | func main() { 10 | m := martini.Classic() 11 | m.Get("/", hello) 12 | m.Run() 13 | } 14 | -------------------------------------------------------------------------------- /go_web/readme.md: -------------------------------------------------------------------------------- 1 | 目前的binding和validate模块普遍存在一个问题 2 | 3 | 因为golang的int、string之类的字段的语义缺失问题的关系(不能=nil),如果先bind,再validate,没有办法判断一个字段的0值是因为默认值导致还是因为用户输入导致 4 | 5 | 而大多数validate模块的required实际上也就只是判断deserilize之后的值是否是字段的默认值而已,这样的判断是不严谨的。很可能会出bug 6 | 7 | -------------------------------------------------------------------------------- /gomod/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | import "fmt" 3 | 4 | import registry "github.com/apache/dubbo-go/registry" 5 | import zk "github.com/apache/dubbo-go/registry/zookeeper" 6 | import xds "mosn.io/mosn/pkg/xds" 7 | 8 | func main() { 9 | var r registry.Registry 10 | fmt.Println(r) 11 | var z zk.Option 12 | fmt.Println(z) 13 | var x xds.Client 14 | fmt.Println(x) 15 | } 16 | -------------------------------------------------------------------------------- /graphviz/psm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cch123/test/8a9d3dd4fbd3eecceaf4d77eb6cb56ca4e1528b9/graphviz/psm.png -------------------------------------------------------------------------------- /images/5g war.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cch123/test/8a9d3dd4fbd3eecceaf4d77eb6cb56ca4e1528b9/images/5g war.png -------------------------------------------------------------------------------- /js/closure2.js: -------------------------------------------------------------------------------- 1 | var name = "trigkit4"; 2 | var segmentFault = { 3 |  name : "My SF", 4 |  getNameFunc : function(){ 5 |   return function(){ 6 |    return this.name; 7 |  }; 8 | } 9 | }; 10 | console.log(segmentFault.getNameFunc()()); //弹出trigkit4 11 | -------------------------------------------------------------------------------- /js/generator.js: -------------------------------------------------------------------------------- 1 | //这个例子的yield和python比较类似 2 | var Fiber = require('fibers'); 3 | 4 | var inc = Fiber(function(start){ 5 | var total = start; 6 | while(true) { 7 | total += start; 8 | Fiber.yield(total); 9 | } 10 | }) 11 | 12 | for(var ii = 0; ii<=10; ii++) { 13 | console.log(inc.run(2)); 14 | } 15 | 16 | for(var ii = 0; ii<=10; ii++) { 17 | console.log(inc.run(1)) 18 | } 19 | -------------------------------------------------------------------------------- /js/intervaltest.js: -------------------------------------------------------------------------------- 1 | var t, sec = 0; 2 | function countDown() { 3 | clearInterval(t); 4 | setTimeout(countDown, 1000); 5 | sec++; 6 | console.log(sec); 7 | } 8 | 9 | function test() { 10 | t = setInterval(countDown, 1000); 11 | } 12 | 13 | -------------------------------------------------------------------------------- /js/node_modules/fibers/.npmignore: -------------------------------------------------------------------------------- 1 | build/ 2 | node_modules/ 3 | -------------------------------------------------------------------------------- /js/node_modules/fibers/bin/.npmignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cch123/test/8a9d3dd4fbd3eecceaf4d77eb6cb56ca4e1528b9/js/node_modules/fibers/bin/.npmignore -------------------------------------------------------------------------------- /js/node_modules/fibers/bin/darwin-ia32-v8-3.14/fibers.node: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cch123/test/8a9d3dd4fbd3eecceaf4d77eb6cb56ca4e1528b9/js/node_modules/fibers/bin/darwin-ia32-v8-3.14/fibers.node -------------------------------------------------------------------------------- /js/node_modules/fibers/bin/darwin-x64-v8-3.14/fibers.node: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cch123/test/8a9d3dd4fbd3eecceaf4d77eb6cb56ca4e1528b9/js/node_modules/fibers/bin/darwin-x64-v8-3.14/fibers.node -------------------------------------------------------------------------------- /js/node_modules/fibers/bin/linux-ia32-v8-3.14/fibers.node: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cch123/test/8a9d3dd4fbd3eecceaf4d77eb6cb56ca4e1528b9/js/node_modules/fibers/bin/linux-ia32-v8-3.14/fibers.node -------------------------------------------------------------------------------- /js/node_modules/fibers/bin/linux-x64-v8-3.14/fibers.node: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cch123/test/8a9d3dd4fbd3eecceaf4d77eb6cb56ca4e1528b9/js/node_modules/fibers/bin/linux-x64-v8-3.14/fibers.node -------------------------------------------------------------------------------- /js/node_modules/fibers/bin/win32-ia32-v8-3.14/fibers.node: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cch123/test/8a9d3dd4fbd3eecceaf4d77eb6cb56ca4e1528b9/js/node_modules/fibers/bin/win32-ia32-v8-3.14/fibers.node -------------------------------------------------------------------------------- /js/node_modules/fibers/bin/win32-x64-v8-3.14/fibers.node: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cch123/test/8a9d3dd4fbd3eecceaf4d77eb6cb56ca4e1528b9/js/node_modules/fibers/bin/win32-x64-v8-3.14/fibers.node -------------------------------------------------------------------------------- /js/node_modules/fibers/quick-test.js: -------------------------------------------------------------------------------- 1 | "use strict" 2 | var Fiber = require('./fibers'); 3 | var fiber = Fiber(function() { 4 | process.stdout.write(Fiber.yield()); 5 | }); 6 | fiber.run(); 7 | fiber.run('pass'); 8 | -------------------------------------------------------------------------------- /js/node_modules/fibers/src/libcoro/README: -------------------------------------------------------------------------------- 1 | Configuration, documentation etc. is provided in the coro.h file. Please 2 | note that the file conftest.c in this distribution is under the GPL. It is 3 | not needed for proper operation of this library though, for that, coro.h 4 | and coro.c suffice. 5 | 6 | Marc Lehmann 7 | -------------------------------------------------------------------------------- /js/node_modules/fibers/test/already-running.js: -------------------------------------------------------------------------------- 1 | // gh-8 2 | var Fiber = require('fibers'); 3 | try { 4 | Fiber(function() { 5 | var that = Fiber.current; 6 | Fiber(function(){ 7 | that.run(); 8 | }).run(); 9 | }).run(); 10 | } catch(err) { 11 | console.log('pass'); 12 | } 13 | -------------------------------------------------------------------------------- /js/node_modules/fibers/test/bad-context.js: -------------------------------------------------------------------------------- 1 | var Fiber = require('fibers'); 2 | 3 | try { 4 | Fiber.prototype.run.call(null); 5 | } catch (err) { 6 | console.log('pass'); 7 | } 8 | -------------------------------------------------------------------------------- /js/node_modules/fibers/test/current.js: -------------------------------------------------------------------------------- 1 | var Fiber = require('fibers'); 2 | 3 | var current; 4 | Fiber(function() { 5 | current = Fiber.current; 6 | Fiber.yield(); 7 | console.log('pass'); 8 | }).run(); 9 | if (current) { 10 | current.run(); 11 | } else { 12 | console.log('fail'); 13 | } 14 | -------------------------------------------------------------------------------- /js/node_modules/fibers/test/finish-multiple.js: -------------------------------------------------------------------------------- 1 | // gh-16 2 | var Fiber = require('fibers'); 3 | Fiber(function() { 4 | Fiber(function() { 5 | Fiber(function() {}).run(); 6 | }).run(); 7 | }).run(); 8 | console.log('pass'); 9 | -------------------------------------------------------------------------------- /js/node_modules/fibers/test/illegal-yield.js: -------------------------------------------------------------------------------- 1 | // gh-3 2 | var Fiber = require('fibers'); 3 | try { 4 | Fiber.yield(); 5 | } catch(err) { 6 | console.log('pass'); 7 | } 8 | -------------------------------------------------------------------------------- /js/node_modules/fibers/test/pool.js: -------------------------------------------------------------------------------- 1 | var Fiber = require('fibers'); 2 | 3 | for (var jj = 0; jj < 10; ++jj) { 4 | var fibers = []; 5 | for (var ii = 0; ii < 200; ++ii) { 6 | var fn = Fiber(function() { 7 | Fiber.yield(); 8 | }); 9 | fn.run(); 10 | fibers.push(fn); 11 | } 12 | for (var ii = 0; ii < fibers.length; ++ii) { 13 | fibers[ii].run(); 14 | } 15 | } 16 | console.log('pass'); 17 | -------------------------------------------------------------------------------- /js/node_modules/fibers/test/process-title.js: -------------------------------------------------------------------------------- 1 | // gh-10 2 | var Fiber = require('fibers'); 3 | 4 | var title = process.title; 5 | Fiber(function() { 6 | process.title = 'pass'; 7 | }).run(); 8 | console.log(process.title === 'pass' || process.title === title ? 'pass' : 'fail'); 9 | -------------------------------------------------------------------------------- /js/node_modules/fibers/test/stack-overflow.js: -------------------------------------------------------------------------------- 1 | var Fiber = require('fibers'); 2 | try { 3 | Fiber(function() { 4 | function foo() { 5 | var hello = Math.random(); 6 | foo(); 7 | } 8 | foo(); 9 | }).run(); 10 | } catch (err) { 11 | err.name === 'RangeError' && console.log('pass'); 12 | } 13 | -------------------------------------------------------------------------------- /js/node_modules/fibers/test/started.js: -------------------------------------------------------------------------------- 1 | // gh-12 2 | var Fiber = require('fibers'); 3 | Fiber(function() { 4 | if (!Fiber.current.started) { 5 | throw new Error; 6 | } 7 | }).run(); 8 | console.log('pass'); 9 | -------------------------------------------------------------------------------- /js/node_modules/fibers/test/unwind.js: -------------------------------------------------------------------------------- 1 | var Fiber = require('fibers'); 2 | 3 | var ii; 4 | var fn = Fiber(function() { 5 | for (ii = 0; ii < 1000; ++ii) { 6 | try { 7 | Fiber.yield(); 8 | } catch (err) {} 9 | } 10 | }); 11 | 12 | fn.run(); 13 | fn.reset(); 14 | ii === 1000 && console.log('pass'); 15 | -------------------------------------------------------------------------------- /js/segmentfault.js: -------------------------------------------------------------------------------- 1 | 2 | function constfuncs() { 3 | var funcs = []; 4 | for (var i = 0; i < 10; i++) { 5 | funcs[i] = function () { 6 | return i; 7 | }() 8 | } 9 | console.log(i) 10 | return funcs; 11 | } 12 | var funcs = constfuncs(); 13 | console.log(funcs[1]); 14 | console.log(funcs[2]); 15 | -------------------------------------------------------------------------------- /js/sleep.js: -------------------------------------------------------------------------------- 1 | var Fiber = require('fibers'); 2 | 3 | function sleep(ms) { 4 | var fiber = Fiber.current; 5 | setTimeout(function(){ 6 | fiber.run(); 7 | }, ms); 8 | Fiber.yield(); 9 | } 10 | 11 | Fiber(function(){ 12 | console.log('wait...' + new Date()); 13 | sleep(1000); 14 | console.log('ok...' + new Date()); 15 | }).run(); 16 | 17 | console.log('back in main'); 18 | 19 | 20 | -------------------------------------------------------------------------------- /js/test.js: -------------------------------------------------------------------------------- 1 | var foo = 0; 2 | var timer = setInterval(function(){ 3 | foo++; 4 | }, 500); 5 | while(1){ 6 | if(foo == 10){ 7 | clearInterval(timer); 8 | break; 9 | } else { 10 | console.log(foo); 11 | } 12 | } 13 | 14 | -------------------------------------------------------------------------------- /js/test2.js: -------------------------------------------------------------------------------- 1 | var x = 1; 2 | var z = 2; 3 | var y = function(x){ 4 | console.log(x); 5 | }; 6 | y(); 7 | (function(x){ 8 | y(); 9 | function y(x) { 10 | console.log(x); 11 | var x = 2; 12 | console.log(x); 13 | } 14 | })(); 15 | -------------------------------------------------------------------------------- /js/test3.js: -------------------------------------------------------------------------------- 1 | var x 2 | console.log(x) 3 | -------------------------------------------------------------------------------- /js/thistest.js: -------------------------------------------------------------------------------- 1 | var name = 'top name'; 2 | function test() { 3 | var name = 'inner'; 4 | console.log(this.name); 5 | } 6 | test() 7 | this.sayHi = test 8 | this.name = name 9 | console.log(this) 10 | -------------------------------------------------------------------------------- /js/timeouttest.js: -------------------------------------------------------------------------------- 1 | var t, sec = 0; 2 | function countDown() { 3 | //clearTimeout(t); 4 | t = setTimeout(countDown, 1000); 5 | sec++; 6 | if(sec == 60) { 7 | clearTimeout(t); 8 | } 9 | console.log(sec); 10 | } 11 | 12 | function test() { 13 | t = setTimeout(countDown, 1000); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /net/programming/readme.md: -------------------------------------------------------------------------------- 1 | 《tcp/ip编程》(尹圣雨著)一书中的代码 2 | 3 | 这本书很不错,因为所有的样例都是可以实际运行的代码 4 | 5 | 用生动的比喻和详实的说明介绍tcp/ip编程的基础知识,行文流畅,思路清晰 6 | 7 | 不像其它的net方面的编程书一样学习给人带来挫败感 8 | 9 | 拿来作为复习和入门材料都非常不错 10 | 11 | 关键是有epoll的系统讲解哦~ 12 | 13 | 目前其它的网络方面的书里都不会讲这个,毕竟是linux内核2.6之后才加的东西,只能在网上零散地查各种资料 14 | -------------------------------------------------------------------------------- /net/programming/tcpip/ch7/readme.md: -------------------------------------------------------------------------------- 1 | int shutdown(int sock, int howto); 2 | 成功返回0,失败返回-1 3 | @sock 需要断开的套接字文件描述符。 4 | @howto 传递断开方式信息,可选值为`SHUT_RD/SHUT_WR/SHUT_RDWR` 5 | 6 | 服务器关闭输出流时向客户端传输EOF 7 | -------------------------------------------------------------------------------- /net/same_port/same_port_outgoing_connections.py: -------------------------------------------------------------------------------- 1 | import socket 2 | s = socket.socket() 3 | s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1) 4 | s2 = socket.socket() 5 | s2.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1) 6 | s.bind(('0.0.0.0', 12345)) 7 | s2.bind(('0.0.0.0', 12345)) 8 | s.connect(('220.181.57.217', 80)) 9 | s2.connect(('54.222.60.252', 80)) 10 | -------------------------------------------------------------------------------- /os/chapter_2/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void test() 5 | { 6 | printf("hello, world!\n"); 7 | } 8 | 9 | int main() 10 | { 11 | test(); 12 | return EXIT_SUCCESS; 13 | } 14 | -------------------------------------------------------------------------------- /os/chapter_2/readme.md: -------------------------------------------------------------------------------- 1 | mac 环境, 2 | 3 | > brew install binutils 4 | 5 | 所有的命令以g开头,例如greadelf,gobjdump 6 | 7 | > gcc -c 8 | 9 | -c Only run preprocess, compile, and assemble steps 10 | 11 | 只运行预处理,编译,汇编 12 | 13 | 也就是说不做链接 14 | 15 | -------------------------------------------------------------------------------- /os/chapter_3/practise/aplusb.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func main() { 4 | var a = 1 5 | var b = 2 6 | var c = a + b 7 | println(c) 8 | } 9 | -------------------------------------------------------------------------------- /os/chapter_3/practise/loop.s: -------------------------------------------------------------------------------- 1 | global _start 2 | 3 | section .text 4 | 5 | _start: 6 | mov rcx, 236 7 | mov rax, 123 8 | 9 | s: 10 | add rax, 123 11 | loop s; 在rcx 变为 0 之前,loop 会一直执行 12 | 13 | mov rax, 60; 'exit' syscall number 14 | xor rdi, rdi 15 | syscall 16 | 17 | -------------------------------------------------------------------------------- /os/chapter_4/func_call.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int add(int a, int b) { 5 | return a + b; 6 | } 7 | 8 | int main(int argv, char ** argc) { 9 | int a = 1; 10 | int b = 2; 11 | printf("%d\n", add(a,b)); 12 | } 13 | -------------------------------------------------------------------------------- /os/chapter_4/more_than_7_params.c: -------------------------------------------------------------------------------- 1 | #include "stdio.h" 2 | #include "stdlib.h" 3 | 4 | void test(long a, long b, long c, long d, long e, long f, long g, long h) { 5 | printf( "%ld\n", a+b+c+d+e+f+g+h); 6 | } 7 | 8 | int main() { 9 | test(1,2,3,4,5,6,7,8); 10 | } 11 | -------------------------------------------------------------------------------- /os/chapter_4/readme.md: -------------------------------------------------------------------------------- 1 | ``` 2 | clang -g more_than_7_params.c 3 | ``` 4 | 5 | 注意参数是怎么从 caller 传到 callee 的 6 | -------------------------------------------------------------------------------- /php/ISO8601.php: -------------------------------------------------------------------------------- 1 | 1, 4 | 'dd' => 2 5 | ]; 6 | print_r($arr); 7 | -------------------------------------------------------------------------------- /php/array_column_test.php: -------------------------------------------------------------------------------- 1 | 'a', 5 | 'quantity' => 2 6 | ], 7 | [ 8 | 'id' => 'b', 9 | 'quantity' => 3 10 | ], 11 | [ 12 | 'id' => 'c', 13 | 'quantity' => 5 14 | ] 15 | ]; 16 | $x = array_column($arr, 'id', 'quantity'); 17 | print_r($x); 18 | 19 | -------------------------------------------------------------------------------- /php/array_combine_test.php: -------------------------------------------------------------------------------- 1 | 'a', "val" => "1"], 4 | ['name' => 'a', "val" => '2'] 5 | ]; 6 | 7 | $keys = array_column($arr, 'name'); 8 | $new_arr = array_combine($keys, $arr); 9 | $new_arr = array_values($new_arr); 10 | print_r($new_arr); 11 | -------------------------------------------------------------------------------- /php/array_slice.php: -------------------------------------------------------------------------------- 1 | 2014, 5 | 'value' => 100 6 | ), array( 7 | 'order_no' => 2014, 8 | 'value' => 130 9 | ) 10 | ); 11 | $key = array_column($arr, 'order_no'); 12 | $arr = array_combine($key, $arr); 13 | print_r($arr); 14 | -------------------------------------------------------------------------------- /php/copydata.php: -------------------------------------------------------------------------------- 1 | query("insert into g_service_worksheet (select * from service_worksheet limit {$offset}, 1000)"); 9 | $offset += 100; 10 | print_r($res); 11 | } 12 | 13 | 14 | -------------------------------------------------------------------------------- /php/csvtest.php: -------------------------------------------------------------------------------- 1 | 1, 'y' => 2], 4 | ['x' => 1, 'y' => 2], 5 | ['x' => 1, 'y' => 2], 6 | ]; 7 | -------------------------------------------------------------------------------- /php/datetest.php: -------------------------------------------------------------------------------- 1 | strtotime('20151212')) { 6 | echo 'yes'; 7 | }else { 8 | echo 'no'; 9 | } 10 | -------------------------------------------------------------------------------- /php/decode_test.php: -------------------------------------------------------------------------------- 1 | array(1,2), 6 | 'content' => 'ssss' 7 | ]; 8 | var_dump($arr); 9 | var_dump(json_encode($new_arr)); 10 | -------------------------------------------------------------------------------- /php/dump.rdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cch123/test/8a9d3dd4fbd3eecceaf4d77eb6cb56ca4e1528b9/php/dump.rdb -------------------------------------------------------------------------------- /php/equaltest.php: -------------------------------------------------------------------------------- 1 | 1, 4 | "products" => [ 5 | [ 6 | "id" => 42, 7 | "quantity" => 3 8 | ], 9 | [ 10 | "id" => 43, 11 | "quantity" => 2 12 | ] 13 | ] 14 | ]; 15 | echo json_encode($arr); 16 | -------------------------------------------------------------------------------- /php/func_test.php: -------------------------------------------------------------------------------- 1 | test(); 10 | -------------------------------------------------------------------------------- /php/mb_substr.php: -------------------------------------------------------------------------------- 1 | 15810540851, 4 | 'content' => '您的订单已经发货,请注意查收', 5 | ); 6 | echo json_encode($x); 7 | 8 | -------------------------------------------------------------------------------- /php/multisort.php: -------------------------------------------------------------------------------- 1 | 'xlex', 'age' => 44 5 | ], 6 | [ 7 | 'name' => 'aaa', 'age' => 55 8 | ] 9 | ]; 10 | 11 | $names = array_column($arr, 'name'); 12 | $ages = array_column($arr,'age'); 13 | array_multisort($ages, SORT_ASC, $arr); 14 | print_r($arr); 15 | array_multisort($names, SORT_ASC, $arr); 16 | print_r($arr); 17 | -------------------------------------------------------------------------------- /php/nodirect.php: -------------------------------------------------------------------------------- 1 | connect("127.0.0.1", 6379); 4 | $setRes = $redis->set("a",1); 5 | var_dump($connRes); 6 | var_dump($setRes); 7 | -------------------------------------------------------------------------------- /php/redis_subtest.php: -------------------------------------------------------------------------------- 1 | connect('127.0.0.1', 6379); 4 | $redis->subscribe(array("channel-1"), function($redis, $chan, $msg){ 5 | echo $msg; 6 | }); 7 | -------------------------------------------------------------------------------- /php/sort.php: -------------------------------------------------------------------------------- 1 | ['sdfsdf'], 4 | 'sss' => ['sz'], 5 | 'x' => [] 6 | ]; 7 | print_r($arr); 8 | unset($arr[1]); 9 | unset($arr['sss']); 10 | unset($arr['x']); 11 | var_dump($arr); 12 | -------------------------------------------------------------------------------- /python/checkAll.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | import requests 3 | import json 4 | 5 | if __name__ == "__main__": 6 | data = {"sid" : "flash", "checkDate" : "2017-05-09", "cityId" : "0"} 7 | headers = {"x-header-id" : "111"} 8 | # post a form 9 | r = requests.post("www.baidu.com", data=data, headers = headers) 10 | print r.text 11 | 12 | -------------------------------------------------------------------------------- /python/dict_init.py: -------------------------------------------------------------------------------- 1 | import datetime 2 | if __name__ == "__main__": 3 | result = { 4 | "a" : datetime.datetime.now().strftime("%Y%m%d %H:%M:%S") 5 | } 6 | print result 7 | -------------------------------------------------------------------------------- /python/for_range.py: -------------------------------------------------------------------------------- 1 | for i in range(1,10): 2 | print i 3 | -------------------------------------------------------------------------------- /python/get_cpu.py: -------------------------------------------------------------------------------- 1 | import psutil 2 | import time 3 | 4 | p = psutil.Process(1) 5 | 6 | while 1: 7 | v = str(p.cpu_percent()) 8 | if "0.0" != v: 9 | print(111111, v, time.time()) 10 | time.sleep(1) 11 | 12 | -------------------------------------------------------------------------------- /python/guolele/guolele/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cch123/test/8a9d3dd4fbd3eecceaf4d77eb6cb56ca4e1528b9/python/guolele/guolele/__init__.py -------------------------------------------------------------------------------- /python/guolele/guolele/__init__.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cch123/test/8a9d3dd4fbd3eecceaf4d77eb6cb56ca4e1528b9/python/guolele/guolele/__init__.pyc -------------------------------------------------------------------------------- /python/guolele/guolele/items.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cch123/test/8a9d3dd4fbd3eecceaf4d77eb6cb56ca4e1528b9/python/guolele/guolele/items.pyc -------------------------------------------------------------------------------- /python/guolele/guolele/pipelines.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # Define your item pipelines here 4 | # 5 | # Don't forget to add your pipeline to the ITEM_PIPELINES setting 6 | # See: http://doc.scrapy.org/en/latest/topics/item-pipeline.html 7 | 8 | 9 | class GuolelePipeline(object): 10 | def process_item(self, item, spider): 11 | return item 12 | -------------------------------------------------------------------------------- /python/guolele/guolele/settings.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cch123/test/8a9d3dd4fbd3eecceaf4d77eb6cb56ca4e1528b9/python/guolele/guolele/settings.pyc -------------------------------------------------------------------------------- /python/guolele/guolele/spiders/__init__.py: -------------------------------------------------------------------------------- 1 | # This package will contain the spiders of your Scrapy project 2 | # 3 | # Please refer to the documentation for information on how to create and manage 4 | # your spiders. 5 | -------------------------------------------------------------------------------- /python/guolele/guolele/spiders/__init__.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cch123/test/8a9d3dd4fbd3eecceaf4d77eb6cb56ca4e1528b9/python/guolele/guolele/spiders/__init__.pyc -------------------------------------------------------------------------------- /python/guolele/guolele/spiders/guolele_spider.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cch123/test/8a9d3dd4fbd3eecceaf4d77eb6cb56ca4e1528b9/python/guolele/guolele/spiders/guolele_spider.pyc -------------------------------------------------------------------------------- /python/guolele/scrapy.cfg: -------------------------------------------------------------------------------- 1 | # Automatically created by: scrapy startproject 2 | # 3 | # For more information about the [deploy] section see: 4 | # https://scrapyd.readthedocs.org/en/latest/deploy.html 5 | 6 | [settings] 7 | default = guolele.settings 8 | 9 | [deploy] 10 | #url = http://localhost:6800/ 11 | project = guolele 12 | -------------------------------------------------------------------------------- /python/osArgs.py: -------------------------------------------------------------------------------- 1 | import datetime 2 | import sys 3 | 4 | def main(): 5 | if len(sys.argv[1:]) == 0: 6 | print "Param number error\n Pleaserun script likt python xxx.py 20150432" 7 | sys.exit() 8 | 9 | dt = datetime.datetime.strptime(sys.argv[1], "%Y%m%d") 10 | print dt 11 | 12 | if __name__ == "__main__": 13 | main() 14 | -------------------------------------------------------------------------------- /python/otp.py: -------------------------------------------------------------------------------- 1 | import pyotp 2 | totp = pyotp.TOTP("2SVVV5X3W4DJWBCX") 3 | print("Current OTP:", totp.now()) 4 | 5 | -------------------------------------------------------------------------------- /python/timedelta.py: -------------------------------------------------------------------------------- 1 | import datetime 2 | 3 | yearAgoStr = (datetime.datetime.now() + datetime.timedelta(days = -365)).strftime("%Y-%m-%d 00:00:00") 4 | todayStr = datetime.datetime.now().strftime("%Y-%m-%d 00:00:00") 5 | 6 | cond = "where create_time >= '%s' and create_time < '%s'" %(yearAgoStr, todayStr) 7 | 8 | print cond 9 | -------------------------------------------------------------------------------- /rabbitmq/delivery_confirm/readme.md: -------------------------------------------------------------------------------- 1 | 收到confirm说明消息已经放在了队列里 2 | 3 | 这时候启动消费者,可以拿到之前堆积在队列里的消息 4 | 5 | 但hello world里的例子是不行的 6 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /rust/1.40/non_exhaustive/a/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "a" 3 | version = "0.1.0" 4 | authors = ["Xargin "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /rust/1.40/non_exhaustive/a/src/lib.rs: -------------------------------------------------------------------------------- 1 | #[non_exhaustive] 2 | #[derive(Debug)] 3 | pub struct Person { 4 | age : i32, 5 | height : i32, 6 | } 7 | 8 | pub fn New() -> Person { 9 | Person {age :1, height : 2} 10 | } 11 | 12 | -------------------------------------------------------------------------------- /rust/1.40/non_exhaustive/b/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "b" 3 | version = "0.1.0" 4 | authors = ["Xargin "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | a = {path = "../a"} 11 | -------------------------------------------------------------------------------- /rust/1.40/non_exhaustive/b/src/main.rs: -------------------------------------------------------------------------------- 1 | use a::Person; 2 | use a::New; 3 | fn main() { 4 | /* 5 | error[E0639]: cannot create non-exhaustive struct using struct expression 6 | --> src/main.rs:3:13 7 | | 8 | 3 | let p = Person {age :1}; 9 | | 10 | */ 11 | dbg!(New()); 12 | } 13 | -------------------------------------------------------------------------------- /rust/1.42/hello/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "hello" 3 | version = "0.1.0" 4 | authors = ["Xargin "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /rust/1.43/hello/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "hello" 3 | version = "0.1.0" 4 | authors = ["Xargin "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /rust/actix/actix_test/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "actix_test" 3 | version = "0.1.0" 4 | authors = ["Xargin "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | actix-web = "1.0" 9 | futures = "0.1.25" 10 | http = "0.1.0" 11 | actix-http = "0.2.3" 12 | 13 | [dev-dependencies] 14 | env_logger = "0.6" -------------------------------------------------------------------------------- /rust/assoc/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "assoc" 5 | version = "0.1.0" 6 | 7 | -------------------------------------------------------------------------------- /rust/assoc/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "assoc" 3 | version = "0.1.0" 4 | authors = ["Xargin "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /rust/assoc2/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "assoc2" 5 | version = "0.1.0" 6 | 7 | -------------------------------------------------------------------------------- /rust/assoc2/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "assoc2" 3 | version = "0.1.0" 4 | authors = ["Xargin "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /rust/assoc3/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "assoc3" 5 | version = "0.1.0" 6 | 7 | -------------------------------------------------------------------------------- /rust/assoc3/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "assoc3" 3 | version = "0.1.0" 4 | authors = ["Xargin "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /rust/assoc3/readme.md: -------------------------------------------------------------------------------- 1 | 使用 assoc type 重构后的例子,可以和 assoc2 对比一下代码。 2 | 3 | 不需要在声明泛型和实例化泛型的时候传一大堆参数了 4 | 5 | -------------------------------------------------------------------------------- /rust/astd_load_test/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "asyncstd_load_test" 3 | version = "0.1.0" 4 | authors = ["Xargin "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /rust/async_tcp_server/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "async_tcp_server" 3 | version = "0.1.0" 4 | authors = ["xargin "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | tokio = { version = "0.2", features = ["full"] } 11 | futures = { version = "0.3", features = ["async-await"] } 12 | -------------------------------------------------------------------------------- /rust/asyncstd/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "asyncstd" 3 | version = "0.1.0" 4 | authors = ["xargin "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | async-std = { version = "1.4.0" , features = ["unstable"] } 11 | futures = "0.3.1" 12 | -------------------------------------------------------------------------------- /rust/box_arr/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "box_arr" 5 | version = "0.1.0" 6 | 7 | -------------------------------------------------------------------------------- /rust/box_arr/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "box_arr" 3 | version = "0.1.0" 4 | authors = ["Xargin "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /rust/box_arr/src/main.rs: -------------------------------------------------------------------------------- 1 | #[derive(Debug)] 2 | struct Solution { 3 | x : Box<[i32]>, 4 | y : [i32;3], 5 | //z : [i32], -> println!("{:?}", s); 6 | // ^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time 7 | } 8 | 9 | fn main() { 10 | let s = Solution { 11 | x : Box::new([1,2]), 12 | y : [3,2,1], 13 | }; 14 | println!("{:?}", s); 15 | } 16 | -------------------------------------------------------------------------------- /rust/box_linklist/Cargo.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = "box_linklist" 3 | version = "0.1.0" 4 | 5 | -------------------------------------------------------------------------------- /rust/box_linklist/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "box_linklist" 3 | version = "0.1.0" 4 | authors = ["Xargin "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | -------------------------------------------------------------------------------- /rust/channel/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "channel" 3 | version = "0.1.0" 4 | authors = ["xargin "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | tokio = "0.2.0-alpha.6" 11 | futures = { version = "0.3", features = ["async-await"] } 12 | -------------------------------------------------------------------------------- /rust/closure/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "closure" 5 | version = "0.1.0" 6 | 7 | -------------------------------------------------------------------------------- /rust/closure/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "closure" 3 | version = "0.1.0" 4 | authors = ["Xargin "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /rust/combine/demo/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "demo" 3 | version = "0.1.0" 4 | authors = ["xargin "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | combine = "3.3.0" -------------------------------------------------------------------------------- /rust/combine/demo/src/main.rs: -------------------------------------------------------------------------------- 1 | extern crate combine; 2 | use combine::char::char; 3 | use combine::{Parser, many1}; 4 | 5 | fn main() { 6 | let r = many1::(char('a').or(char('b'))).parse("aaaabbbbabababab"); 7 | match r { 8 | Ok((value, remaining)) => println!("value: {} remaining: {}", value,remaining), 9 | Err(err) => println!("{}", err) 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /rust/csv_parser/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "csv_parser" 3 | version = "0.1.0" 4 | authors = ["Xargin "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | pest = "2.0" 9 | pest_derive = "2.0" 10 | 11 | -------------------------------------------------------------------------------- /rust/csv_parser/numbers.csv: -------------------------------------------------------------------------------- 1 | 65279,1179403647,1463895090 2 | 3.1415927,2.7182817,1.618034 3 | -40,-273.15 4 | 13,42 5 | 65537 6 | 7 | -------------------------------------------------------------------------------- /rust/csv_parser/src/csv.pest: -------------------------------------------------------------------------------- 1 | field = { (ASCII_DIGIT | "." | "-")+ } 2 | record = { field ~ ("," ~ field)* } 3 | file = { SOI ~ (record ~ ("\r\n" | "\n"))* ~ EOI } 4 | -------------------------------------------------------------------------------- /rust/elastic_test/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "elastic_test" 3 | version = "0.1.0" 4 | authors = ["Xargin "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | elastic_query = "0.1.0" 9 | -------------------------------------------------------------------------------- /rust/elastic_test/src/main.rs: -------------------------------------------------------------------------------- 1 | extern crate elastic_query; 2 | 3 | fn main() { 4 | let result = elastic_query::convert("a = 1 and b in (1,2,3)".to_string(), 0, 100, vec![], vec![]).unwrap(); 5 | println!("{}", result); 6 | } 7 | -------------------------------------------------------------------------------- /rust/expr_test/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "expr_test" 3 | version = "0.1.0" 4 | authors = ["Xargin "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | pest = "2.0" 9 | pest_derive = "2.0" 10 | -------------------------------------------------------------------------------- /rust/flat_map/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "flat_map" 5 | version = "0.1.0" 6 | 7 | -------------------------------------------------------------------------------- /rust/flat_map/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "flat_map" 3 | version = "0.1.0" 4 | authors = ["Xargin "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /rust/future-impl/executor/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "executor" 3 | version = "0.1.0" 4 | authors = ["Xargin "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | #futures = { version = "0.3.1", features = ["full"] } 11 | futures = "0.3.1" 12 | -------------------------------------------------------------------------------- /rust/future-impl/executor/src/main.rs: -------------------------------------------------------------------------------- 1 | pub mod executor; 2 | 3 | fn main() { 4 | let (executor, spawner) = executor::new_executor_and_spawner(); 5 | 6 | spawner.spawn(async { 7 | println!("hello in async 1"); 8 | println!("world in async 2"); 9 | }); 10 | 11 | drop(spawner); 12 | executor.run(); 13 | } 14 | -------------------------------------------------------------------------------- /rust/future-impl/simple_poll/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "simple_poll" 3 | version = "0.1.0" 4 | authors = ["Xargin "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | futures = "0.3" 11 | -------------------------------------------------------------------------------- /rust/future-impl/simplefuture/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "future-impl" 3 | version = "0.1.0" 4 | authors = ["Xargin "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /rust/future-impl/simplefuture/src/main.rs: -------------------------------------------------------------------------------- 1 | pub mod future; 2 | 3 | fn main() { 4 | } 5 | -------------------------------------------------------------------------------- /rust/hashmap/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "hashmap" 5 | version = "0.1.0" 6 | 7 | -------------------------------------------------------------------------------- /rust/hashmap/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "hashmap" 3 | version = "0.1.0" 4 | authors = ["xargin "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /rust/httparse/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "httparse" 3 | version = "0.1.0" 4 | authors = ["Xargin "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | httparse = "1.3.4" -------------------------------------------------------------------------------- /rust/iter/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "iter" 3 | version = "0.1.0" 4 | authors = ["Xargin "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /rust/iter/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let mut v = vec![1,2,3]; 3 | v.iter().for_each(|e| { 4 | println!("{}", e); 5 | }); 6 | 7 | (0..10).for_each(|e| { 8 | println!("{}", e); 9 | }); 10 | 11 | println!("{:?}", v.iter().map(|e| e + 1).collect::>()); 12 | v.iter_mut().for_each(|e| {*e = 1}); 13 | dbg!(v); 14 | } 15 | -------------------------------------------------------------------------------- /rust/lazy_static/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "lazy_static" 3 | version = "0.1.0" 4 | authors = ["xargin "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | lazy_static = "1.3.0" 11 | -------------------------------------------------------------------------------- /rust/lifetime_test/Cargo.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = "lifetime_test" 3 | version = "0.1.0" 4 | 5 | -------------------------------------------------------------------------------- /rust/lifetime_test/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "lifetime_test" 3 | version = "0.1.0" 4 | authors = ["xargin "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | -------------------------------------------------------------------------------- /rust/load_test/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "load_test" 3 | version = "0.1.0" 4 | authors = ["Xargin "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | async-std = "1" 11 | futures = "0.3" 12 | -------------------------------------------------------------------------------- /rust/loop_time_and_mul_threads_join/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "loop_time_cost" 3 | version = "0.1.0" 4 | authors = ["Xargin "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /rust/maplit/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "atomic": "cpp", 4 | "stdio.h": "c", 5 | "stdatomic.h": "c", 6 | "pthread.h": "c" 7 | } 8 | } -------------------------------------------------------------------------------- /rust/maplit/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "maplit" 3 | version = "0.1.0" 4 | authors = ["Xargin "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | maplit = "1.0" 11 | unicorn = "0.9.1" 12 | 13 | -------------------------------------------------------------------------------- /rust/mio_test/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mio_test" 3 | version = "0.1.0" 4 | authors = ["Xargin "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | mio = { git = "https://github.com/tokio-rs/mio" , features = ["os-poll", "tcp"] } 11 | 12 | -------------------------------------------------------------------------------- /rust/module_test/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "module_test" 3 | version = "0.1.0" 4 | authors = ["Xargin "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /rust/module_test/src/array.rs: -------------------------------------------------------------------------------- 1 | pub(super) fn print() { 2 | println!("{}", "this is in module crate::array"); 3 | } -------------------------------------------------------------------------------- /rust/module_test/src/inner/go.rs: -------------------------------------------------------------------------------- 1 | pub(crate) fn print_gogo() { 2 | println!("{}", "this is in mod inner::go") 3 | } 4 | -------------------------------------------------------------------------------- /rust/module_test/src/inner/mod.rs: -------------------------------------------------------------------------------- 1 | //pub(in crate::list), 2 | //pub(in crate::array) mod go; 3 | // 上面这些都是会报错的 4 | pub mod go; -------------------------------------------------------------------------------- /rust/module_test/src/list.rs: -------------------------------------------------------------------------------- 1 | use crate::inner::go; 2 | pub(super) fn print() { 3 | println!("{}", "this is in module crate::list"); 4 | go::print_gogo(); 5 | } -------------------------------------------------------------------------------- /rust/module_test/src/main.rs: -------------------------------------------------------------------------------- 1 | pub mod list; 2 | pub mod array; 3 | pub mod inner; 4 | 5 | fn main() { 6 | list::print(); 7 | array::print(); 8 | } 9 | -------------------------------------------------------------------------------- /rust/net2_test/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "net2_test" 3 | version = "0.1.0" 4 | authors = ["Xargin "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | net2 = "0.2.33" 11 | tokio = {version = "0.2", features = ["full"]} 12 | -------------------------------------------------------------------------------- /rust/ngx_rs/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ngx_rs" 3 | version = "0.1.0" 4 | authors = ["Xargin "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /rust/ngx_rs/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | println!("Hello, world!"); 3 | } 4 | -------------------------------------------------------------------------------- /rust/nom/basic/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "basic" 3 | version = "0.1.0" 4 | authors = ["xargin "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | nom = "4.2.0" 9 | 10 | -------------------------------------------------------------------------------- /rust/partial_eq/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "partial_eq" 5 | version = "0.1.0" 6 | 7 | -------------------------------------------------------------------------------- /rust/partial_eq/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "partial_eq" 3 | version = "0.1.0" 4 | authors = ["Xargin "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /rust/pest_test/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /rust/pest_test/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | -------------------------------------------------------------------------------- /rust/pest_test/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /rust/pest_test/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /rust/pest_test/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "pest_test" 3 | version = "0.1.0" 4 | authors = ["Xargin "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | pest = "2.0" 9 | pest_derive = "2.0" 10 | -------------------------------------------------------------------------------- /rust/pest_test/src/ident.pest: -------------------------------------------------------------------------------- 1 | alpha = { 'a'..'z' | 'A'..'Z' } 2 | digit = { '0'..'9' } 3 | 4 | ident = { (alpha | digit)+ } 5 | 6 | ident_list = _{ !digit ~ ident ~ (" " ~ ident)+ } 7 | // ^ 8 | // ident_list rule is silent which means it produces no tokens 9 | -------------------------------------------------------------------------------- /rust/phantomdata/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "phantomdata" 5 | version = "0.1.0" 6 | 7 | -------------------------------------------------------------------------------- /rust/phantomdata/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "phantomdata" 3 | version = "0.1.0" 4 | authors = ["Xargin "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /rust/prec_climber_test/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "prec_climber_test" 3 | version = "0.1.0" 4 | authors = ["xargin "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | pest = "2.0" 9 | pest_derive = "2.0" 10 | serde_json = "1.0.37" 11 | rustyline = "1" 12 | -------------------------------------------------------------------------------- /rust/print_file_and_line/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "print_file_and_line" 5 | version = "0.1.0" 6 | 7 | -------------------------------------------------------------------------------- /rust/print_file_and_line/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "print_file_and_line" 3 | version = "0.1.0" 4 | authors = ["xargin "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /rust/print_file_and_line/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | println!("file : {}; line : {};", file!(), line!()); 3 | } 4 | -------------------------------------------------------------------------------- /rust/proc_macro_workshop/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "proc_macro_workshop" 3 | version = "0.1.0" 4 | authors = ["Xargin "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /rust/proc_macro_workshop/src/debug.rs: -------------------------------------------------------------------------------- 1 | #[macro_export] 2 | macro_rules! each_tt { 3 | () => {}; 4 | ($_tt:tt $($rest:tt)*) => {each_tt!($($rest)*);}; 5 | } 6 | -------------------------------------------------------------------------------- /rust/proc_macro_workshop/src/easy.rs: -------------------------------------------------------------------------------- 1 | #[macro_export] // macro_export 会把这个 macro export 到 crate:: 根部 2 | macro_rules! four { 3 | () => { 4 | 1 + 3 5 | }; 6 | } 7 | -------------------------------------------------------------------------------- /rust/programming_rust/ch1/cmd_args/Cargo.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = "cmd_args" 3 | version = "0.1.0" 4 | 5 | -------------------------------------------------------------------------------- /rust/programming_rust/ch1/cmd_args/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "cmd_args" 3 | version = "0.1.0" 4 | authors = ["Xargin "] 5 | 6 | [dependencies] 7 | -------------------------------------------------------------------------------- /rust/programming_rust/ch1/gcd/Cargo.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = "gcd" 3 | version = "0.1.0" 4 | 5 | -------------------------------------------------------------------------------- /rust/programming_rust/ch1/gcd/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "gcd" 3 | version = "0.1.0" 4 | authors = ["Xargin "] 5 | 6 | [dependencies] 7 | -------------------------------------------------------------------------------- /rust/programming_rust/ch1/hello/Cargo.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = "hello" 3 | version = "0.1.0" 4 | 5 | -------------------------------------------------------------------------------- /rust/programming_rust/ch1/hello/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "hello" 3 | version = "0.1.0" 4 | authors = ["Xargin "] 5 | 6 | [dependencies] 7 | -------------------------------------------------------------------------------- /rust/programming_rust/ch1/hello/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | println!("Hello, world!"); 3 | } 4 | -------------------------------------------------------------------------------- /rust/programming_rust/ch1/hello/target/rls/debug/.cargo-lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cch123/test/8a9d3dd4fbd3eecceaf4d77eb6cb56ca4e1528b9/rust/programming_rust/ch1/hello/target/rls/debug/.cargo-lock -------------------------------------------------------------------------------- /rust/programming_rust/ch1/hello/target/rls/debug/.fingerprint/hello-361a3be39b79a777/bin-hello-361a3be39b79a777: -------------------------------------------------------------------------------- 1 | c2380b14145a5419 -------------------------------------------------------------------------------- /rust/programming_rust/ch1/hello/target/rls/debug/.fingerprint/hello-361a3be39b79a777/bin-hello-361a3be39b79a777.json: -------------------------------------------------------------------------------- 1 | {"rustc":17244551033254524728,"features":"[]","target":9265103797016190678,"profile":12391660418100547439,"path":1036222786711178230,"deps":[],"local":[{"MtimeBased":[[1521876703,440289269],".fingerprint/hello-361a3be39b79a777/dep-bin-hello-361a3be39b79a777"]}],"rustflags":["--error-format=json"]} -------------------------------------------------------------------------------- /rust/programming_rust/ch1/hello/target/rls/debug/.fingerprint/hello-361a3be39b79a777/dep-bin-hello-361a3be39b79a777: -------------------------------------------------------------------------------- 1 | src/main.rs -------------------------------------------------------------------------------- /rust/programming_rust/ch1/hello/target/rls/debug/deps/hello-361a3be39b79a777.d: -------------------------------------------------------------------------------- 1 | /Users/caochunhui/test/rust/programming_rust/ch1/hello/target/rls/debug/deps/hello-361a3be39b79a777.rmeta: src/main.rs 2 | 3 | /Users/caochunhui/test/rust/programming_rust/ch1/hello/target/rls/debug/deps/hello-361a3be39b79a777.d: src/main.rs 4 | 5 | src/main.rs: 6 | -------------------------------------------------------------------------------- /rust/programming_rust/ch1/hello/target/rls/debug/libhello.d: -------------------------------------------------------------------------------- 1 | /Users/caochunhui/test/rust/programming_rust/ch1/hello/target/rls/debug/libhello.rmeta: /Users/caochunhui/test/rust/programming_rust/ch1/hello/src/main.rs 2 | -------------------------------------------------------------------------------- /rust/programming_rust/ch1/web-sum/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "web-sum" 3 | version = "0.1.0" 4 | authors = ["Xargin "] 5 | 6 | [dependencies] 7 | iron = "0.5.1" 8 | mime = "0.2.3" 9 | router = "0.5.1" 10 | urlencoded = "0.5.0" 11 | -------------------------------------------------------------------------------- /rust/read_from_stdin/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "read_from_stdin" 3 | version = "0.1.0" 4 | authors = ["Xargin "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /rust/read_from_stdin/readme.md: -------------------------------------------------------------------------------- 1 | echo xxx | cargo run 2 | cargo run 3 | 4 | 怎么在后面这种情况下,要求用户从 pipe 输入? 5 | -------------------------------------------------------------------------------- /rust/read_from_stdin/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::io::{self, Read}; 2 | 3 | fn main() -> io::Result<()> { 4 | let mut buffer = Vec::new(); 5 | io::stdin().read_to_end(&mut buffer)?; 6 | println!("read result : {:?}", String::from_utf8(buffer)); 7 | Ok(()) 8 | } 9 | -------------------------------------------------------------------------------- /rust/refcell_linklist/Cargo.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = "refcell_linklist" 3 | version = "0.1.0" 4 | 5 | -------------------------------------------------------------------------------- /rust/refcell_linklist/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "refcell_linklist" 3 | version = "0.1.0" 4 | authors = ["Xargin "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | -------------------------------------------------------------------------------- /rust/reqwest/example/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "example" 3 | version = "0.1.0" 4 | authors = ["Xargin "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | reqwest = "^0.9.18" 9 | serde_json = "1.0.40" 10 | -------------------------------------------------------------------------------- /rust/rock_test/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rock_test" 3 | version = "0.1.0" 4 | authors = ["Xargin "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | rocket = "0.4.2" 11 | 12 | -------------------------------------------------------------------------------- /rust/rocket_complete_project/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rocket_complete_project" 3 | version = "0.1.0" 4 | authors = ["Xargin "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | rocket = "0.4.2" 11 | toml = "0.5.3" 12 | 13 | -------------------------------------------------------------------------------- /rust/rocket_complete_project/build.rs: -------------------------------------------------------------------------------- 1 | // 该文件应该做一些预处理,例如根据机器初始化 IDC 信息,并根据这些信息,把 conf 2 | // 文件夹中的内容移动到外部 3 | 4 | fn main() { 5 | println!("hello here is the build.rs file~") 6 | } 7 | -------------------------------------------------------------------------------- /rust/rocket_complete_project/src/conf/db.toml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cch123/test/8a9d3dd4fbd3eecceaf4d77eb6cb56ca4e1528b9/rust/rocket_complete_project/src/conf/db.toml -------------------------------------------------------------------------------- /rust/rocket_complete_project/src/conf/etcd.toml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cch123/test/8a9d3dd4fbd3eecceaf4d77eb6cb56ca4e1528b9/rust/rocket_complete_project/src/conf/etcd.toml -------------------------------------------------------------------------------- /rust/rocket_complete_project/src/conf/ratelimit.toml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cch123/test/8a9d3dd4fbd3eecceaf4d77eb6cb56ca4e1528b9/rust/rocket_complete_project/src/conf/ratelimit.toml -------------------------------------------------------------------------------- /rust/rocket_complete_project/src/conf/redis.toml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cch123/test/8a9d3dd4fbd3eecceaf4d77eb6cb56ca4e1528b9/rust/rocket_complete_project/src/conf/redis.toml -------------------------------------------------------------------------------- /rust/rocket_complete_project/src/config/mod.rs: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /rust/rocket_complete_project/src/controller/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod order; 2 | pub mod user; 3 | -------------------------------------------------------------------------------- /rust/rocket_complete_project/src/controller/order.rs: -------------------------------------------------------------------------------- 1 | #![feature(proc_macro_hygiene)] 2 | #![feature(decl_macro)] 3 | 4 | #[get("/info/")] 5 | pub fn get_order_info(id: i64) -> String { 6 | let mut res = "hello this is order detail".to_string(); 7 | res.push_str(&id.to_string()); 8 | res 9 | } 10 | -------------------------------------------------------------------------------- /rust/rocket_complete_project/src/controller/user.rs: -------------------------------------------------------------------------------- 1 | #![feature(proc_macro_hygiene)] 2 | #![feature(decl_macro)] 3 | 4 | #[get("/info/")] 5 | pub fn get_user_info(id: i64) -> String { 6 | "hello here is Xargin".to_string() 7 | } 8 | 9 | #[get("/info/")] 10 | pub fn get_user_info(id: i64) -> String { 11 | "hello here is Xargin".to_string() 12 | } 13 | -------------------------------------------------------------------------------- /rust/rocket_complete_project/src/init.rs: -------------------------------------------------------------------------------- 1 | pub fn init() { 2 | read_config(); 3 | } 4 | 5 | fn read_config() {} 6 | -------------------------------------------------------------------------------- /rust/rocket_complete_project/src/logic/mod.rs: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /rust/rocket_complete_project/src/model/mod.rs: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /rust/rust_book/ch1/borrow_twice.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let mut x = vec!["hello", "world"]; 3 | let y = &x[0]; 4 | x.push("anyway"); 5 | } 6 | -------------------------------------------------------------------------------- /rust/rust_book/ch1/clone.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let mut x = vec!["hello", "world"]; 3 | let y = x[0].clone(); 4 | x.push("anyway"); 5 | } 6 | -------------------------------------------------------------------------------- /rust/rust_book/ch2/cargo/hello_world/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "hello_world" 3 | version = "0.1.0" 4 | authors = ["Xargin "] 5 | 6 | [dependencies] 7 | -------------------------------------------------------------------------------- /rust/rust_book/ch2/cargo/hello_world/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | println!("Hello, world!"); 3 | } 4 | -------------------------------------------------------------------------------- /rust/rust_book/ch2/helloworld.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | println!("hello world!"); 3 | } 4 | -------------------------------------------------------------------------------- /rust/rust_programming_lang/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | **/*.rs.bk 3 | -------------------------------------------------------------------------------- /rust/rust_programming_lang/guess_num/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "hello" 3 | version = "0.1.0" 4 | authors = ["xargin "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | 9 | rand = "0.4.0" 10 | -------------------------------------------------------------------------------- /rust/rustyline_test/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /rust/rustyline_test/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | -------------------------------------------------------------------------------- /rust/rustyline_test/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /rust/rustyline_test/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /rust/rustyline_test/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rustyline_test" 3 | version = "0.1.0" 4 | authors = ["xargin "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | rustyline = "3.0.0" 9 | -------------------------------------------------------------------------------- /rust/serdejson_test/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "serdejson_test" 3 | version = "0.1.0" 4 | authors = ["xargin "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | serde_json = "1.0.37" 9 | 10 | 11 | -------------------------------------------------------------------------------- /rust/thrift_test/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "thrift_test" 3 | version = "0.1.0" 4 | authors = ["Xargin "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | thrift = "0.13.0" 11 | -------------------------------------------------------------------------------- /rust/thrift_test/src/main.rs: -------------------------------------------------------------------------------- 1 | use thrift::transport::*; 2 | 3 | fn main() { 4 | println!("Hello, world!"); 5 | } 6 | -------------------------------------------------------------------------------- /rust/tokio_load_test/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "tokio_runtime" 3 | version = "0.1.0" 4 | authors = ["Xargin "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | tokio = { version = "0.2", features = ["full"]} 11 | futures = "0.3" 12 | -------------------------------------------------------------------------------- /rust/traits/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "generics" 5 | version = "0.1.0" 6 | 7 | -------------------------------------------------------------------------------- /rust/traits/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "generics" 3 | version = "0.1.0" 4 | authors = ["Xargin "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /rust/traits/src/main.rs: -------------------------------------------------------------------------------- 1 | trait P { 2 | fn println(&self, x: i32); 3 | } 4 | 5 | impl P for i32 { 6 | fn println(&self, x: i32) { 7 | println!("{}", x); 8 | } 9 | } 10 | 11 | fn getP() -> impl P { 12 | return 1; 13 | } 14 | 15 | fn main() { 16 | let mut x = 1; 17 | let mut y = getP(); 18 | y.println(10); 19 | } 20 | -------------------------------------------------------------------------------- /scala/lambda/closure2.scala: -------------------------------------------------------------------------------- 1 | //We can take that closure and throw it into a method and it will still hold the environment: 2 | def summation(x: Int, y: Int ⇒ Int) = y(x) 3 | 4 | var incrementer = 3 5 | def closure = (x: Int) ⇒ x + incrementer 6 | 7 | val result = summation(10, closure) 8 | 9 | incrementer = 4 10 | val result2 = summation(10, closure) 11 | 12 | -------------------------------------------------------------------------------- /scala/lambda/lambda.scala: -------------------------------------------------------------------------------- 1 | def lambda = {x: Int => x+1} 2 | def lambda2 = (x:Int) => x+2 3 | def lambda3 = (x:Int) => x+3 4 | 5 | def lambda4 = new Function1[Int, Int] { 6 | def apply(v1: Int) : Int = v1 - 1 7 | } 8 | 9 | def lambda5(x: Int) = x + 1 10 | -------------------------------------------------------------------------------- /scala/lambda/returning_annoymous_function.scala: -------------------------------------------------------------------------------- 1 | def addWithSyntaxSugar(x: Int) = (y: Int) ⇒ x + y 2 | 3 | addWithSyntaxSugar(1).isInstanceOf[Function1[Int, Int]] 4 | 5 | addWithSyntaxSugar(2)(3) 6 | 7 | def fiveAdder = addWithSyntaxSugar(5) 8 | 9 | fiveAdder(5) 10 | 11 | addWithSyntaxSugar(1).isInstanceOf[Function1[_, _]] 12 | -------------------------------------------------------------------------------- /scala/lambda/returning_function.scala: -------------------------------------------------------------------------------- 1 | def addWithoutSyntaxSugar(x: Int): Function1[Int, Int] = { 2 | new Function1[Int, Int]() { 3 | def apply(y: Int): Int = x + y 4 | } 5 | } 6 | 7 | addWithoutSyntaxSugar(1).isInstanceOf[Function1[Int, Int]] 8 | 9 | def fiveAdder: Function1[Int, Int] = addWithoutSyntaxSugar(5) 10 | 11 | fiveAdder(5) 12 | -------------------------------------------------------------------------------- /scala/lists/access_by_position.scala: -------------------------------------------------------------------------------- 1 | val a = List(1,2,3) 2 | 3 | a(0) 4 | a(2) 5 | a(5) 6 | 7 | // ?? 8 | intercept[IndexOutOfBoundsException] { 9 | println(a(5)) 10 | } 11 | -------------------------------------------------------------------------------- /scala/lists/create_from_range.scala: -------------------------------------------------------------------------------- 1 | val a = (1 to 100).toList 2 | 3 | println(a) 4 | -------------------------------------------------------------------------------- /scala/lists/fold_left.scala: -------------------------------------------------------------------------------- 1 | val a = List(1, 3, 5, 7) 2 | 3 | // 和reduce一样,不过foldLeft有个start value 4 | println(a.foldLeft(0)(_ + _)) 5 | println(a.foldLeft(0)(_ * _)) 6 | println(a.foldLeft(10)(_ + _)) 7 | println(a.foldLeft(10)(_ * _)) 8 | 9 | -------------------------------------------------------------------------------- /scala/lists/head_tail.scala: -------------------------------------------------------------------------------- 1 | // head headOption tail 2 | val a = List(1,2,3) 3 | // 注意这两个的区别,scala里的Option是支持为空的head的,但不带option的可能会抛异常 4 | a.head 5 | a.headOption 6 | // tail没有tailOption之类的东西 7 | a.tail 8 | -------------------------------------------------------------------------------- /scala/lists/immutable.scala: -------------------------------------------------------------------------------- 1 | val a = List(1, 3, 5, 7, 9) 2 | val b = a.filterNot(v ⇒ v == 5) // remove where value is 5 3 | 4 | println(a) 5 | println(b) 6 | -------------------------------------------------------------------------------- /scala/lists/list.scala: -------------------------------------------------------------------------------- 1 | // 注意,和 java 是反着的 2 | //eq tests identity (same object): 3 | val a = List(1, 2, 3) 4 | val b = List(1, 2, 3) 5 | (a eq b) 6 | 7 | //== tests equality (same content): 8 | val a = List(1, 2, 3) 9 | val b = List(1, 2, 3) 10 | (a == b) 11 | -------------------------------------------------------------------------------- /scala/lists/list_methods.scala: -------------------------------------------------------------------------------- 1 | val a = List(1, 3, 5, 7, 9) 2 | 3 | println(a.length) 4 | 5 | println(a.reverse) 6 | println(a) 7 | 8 | a.map { 9 | v => v * 100 10 | } 11 | 12 | println(a) 13 | 14 | a.filter { 15 | v => v % 3 == 0 16 | } 17 | 18 | println(a) 19 | 20 | // 上面的操作都会生成新的列表,并不会影响到原始的对象 21 | -------------------------------------------------------------------------------- /scala/lists/nil_compare.scala: -------------------------------------------------------------------------------- 1 | val a: List[String] = Nil 2 | val b: List[Int] = Nil 3 | 4 | a == Nil 5 | a eq Nil 6 | 7 | b == Nil 8 | b eq Nil 9 | 10 | // 上面的比较全都是 true 11 | -------------------------------------------------------------------------------- /scala/lists/reduce_list.scala: -------------------------------------------------------------------------------- 1 | val a = List(1,2,3, 10) 2 | 3 | println(a.reduceLeft(_ + _)) 4 | println(a.reduceLeft(_* _)) 5 | -------------------------------------------------------------------------------- /scala/lists/short_hand.scala: -------------------------------------------------------------------------------- 1 | val a = List(1,2,3) 2 | 3 | println(a.map{ _* 10}) 4 | 5 | println(a.filter{ _ % 2 == 0}) 6 | -------------------------------------------------------------------------------- /scala/lists/tail_reuse.scala: -------------------------------------------------------------------------------- 1 | val d = Nil 2 | 3 | val c = 3 :: d 4 | val b = 2 :: c 5 | val a = 1 ::b 6 | println(a) 7 | println(b) 8 | println(c) 9 | println(d) 10 | 11 | println(a.tail) 12 | println(b.tail) 13 | println(c.tail) 14 | //println(d.tail) exception 15 | -------------------------------------------------------------------------------- /scala/lists/use_paren.scala: -------------------------------------------------------------------------------- 1 | // 在 list 上进行操作的 function 可以用 () 代替 {} 2 | val a = List(1, 2, 3) 3 | a.map(_ * 2) 4 | a.filter(_ % 2 != 0) 5 | -------------------------------------------------------------------------------- /scala/map/basic_def.scala: -------------------------------------------------------------------------------- 1 | val myMap = Map("Mi" -> 100, "A" -> 1) 2 | 3 | val myMap2 = Map(("a" ,1), ("b",2)) 4 | 5 | println(myMap) 6 | println(myMap2) 7 | -------------------------------------------------------------------------------- /scala/object.scala: -------------------------------------------------------------------------------- 1 | // object 和 java 的静态方法类似,但实际上却是一个全局一致的单例 2 | 3 | object Greeting { 4 | def english = "Hi" 5 | def chn = "艹" 6 | } 7 | 8 | println(Greeting.english) 9 | println(Greeting.chn) 10 | -------------------------------------------------------------------------------- /scala/object_is_singleton.scala: -------------------------------------------------------------------------------- 1 | // 单例证明 2 | object Greeting { 3 | def english = "Hi" 4 | def chn = "艹" 5 | } 6 | 7 | val x = Greeting 8 | val y = x 9 | val z = Greeting 10 | println(x eq y) 11 | println(x eq z) 12 | -------------------------------------------------------------------------------- /scala/rdd/rdd.txt: -------------------------------------------------------------------------------- 1 | 10 1 x 2 | -------------------------------------------------------------------------------- /scala/readme.md: -------------------------------------------------------------------------------- 1 | 运行脚本: 2 | 3 | scala xxxx.scala 4 | -------------------------------------------------------------------------------- /scala/spark/test.scala: -------------------------------------------------------------------------------- 1 | import org.apache.spark.sql.hive.HiveContext 2 | 3 | val hiveCtx = new HiveContext(sc) 4 | 5 | val studentRDD = hiveCtx.sql("select * from test.user").rdd 6 | 7 | studentRDD 8 | 9 | -------------------------------------------------------------------------------- /scala/tuple/tuple.scala: -------------------------------------------------------------------------------- 1 | val t = (1, "hello", Console) 2 | 3 | // is short for 4 | 5 | val t3 = new Tuple3(1, "hello", Console) 6 | 7 | val tuple = ("apple", "dog") 8 | val fruit = tuple._1 9 | val animal = tuple._2 10 | 11 | //val tuple5 = ("a", 1, 2.2, new Date(), "five") 12 | 13 | val student = ("Sean Rogers", 21, 3.5) 14 | val (name, age, gpa) = student 15 | 16 | val tuplex = ("apple", 3).swap 17 | 18 | -------------------------------------------------------------------------------- /shell/awk/dat.txt: -------------------------------------------------------------------------------- 1 | 32323423423123 2 | 32323423423103 3 | 32323423423112 4 | 32323423423143 5 | 32323423423153 6 | 32323423423113 7 | 32323423423112 8 | -------------------------------------------------------------------------------- /shell/awk/fix.sh: -------------------------------------------------------------------------------- 1 | #!bin/bash 2 | counter=0 3 | slCounter=100 4 | while read line 5 | do 6 | mysql -h127.0.0.1 -uroot -p123456 -e "$line" 7 | echo $line 8 | counter=$(($counter+1)) 9 | echo $counter 10 | 11 | if [ $counter -eq $slCounter ] 12 | then 13 | sleep 1 14 | counter=0 15 | echo "oh yes" 16 | fi 17 | done < res.txt 18 | 19 | -------------------------------------------------------------------------------- /shell/awk/test.awk: -------------------------------------------------------------------------------- 1 | { 2 | x = $1 % 1000 3 | #print x 4 | driver_id = $1 5 | order_id = $2 6 | print "update db_name.table_name"driver_id % 1000 , "set star = 5 where order_id = " driver_id ";" 7 | #print order_id 8 | } 9 | 10 | -------------------------------------------------------------------------------- /shell/download.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | servers=("" "" "" "") 4 | yesterday=`date +%Y%m%d --date="-1 day"` 5 | today=`date '+%Y%m%d'` 6 | day=$1 7 | if [ ! $day ]; 8 | then 9 | day=$yesterday 10 | fi 11 | path="/home/logs/x.log" 12 | 13 | 14 | for var in ${servers[*]} 15 | do 16 | 17 | scp -l 30000 $var:$path$day ./$var.$day 18 | 19 | done 20 | 21 | -------------------------------------------------------------------------------- /shell/expect: -------------------------------------------------------------------------------- 1 | #!/usr/bin/sh 2 | user=$1 3 | if [[ $user -eq "me" ]]; 4 | then 5 | expect << EOF 6 | set timeout 30 7 | spawn ssh root@10.10.38.89 -o StrictHostKeyChecking=no 8 | expect "password" 9 | send "iovVmVI!@vm\r" 10 | expect eof 11 | EOF 12 | fi 13 | -------------------------------------------------------------------------------- /shell/forloop.sh: -------------------------------------------------------------------------------- 1 | #!bin/bash 2 | for i in `seq 10000` 3 | do 4 | ./ttt 5 | done 6 | -------------------------------------------------------------------------------- /shell/simple_loop.sh: -------------------------------------------------------------------------------- 1 | #!bin/bash 2 | 3 | for i in `seq 30` 4 | do 5 | # execute your bash command here 6 | done 7 | -------------------------------------------------------------------------------- /syscall/what_is_backlog.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cch123/test/8a9d3dd4fbd3eecceaf4d77eb6cb56ca4e1528b9/syscall/what_is_backlog.md -------------------------------------------------------------------------------- /syscall/what_is_fork.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cch123/test/8a9d3dd4fbd3eecceaf4d77eb6cb56ca4e1528b9/syscall/what_is_fork.md -------------------------------------------------------------------------------- /syscall/what_is_malloc.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cch123/test/8a9d3dd4fbd3eecceaf4d77eb6cb56ca4e1528b9/syscall/what_is_malloc.md -------------------------------------------------------------------------------- /syscall/what_is_mmap.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cch123/test/8a9d3dd4fbd3eecceaf4d77eb6cb56ca4e1528b9/syscall/what_is_mmap.md -------------------------------------------------------------------------------- /syscall/what_is_sendfile.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cch123/test/8a9d3dd4fbd3eecceaf4d77eb6cb56ca4e1528b9/syscall/what_is_sendfile.md -------------------------------------------------------------------------------- /uml/activity.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cch123/test/8a9d3dd4fbd3eecceaf4d77eb6cb56ca4e1528b9/uml/activity.png -------------------------------------------------------------------------------- /uml/activity.txt: -------------------------------------------------------------------------------- 1 | @startuml 2 | 3 | scale 1024*768 4 | 5 | start 6 | 7 | if (exec Lazarus?) then (yes) 8 | :find a livable planet; 9 | :save **human beings**; 10 | else (no) 11 | :keep adapting, 12 | __keep farming__ and keep dying; 13 | endif 14 | 15 | stop 16 | 17 | @enduml 18 | 19 | -------------------------------------------------------------------------------- /uml/activity_icons.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cch123/test/8a9d3dd4fbd3eecceaf4d77eb6cb56ca4e1528b9/uml/activity_icons.png -------------------------------------------------------------------------------- /uml/activity_icons.txt: -------------------------------------------------------------------------------- 1 | @startuml 2 | scale 2 3 | :Ready; 4 | :next(o)| 5 | :Receiving; 6 | split 7 | :nak(i)< 8 | :ack(o)> 9 | split again 10 | :ack(i)< 11 | :next(o) 12 | on several line| 13 | :i := i + 1] 14 | :ack(o)> 15 | split again 16 | :err(i)< 17 | :nak(o)> 18 | split again 19 | :foo/ 20 | split again 21 | :i > 5} 22 | stop 23 | end split 24 | :finish; 25 | @enduml 26 | -------------------------------------------------------------------------------- /uml/actor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cch123/test/8a9d3dd4fbd3eecceaf4d77eb6cb56ca4e1528b9/uml/actor.png -------------------------------------------------------------------------------- /uml/actor.txt: -------------------------------------------------------------------------------- 1 | @startuml 2 | actor "星际穿越的男主角" as copper 3 | actor "星际穿越的男主女儿" as murphy 4 | 5 | copper -> murphy: 爱和引力可以穿越 6 | @enduml 7 | -------------------------------------------------------------------------------- /uml/advanced_activity.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cch123/test/8a9d3dd4fbd3eecceaf4d77eb6cb56ca4e1528b9/uml/advanced_activity.png -------------------------------------------------------------------------------- /uml/advanced_activity.txt: -------------------------------------------------------------------------------- 1 | @startuml 2 | scale 512*1024 3 | 4 | |Gateway| 5 | start 6 | repeat 7 | :record data; 8 | :wating; 9 | repeat while (id < 10) 10 | 11 | |#778899|Copper| 12 | :enter the Endurance; 13 | while (not hungry) 14 | :play; 15 | :kick football; 16 | endwhile 17 | 18 | end 19 | 20 | @enduml 21 | -------------------------------------------------------------------------------- /uml/advanced_actor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cch123/test/8a9d3dd4fbd3eecceaf4d77eb6cb56ca4e1528b9/uml/advanced_actor.png -------------------------------------------------------------------------------- /uml/advanced_actor.txt: -------------------------------------------------------------------------------- 1 | @startuml 2 | actor "星际穿越的\n男主角" as copper #99ff99 3 | actor "星际穿越的\n男主女儿" as murphy #red 4 | 5 | copper -[#orange]> murphy: 爱和引力可以穿越 6 | @enduml 7 | -------------------------------------------------------------------------------- /uml/advanced_sequence.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cch123/test/8a9d3dd4fbd3eecceaf4d77eb6cb56ca4e1528b9/uml/advanced_sequence.png -------------------------------------------------------------------------------- /uml/advanced_sequence.txt: -------------------------------------------------------------------------------- 1 | @startuml 2 | participant Ark #white 3 | participant Noah #eeffee 4 | participant "SMS \n网关" as sms 5 | 6 | Ark -[#orange]> Noah : send sms 7 | Noah -> sms : send request 8 | Noah --[#red]> Ark : return success 9 | @enduml 10 | -------------------------------------------------------------------------------- /uml/more_advanced_activity.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cch123/test/8a9d3dd4fbd3eecceaf4d77eb6cb56ca4e1528b9/uml/more_advanced_activity.png -------------------------------------------------------------------------------- /uml/more_advanced_seq.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cch123/test/8a9d3dd4fbd3eecceaf4d77eb6cb56ca4e1528b9/uml/more_advanced_seq.png -------------------------------------------------------------------------------- /uml/plantuml.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cch123/test/8a9d3dd4fbd3eecceaf4d77eb6cb56ca4e1528b9/uml/plantuml.jar -------------------------------------------------------------------------------- /uml/sequence.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cch123/test/8a9d3dd4fbd3eecceaf4d77eb6cb56ca4e1528b9/uml/sequence.png -------------------------------------------------------------------------------- /uml/sequence.txt: -------------------------------------------------------------------------------- 1 | @startuml 2 | participant Ark 3 | participant Noah 4 | participant "SMS网关" as sms 5 | 6 | Ark -> Noah : send sms 7 | Noah -> sms : send request 8 | Noah --> Ark : return success 9 | @enduml 10 | -------------------------------------------------------------------------------- /uml/ufs.plantuml: -------------------------------------------------------------------------------- 1 | @startuml 2 | 3 | (*) --> "创建工单" 4 | --> "编辑工单" 5 | --> "提交工单" 6 | --> “数据校验” 7 | if "校验通过" then 8 | --> [Yes] "工单审核" 9 | if "审核通过" then 10 | --> [Yes] "创建特征" 11 | --> "创建特征相关数据" 12 | --> "特征发布" 13 | --> (*) 14 | else 15 | --> [No] "编辑工单" 16 | endif 17 | else 18 | --> [No] "编辑工单" 19 | endif 20 | @enduml -------------------------------------------------------------------------------- /vagrant_files/bootstrap.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | debconf-set-selections <<< 'mysql-server mysql-server/root_password password MySuperPassword' 4 | debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password MySuperPassword' 5 | apt-get update 6 | apt-get install -y mysql-server 7 | -------------------------------------------------------------------------------- /vagrant_files/init.sh: -------------------------------------------------------------------------------- 1 | echo " 2 | rdr pass inet proto tcp from any to 127.0.0.1 port 80 -> 127.0.0.1 port 8080 3 | rdr pass inet proto tcp from any to 127.0.0.1 port 443 -> 127.0.0.1 port 4443 4 | " | sudo pfctl -ef - >/dev/null 2>&1; echo "Add Port Forwarding (80 => 8080)\nAdd Port Forwarding (443 => 8443)" 5 | 6 | -------------------------------------------------------------------------------- /vagrant_files/readme.md: -------------------------------------------------------------------------------- 1 | Vagrantfile是vagrant的配置文件,里面有关于vagrant-triggers的配置,如果能够成功安装vagrant-triggers这个插件的话,则不需要在mac上做额外的端口转发,如果不能安装,那么需要在启动虚拟机的时候运行init.sh 2 | 3 | init.sh是在mac上用来转发80到8080,443到4443端口的脚本 4 | 5 | uinit.sh是取消上述操作的脚本 6 | -------------------------------------------------------------------------------- /vagrant_files/uinit.sh: -------------------------------------------------------------------------------- 1 | sudo pfctl -F all -f /etc/pf.conf >/dev/null 2>&1; echo "Removing Port Forwarding (80 => 8080)\nRemove Port Forwarding (443 => 4443)" 2 | 3 | -------------------------------------------------------------------------------- /vscode_configs/readme.md: -------------------------------------------------------------------------------- 1 | you need to set this to true first 2 | 3 | > gocode close 4 | 5 | > gocode set unimported-packages true 6 | -------------------------------------------------------------------------------- /x.md: -------------------------------------------------------------------------------- 1 | ddf 2 | --------------------------------------------------------------------------------