├── .gitignore ├── LICENSE ├── README.md └── snippet ├── bin └── shell │ ├── bashrc_docker.sh │ ├── dropfile.sh │ ├── freem.sh │ ├── install-vim.sh │ ├── install.sh │ ├── set_display_resolution.py │ └── yum ├── config ├── atom.md ├── komodoide-prefs.xml ├── pep257 ├── pep8 ├── pylintrc ├── sss_config.md ├── tmux-bash-completation ├── tmux.conf ├── vscode.md └── webpack.config.template.js ├── docs ├── README.md ├── algorithm │ ├── README.md │ ├── _static │ │ └── timecomplexity.png │ └── algorithm-analysis-and-design.md ├── architecture │ ├── README.md │ ├── ha-lb │ │ ├── _static │ │ │ ├── lvs-1.png │ │ │ ├── lvs-2.png │ │ │ ├── lvs-3.png │ │ │ ├── lvs-4.png │ │ │ ├── lvs-5.png │ │ │ └── lvs-6.png │ │ ├── haproxy-architecture.txt │ │ ├── haproxy-conf-example.md │ │ ├── haproxy-configuration.txt │ │ ├── haproxy-intro.txt │ │ ├── keepalived-conf.md │ │ ├── keepalived.md │ │ └── lvs-lb-and-install.md │ └── http-api-spec.md ├── assembly │ └── linux-assembly-development-guide.md ├── book&article │ └── README.md ├── bt │ └── dht-proto-chinese.md ├── c&c++ │ ├── README.md │ ├── cpp.md │ ├── effective-cpp-gist-excerpt.md │ ├── more-effective-cpp-gist-excerpt.md │ └── resource-management.md ├── compile │ ├── links.md │ └── parser_generator.md ├── compute │ ├── README.md │ └── how-to-teach-endian.md ├── db │ └── sql │ │ ├── README.md │ │ ├── _static │ │ ├── 1.jpg │ │ ├── 10.jpg │ │ ├── 2.jpg │ │ ├── 3.jpg │ │ ├── 4.jpg │ │ ├── 5.jpg │ │ ├── 6.jpg │ │ ├── 7.jpg │ │ ├── 8.jpg │ │ ├── 9.jpg │ │ └── sql-quick-ref.png │ │ ├── million-record.md │ │ ├── mysql-index.md │ │ ├── mysql-select.md │ │ ├── mysql-table-and-index.md │ │ └── sql-quick-ref.md ├── distributed │ ├── README.md │ ├── _static │ │ ├── 1.jpg │ │ ├── 10.jpg │ │ ├── 2.jpg │ │ ├── 3.jpg │ │ ├── 4.jpg │ │ ├── 5.jpg │ │ ├── 6.jpg │ │ ├── 7.jpg │ │ ├── 8.jpg │ │ └── 9.jpg │ ├── cap-theory.md │ ├── consistency.md │ ├── distributed-transaction.md │ ├── etcd-example.md │ └── zookeeper-theory.md ├── docker │ └── README.md ├── document │ ├── README.md │ ├── markdown │ │ ├── README.md │ │ ├── _static │ │ │ ├── 1.png │ │ │ ├── 2.png │ │ │ └── 3.png │ │ └── cheatsheet.md │ └── reStructuredText │ │ └── README.md ├── editor │ └── vim │ │ ├── README.md │ │ ├── _static │ │ └── 1.png │ │ ├── links.md │ │ ├── others.md │ │ ├── vim-keyboard-map.md │ │ ├── vim-plugin-nerdtree.md │ │ ├── vim-script-syntax.md │ │ └── vim-write-script-first.md ├── encoding │ └── README.md ├── gcc │ └── gcc-lib.md ├── go │ ├── README.md │ ├── _static │ │ └── package-init.png │ ├── go-base-syntax.md │ ├── go-base-type.md │ ├── go-expression.md │ ├── go-function.md │ ├── go-learning-note.md │ ├── go-others.md │ ├── go-package.md │ ├── go-statement.md │ ├── go-std-lib.md │ ├── go-tool-repo.md │ ├── go-version.md │ ├── net-http.md │ ├── optimization.md │ ├── packages.md │ └── template.txt ├── java │ ├── README.md │ └── packages.md ├── js │ ├── README.md │ ├── _static │ │ ├── 1.jpg │ │ ├── 2.jpg │ │ └── 3.png │ ├── amd-commonjs-umd.md │ ├── apply-call-bind.md │ ├── es2016-es2017.md │ ├── es2016-overview.md │ ├── faq.md │ ├── javascript.md │ ├── js-quick-reference.md │ ├── packages.md │ └── webpack-plugins.md ├── kubernetes │ └── README.md ├── linux │ ├── QoS │ │ ├── README.md │ │ ├── _static │ │ │ ├── 1.jpg │ │ │ ├── 2.jpg │ │ │ ├── 3.jpg │ │ │ ├── 4.jpg │ │ │ ├── 5.jpg │ │ │ ├── 6.jpg │ │ │ ├── 7.jpg │ │ │ ├── 8.jpg │ │ │ ├── 9.jpg │ │ │ └── htb-queue-discipline-diagram.png │ │ ├── htb-example.md │ │ ├── htb-example2.md │ │ ├── htb-user-guide.md │ │ ├── link.md │ │ ├── qos-filter.md │ │ ├── qos-theory.md │ │ ├── qos-use.md │ │ └── tc-doc │ │ │ ├── cls_fw.txt │ │ │ ├── cls_route.txt │ │ │ ├── cls_rsvp.txt │ │ │ ├── cls_u32.txt │ │ │ ├── estimators.txt │ │ │ ├── police.txt │ │ │ ├── priority.txt │ │ │ ├── sch_bfifo.txt │ │ │ ├── sch_cbq.txt │ │ │ ├── sch_hfsc.txt │ │ │ ├── sch_noop.txt │ │ │ ├── sch_noqueue.txt │ │ │ ├── sch_pfifo.txt │ │ │ ├── sch_pfifo_fast.txt │ │ │ ├── sch_prio.txt │ │ │ ├── sch_sfq.txt │ │ │ ├── sch_tbf.txt │ │ │ └── virtual_devices.txt │ ├── README.md │ ├── diskio │ │ └── fio.md │ ├── distribution │ │ └── kali.md │ ├── iproute2 │ │ ├── _static │ │ │ ├── 1.png │ │ │ ├── 2.png │ │ │ ├── 3.png │ │ │ ├── 4.png │ │ │ ├── 5.png │ │ │ ├── 6.png │ │ │ ├── 7.jpg │ │ │ └── iproute2.png │ │ ├── ip1.md │ │ └── tc1.md │ ├── ipv4 │ │ ├── common-setting.md │ │ └── system-config.md │ ├── kernel │ │ ├── README.md │ │ └── _static │ │ │ └── linux-kernel-map.png │ ├── netfilter │ │ ├── _static │ │ │ ├── 1.png │ │ │ ├── 10.png │ │ │ ├── 11.png │ │ │ ├── 12.png │ │ │ ├── 13.png │ │ │ ├── 14.png │ │ │ ├── 15.png │ │ │ ├── 2.png │ │ │ ├── 3.png │ │ │ ├── 4.png │ │ │ ├── 5.png │ │ │ ├── 6.png │ │ │ ├── 7.png │ │ │ ├── 8.png │ │ │ ├── 9.png │ │ │ ├── p1.png │ │ │ └── p2.png │ │ ├── iptables-beginner.md │ │ ├── iptables-ext.md │ │ ├── iptables-usage.md │ │ ├── link.md │ │ └── netfilter.txt │ ├── netlink │ │ ├── _static │ │ │ ├── 1.jpg │ │ │ ├── 2.jpg │ │ │ └── 3.jpg │ │ ├── generic-netlink-howto.txt │ │ ├── netlink-implementation-analyzation.pdf │ │ └── netlink-note.md │ ├── others │ │ ├── README.md │ │ ├── _static │ │ │ ├── backlog.png │ │ │ ├── css-selector.png │ │ │ ├── gnome-shell-calemdar-fore.png │ │ │ ├── gnome-shell-calendar-post.png │ │ │ ├── gnome-shell-main.png │ │ │ ├── gnome-shell-min-width-fore.png │ │ │ ├── gnome-shell-min-width-post.png │ │ │ ├── gnome-shell-overview.png │ │ │ ├── gnome-shell-status-icon-hpadding-fore.png │ │ │ ├── gnome-shell-status-icon-hpadding-post.png │ │ │ └── gnome-shell-toggle-1.png │ │ ├── backlog.md │ │ ├── customize-gnome-shell.md │ │ ├── linux-info.md │ │ └── linux-performance-analysis-and-optimization.md │ ├── program │ │ ├── _static │ │ │ ├── 1.png │ │ │ ├── 10.png │ │ │ ├── 11.png │ │ │ ├── 12.png │ │ │ ├── 13.jpg │ │ │ ├── 14.jpg │ │ │ ├── 2.png │ │ │ ├── 3.jpg │ │ │ ├── 4.png │ │ │ ├── 5.png │ │ │ ├── 6.png │ │ │ ├── 7.png │ │ │ ├── 8.png │ │ │ └── 9.jpg │ │ ├── compile-kernel.md │ │ ├── daemon.md │ │ ├── linux-system-programming.md │ │ ├── raw-socket-demystified.txt │ │ ├── raw-socket-ipv4.md │ │ ├── raw-socket.md │ │ └── so_reuse.md │ └── tap │ │ ├── README.md │ │ ├── _static │ │ ├── 1.jpg │ │ ├── 2.jpg │ │ └── 3.jpg │ │ └── tap-tun.md ├── network │ ├── ddos │ │ └── ddos-blackhole.md │ ├── nat │ │ ├── _static │ │ │ ├── 1.png │ │ │ ├── 10.jpg │ │ │ ├── 11.jpg │ │ │ ├── 2.png │ │ │ ├── 3.png │ │ │ ├── 4.png │ │ │ ├── 5.png │ │ │ ├── 6.png │ │ │ ├── 7.png │ │ │ ├── 8.png │ │ │ └── 9.png │ │ ├── p2p-communication-across-nat.md │ │ └── penetrate-nat.md │ ├── others │ │ ├── port-scan.md │ │ └── userspace-net-stack.md │ ├── ovs-of │ │ ├── QoS.md │ │ ├── README.md │ │ ├── _static │ │ │ ├── OVS_Flow_Tables.png │ │ │ └── OVS_flow_Tables_with_ARP_responder.png │ │ ├── dump-flows.md │ │ ├── in_port.md │ │ ├── link.md │ │ ├── others.md │ │ ├── ovs-dpdk.md │ │ └── tunnel.md │ ├── protocol │ │ ├── README.md │ │ ├── _static │ │ │ ├── ethernet.jpg │ │ │ ├── tcpip.png │ │ │ └── vlan_tag.png │ │ ├── data-link-layer.md │ │ └── switch-router.md │ ├── tcp │ │ ├── _static │ │ │ └── 1.png │ │ └── close_wait_and_time_wait.md │ ├── tcpdump │ │ ├── detailed-manuel.md │ │ └── simple-manuel.txt │ └── tunnel │ │ ├── _static │ │ ├── 1.jpg │ │ ├── 10.png │ │ ├── 2.jpg │ │ ├── 3.jpg │ │ ├── 4.jpg │ │ ├── 5.jpg │ │ ├── 6.jpg │ │ ├── 7.jpg │ │ ├── 8.jpg │ │ └── 9.png │ │ ├── ssh.md │ │ └── vtun-usage-and-src-analysis.md ├── openstack │ ├── README.md │ └── _static │ │ └── tunnel-flows.png ├── package │ └── fpm.md ├── python │ ├── README.md │ ├── _static │ │ ├── 1.png │ │ ├── 2.jpg │ │ ├── 3.png │ │ ├── 4.jpg │ │ └── 5.png │ ├── builtin.md │ ├── django-form.md │ ├── link.md │ ├── logging.md │ ├── pastedeploy.md │ ├── pypi_source.md │ ├── python-advance-app.md │ ├── python-advanced-feature.md │ ├── python-appendix.md │ ├── python-attr.md │ ├── python-base.md │ ├── python-c-extension.md │ ├── python-class.md │ ├── python-exception.md │ ├── python-expression-statement.md │ ├── python-file-encoding.md │ ├── python-function.md │ ├── python-operator-overload.md │ ├── python-other-key-point.md │ ├── python-package-guide.md │ ├── python-preface.md │ ├── python-type.md │ ├── python-variable-scope-package.md │ └── sqlalchemy-analysis.md ├── rust │ ├── README.md │ ├── notes.md │ ├── packages.md │ └── ref.md ├── shell │ ├── README.md │ ├── shell-appendix.md │ ├── shell-argument.md │ ├── shell-arithmetic.md │ ├── shell-builtin-command.md │ ├── shell-environment-var.md │ ├── shell-extension.md │ ├── shell-history.md │ ├── shell-lexical-preview.md │ ├── shell-others.md │ ├── shell-preface.md │ ├── shell-readline.md │ ├── shell-redirection.md │ ├── shell-reference.md │ └── shell-syntax.md ├── swift │ ├── README.md │ └── packages.md ├── tool │ ├── README.md │ ├── diff&patch.md │ └── script │ │ └── install-aria2-dep.sh ├── vcs │ ├── README.md │ ├── _static │ │ ├── 1.png │ │ ├── 10.png │ │ ├── 11.png │ │ ├── 12.png │ │ ├── 2.png │ │ ├── 3.png │ │ ├── 4.png │ │ ├── 5.png │ │ ├── 6.png │ │ ├── 7.png │ │ ├── 8.png │ │ ├── 9.png │ │ ├── git-server-method.png │ │ ├── git-shortcut.jpg │ │ └── repo.png │ ├── build-git-server.md │ ├── build-svn-server.md │ ├── git-commit-message.md │ ├── git-http-proxy.md │ ├── git-learning-note.md │ ├── git-rebase.md │ └── github-guide.md ├── web │ ├── README.md │ ├── _static │ │ ├── 1.png │ │ ├── 10.png │ │ ├── 11.png │ │ ├── 12.png │ │ ├── 13.png │ │ ├── 14.png │ │ ├── 15.png │ │ ├── 16.png │ │ ├── 17.png │ │ ├── 18.jpg │ │ ├── 19.png │ │ ├── 2.png │ │ ├── 20.jpg │ │ ├── 20.png │ │ ├── 21.png │ │ ├── 22.png │ │ ├── 3.png │ │ ├── 4.png │ │ ├── 5.png │ │ ├── 6.png │ │ ├── 7.png │ │ ├── 8.png │ │ └── 9.png │ ├── browse-http-cache.md │ ├── css-selector.md │ ├── url_hash.md │ ├── website-evolution-summary.md │ └── website-evolution.md └── windows │ └── README.md ├── example ├── c-c++ │ ├── BiTree.c │ ├── OICQ-20120820.tar.gz │ ├── find-sort.c │ ├── fragroute │ │ ├── fragroute-1.2.tar.gz │ │ ├── fragroute.8.txt │ │ └── fragtest.8.txt │ ├── maze_demo.cpp │ ├── sendip │ │ ├── sendip-2.5.tar.gz │ │ └── sendip-source-analyzation.doc │ └── tcpipiv1.tar.Z ├── dockerfile │ └── python36.dockerfile ├── go │ ├── mxj.go │ ├── project │ │ ├── README.md │ │ ├── cmd │ │ │ └── project │ │ │ │ └── main.go │ │ ├── glide.yaml │ │ └── project │ │ │ ├── conf │ │ │ └── conf.go │ │ │ └── enter.go │ ├── snippet │ │ ├── port_range.go │ │ ├── port_range_test.go │ │ ├── value.go │ │ └── value_test.go │ ├── src │ │ ├── listenport │ │ │ ├── client │ │ │ │ └── main.go │ │ │ └── server │ │ │ │ └── main.go │ │ └── service │ │ │ ├── client │ │ │ └── main.go │ │ │ └── server │ │ │ └── main.go │ └── xml.go ├── linux │ ├── flow_hash_list.tar.gz │ ├── list-netns.py │ ├── netfilter │ │ ├── Makefile │ │ └── test_nf.c │ └── timer.c ├── nodejs │ └── webpack │ │ ├── .eslintrc.js │ │ ├── build │ │ ├── config.js │ │ ├── webpack.base.config.js │ │ ├── webpack.dev.config.js │ │ ├── webpack.dll.config.js │ │ └── webpack.production.config.js │ │ ├── dll │ │ └── vendor.js │ │ ├── index.html │ │ ├── package.json │ │ └── src │ │ ├── index1.js │ │ └── index2.js ├── python │ ├── api_proxy.py │ ├── bt │ │ ├── ItMetadata.py │ │ ├── bencode.py │ │ ├── downloadTorrent.py │ │ ├── metadata.py │ │ ├── metautils.py │ │ ├── simMetadata.py │ │ ├── simdt_worker.py │ │ └── startCrawler.py │ ├── call_retry.py │ ├── check_music.py │ ├── circuit_breaker.py │ ├── classifier.py │ ├── config-parser.py │ ├── falcon_app.py │ ├── greentaskpool.py │ ├── gunicorn-conf.py │ ├── gunicorn-logrotate.conf │ ├── gunicorn.py │ ├── gunicorn_app.py │ ├── init_logging.py │ ├── lifemanager.py │ ├── oslo_messaging │ │ ├── client.py │ │ └── server.py │ ├── osloconfig.py │ ├── oslolog.py │ ├── ovs-port-range.py │ ├── password.py │ ├── ping_ip.py │ ├── pool.py │ ├── process.py │ ├── project │ │ ├── LICENSE │ │ ├── PKG-INFO │ │ ├── README.rst │ │ ├── doc │ │ │ └── Introduction.txt │ │ ├── logging.ini │ │ ├── project.conf │ │ ├── project │ │ │ ├── __init__.py │ │ │ ├── _options.py │ │ │ ├── common │ │ │ │ ├── __init__.py │ │ │ │ ├── logging.py │ │ │ │ └── utils.py │ │ │ ├── db │ │ │ │ ├── __init__.py │ │ │ │ └── sqlalchemy │ │ │ │ │ ├── __init__.py │ │ │ │ │ ├── api.py │ │ │ │ │ ├── base.py │ │ │ │ │ └── models.py │ │ │ └── main.py │ │ ├── requirements.txt │ │ ├── setup.cfg │ │ ├── setup.py │ │ └── test │ │ │ └── test.py │ ├── ratelimit.py │ ├── resourcelock.py │ ├── ryu-nat-switch.py │ ├── scrapy │ │ └── crawler │ │ │ ├── README │ │ │ ├── crawler │ │ │ ├── __init__.py │ │ │ ├── items.py │ │ │ ├── linkextractors.py │ │ │ ├── pipelines.py │ │ │ ├── settings.py │ │ │ ├── spiders │ │ │ │ ├── __init__.py │ │ │ │ ├── base.py │ │ │ │ ├── imagespide.py │ │ │ │ └── textspider.py │ │ │ └── utils.py │ │ │ └── scrapy.cfg │ ├── snake.py │ ├── sqlalchemy-orm-example.py │ ├── sqlalchemy-orm-model.py │ ├── sqlalchemy_db.py │ ├── stevedore.md │ ├── tap.c │ ├── template.py │ ├── url.py │ ├── utils.py │ ├── version.py │ ├── wsgi.py │ ├── xml2json.py │ └── zookeeper.py ├── shell │ ├── openvpn.sh │ └── rublock.sh └── templates │ ├── Makefile │ ├── html5.html │ ├── service-script(openstack-nova-api) │ └── sublimetext-sftp-config.json ├── libs ├── c-c++ │ ├── encode.cpp │ ├── frame-crc32.c │ ├── list.h │ └── xlib │ │ ├── xdlist.c │ │ ├── xdlist.h │ │ ├── xgf.c │ │ ├── xgf.h │ │ ├── xslist.c │ │ ├── xslist.h │ │ └── xtypes.h ├── css │ ├── cssbase.css │ ├── cssreset.css │ └── normalize.css ├── js │ ├── cookie.js │ ├── jquery.cookie │ │ ├── README.md │ │ └── jquery.cookie.js │ ├── json.js │ ├── loadjs.js │ ├── md5.js │ └── utils.js └── linux │ ├── init.d-service-example │ └── kernel-utils.h └── software └── symbol-fonts_1.2_all.deb /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | 5 | # C extensions 6 | *.so 7 | 8 | # Distribution / packaging 9 | .Python 10 | env/ 11 | develop-eggs/ 12 | dist/ 13 | downloads/ 14 | eggs/ 15 | .eggs/ 16 | lib/ 17 | lib64/ 18 | parts/ 19 | sdist/ 20 | var/ 21 | *.egg-info/ 22 | .installed.cfg 23 | *.egg 24 | 25 | # PyInstaller 26 | # Usually these files are written by a python script from a template 27 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 28 | *.manifest 29 | *.spec 30 | 31 | # Installer logs 32 | pip-log.txt 33 | pip-delete-this-directory.txt 34 | 35 | # Unit test / coverage reports 36 | htmlcov/ 37 | .tox/ 38 | .coverage 39 | .coverage.* 40 | .cache 41 | nosetests.xml 42 | coverage.xml 43 | *,cover 44 | 45 | # Translations 46 | *.mo 47 | *.pot 48 | 49 | # Django stuff: 50 | *.log 51 | 52 | # Sphinx documentation 53 | docs/_build/ 54 | 55 | # PyBuilder 56 | target/ 57 | 58 | # VS Code 59 | .vscode/ 60 | 61 | # CTags 62 | tags 63 | 64 | # Mac OS 65 | .DS_Store 66 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /snippet/bin/shell/dropfile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #while true;do 4 | # read -p 'please input the directory absolute path we will serivce: ' DIRE 5 | # if [ -d $DIRE ];then 6 | # while true;do 7 | # read -p 'please input the postfix of the file you want delete, eg: pyc|pyo, but one at a time: ' POSTFIX 8 | # read -p 'are you sure? (Y|N): ' YON 9 | # char=`echo $YON | tr 'yn' 'YN'` 10 | # [ $char == 'Y' ] && break || continue 11 | # done 12 | # break 13 | # else 14 | # echo -e '\033[31mwrong input, your input is not a directory or anythine else i cannot identifiy\033[0m' 15 | # continue 16 | # fi 17 | #done 18 | 19 | #echo '***********************************' 20 | 21 | function dropfile { 22 | for item in `ls $1`;do 23 | echo $1/$item | grep ".*.$POSTFIX$" &> /dev/null 24 | if [ -f $1/$item -a $? -eq 0 ];then 25 | echo -e "\033[31mdropping the file $1/$item\033[0m" 26 | rm -rf $1/$item 27 | elif [ -d $1/$item ];then 28 | echo -e "\033[32mswitch directory to $1/$item\033[0m" 29 | dropfile $1/$item 30 | fi 31 | done 32 | } 33 | DIRE=$1 34 | POSTFIX=$2 35 | 36 | dropfile $DIRE 37 | -------------------------------------------------------------------------------- /snippet/bin/shell/freem.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Free the memory under Linux. 4 | # 5 | ################ Introduction about freeing memory under Linux. 6 | # 7 | # 在Linux系统下,我们一般不需要去释放内存,因为系统已经将内存管理的很好。但是凡事 8 | # 也有例外,有的时候内存会被缓存占用掉,导致系统使用SWAP空间影响性能,此时就需要执行 9 | # 释放内存(清理缓存)的操作了。 10 | # 11 | # Linux系统的缓存机制是相当先进的,他会针对dentry(用于VFS,加速文件路径名到inode 12 | # 的转换)、Buffer Cache(针对磁盘块的读写)和Page Cache(针对文件inode的读写)进 13 | # 行缓存操作。但是在进行了大量文件操作之后,缓存会把内存资源基本用光。但实际上我们文 14 | # 件操作已经完成,这部分缓存已经用不到了。这个时候,我们难道只能眼睁睁的看着缓存把内 15 | # 存空间占据掉么? 16 | # 17 | # 所以,我们还是有必要来手动进行Linux下释放内存的操作,其实也就是释放缓存的操作了。 18 | # 19 | # 要达到释放缓存的目的,我们首先需要了解下关键的配置文件/proc/sys/vm/drop_caches。 20 | # 这个文件中记录了缓存释放的参数,默认值为0,也就是不释放缓存。他的值可以为0~3之间 21 | # 的任意数字,代表着不同的含义: 22 | # 23 | # 0 – 不释放 24 | # 1 – 释放页缓存 25 | # 2 – 释放dentries和inodes 26 | # 3 – 释放所有缓存 27 | # 28 | # 知道了参数后,我们就可以根据我们的需要,使用下面的指令来进行操作。 29 | # 30 | # 首先我们需要使用sync指令,将所有未写的系统缓冲区写到磁盘中,包含已修改的 i-node、 31 | # 已延迟的块 I/O 和读写映射文件。否则在释放缓存的过程中,可能会丢失未保存的文件。 32 | # 33 | # # sync 34 | # 35 | # 接下来,我们需要将需要的参数写进/proc/sys/vm/drop_caches文件中,比如我们需要释放 36 | # 所有缓存,就输入下面的命令: 37 | # 38 | # # echo 3 > /proc/sys/vm/drop_caches 39 | # 40 | # 此指令输入后会立即生效,可以查询现在的可用内存明显的变多了。 41 | # 42 | # 要查询当前缓存释放的参数,可以输入下面的指令: 43 | # 44 | # # cat /proc/sys/vm/drop_caches 45 | # 46 | ############################################################################### 47 | 48 | level=3 49 | if [ $# -gt 0 ]; then 50 | level=$1 51 | fi 52 | if [ $level -gt 3 ] || [ $level -lt 0 ]; then 53 | level=0 54 | fi 55 | 56 | #[ $? -eq 0 ] && echo $level 57 | #exit 0 58 | 59 | [ $? -eq 0 ] && sync && echo "$level" > /proc/sys/vm/drop_caches 60 | 61 | -------------------------------------------------------------------------------- /snippet/bin/shell/install-vim.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Install the vimrc 4 | # https://github.com/xgfone/dot-vimrc 5 | # 6 | 7 | ## Install Dependencie 8 | yaourt -S ack ctags &> /dev/null # ArchLinux 9 | sudo apt-get install ack-grep exuberant-ctags &> /dev/null # Ubuntu 10 | brew install ack ctags &> /dev/null # OS X 11 | 12 | # Backup your old vim configuration files 13 | mv ~/.vim ~/.vim.orig &> /dev/null 14 | mv ~/.vimrc ~/.vimrc.orig &> /dev/null 15 | 16 | # Clone and install this repo 17 | git clone git://github.com/xgfone/dot-vimrc.git ~/.vim 18 | ln -s ~/.vim/vimrc ~/.vimrc 19 | 20 | # Setup Vundle 21 | git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle 22 | 23 | # Last, you can execute the vim, and install bundles. 24 | # :BundleInstall 25 | -------------------------------------------------------------------------------- /snippet/bin/shell/yum: -------------------------------------------------------------------------------- 1 | yum --setopt=tsflags=noscripts $@ 2 | -------------------------------------------------------------------------------- /snippet/config/pep257: -------------------------------------------------------------------------------- 1 | [pep257] 2 | ignore = D100,D101,D102,D103,D104,D105,D202,D203,D209 3 | -------------------------------------------------------------------------------- /snippet/config/pep8: -------------------------------------------------------------------------------- 1 | [pep8] 2 | max-line-length = 120 3 | ignore = E125,E126,E127,E128,E129,E221,E265,E309,E401,E402,E731 4 | -------------------------------------------------------------------------------- /snippet/docs/README.md: -------------------------------------------------------------------------------- 1 | 2 | ##### [awesome](https://github.com/sindresorhus/awesome) 3 | A curated list of awesome lists. 4 | -------------------------------------------------------------------------------- /snippet/docs/algorithm/README.md: -------------------------------------------------------------------------------- 1 | 2 | - [算法分析与设计](./algorithm-analysis-and-design.md) 3 | - [红黑树深入剖析及Java实现](http://tech.meituan.com/redblack-tree.html) 4 | - [漫画:什么是动态规划](http://mp.weixin.qq.com/s/_kHeAI4PvF-KH7IQrmnRVg) 5 | - [漫画:什么是 B+ 树?](http://mp.weixin.qq.com/s/cK_GIhCuGoUwJpDpoaETxw) 6 | 7 | 8 | ![time complexity](./_static/timecomplexity.png) 9 | -------------------------------------------------------------------------------- /snippet/docs/algorithm/_static/timecomplexity.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/algorithm/_static/timecomplexity.png -------------------------------------------------------------------------------- /snippet/docs/architecture/README.md: -------------------------------------------------------------------------------- 1 | 2 | - [system Design Primer](https://github.com/donnemartin/system-design-primer) 3 | - [High Availability & Load Balance](./ha-lb) 4 | - [Keepalived](./ha-lb/keepalived.md) 5 | - [Keepalived Config](./ha-lb/keepalived-conf.md) 6 | - [HAProxy Introduction](./ha-lb/haproxy-intro.txt) 7 | - [HAProxy Architecture](./ha-lb/haproxy-architecture.txt) 8 | - [HAProxy Configure](./ha-lb/haproxy-configuration.txt) 9 | - [HAProxy Conf Example](./ha-lb/haproxy-conf-example.md) 10 | - [LVS 技术原理](https://help.aliyun.com/knowledge_detail/39444.html) 11 | - [LVS 负载均衡原理及安装配置详解](./ha-lb/lvs-lb-and-install.md) 12 | - [究竟啥才是互联网架构 `高可用`](http://mp.weixin.qq.com/s/7nfSvxZ4vJAxpIN5rCdaCw) 13 | - RESTfull API 14 | - [RESTful API 设计指南](http://www.ruanyifeng.com/blog/2014/05/restful_api.html) 15 | - [REST接口设计规范](http://wangwei.info/about-rest-api) 16 | - [跟着 Github 学习 Restful HTTP API 设计](http://cizixs.com/2016/12/12/restful-api-design-guide) 17 | - **Other** 18 | - [我的架构感悟:从美国宪法学习架构设计原则](http://gitbook.cn/books/58836d405a5adc3f0316023b/index.html) 19 | - [实录:架构设计,可以学美国制宪;架构改造,可以学中国改革](http://www.10tiao.com/html/689/201702/2651576825/1.html) 20 | - [秒杀系统架构分析与实战](http://www.cnblogs.com/andy-zhou/p/5364136.html) 21 | - [HTTP API 接口调用规范](./http-api-spec.md) 22 | -------------------------------------------------------------------------------- /snippet/docs/architecture/ha-lb/_static/lvs-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/architecture/ha-lb/_static/lvs-1.png -------------------------------------------------------------------------------- /snippet/docs/architecture/ha-lb/_static/lvs-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/architecture/ha-lb/_static/lvs-2.png -------------------------------------------------------------------------------- /snippet/docs/architecture/ha-lb/_static/lvs-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/architecture/ha-lb/_static/lvs-3.png -------------------------------------------------------------------------------- /snippet/docs/architecture/ha-lb/_static/lvs-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/architecture/ha-lb/_static/lvs-4.png -------------------------------------------------------------------------------- /snippet/docs/architecture/ha-lb/_static/lvs-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/architecture/ha-lb/_static/lvs-5.png -------------------------------------------------------------------------------- /snippet/docs/architecture/ha-lb/_static/lvs-6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/architecture/ha-lb/_static/lvs-6.png -------------------------------------------------------------------------------- /snippet/docs/book&article/README.md: -------------------------------------------------------------------------------- 1 | 2 | ##### [go-database-sql-tutorial](https://github.com/VividCortex/go-database-sql-tutorial) 3 | A tutorial for Go's database/sql package http://go-database-sql.org. 4 | 5 | ##### [raft-zh_cn](https://github.com/maemual/raft-zh_cn) 6 | Raft一致性算法论文的中文翻译 7 | 8 | ##### [Qix](https://github.com/ty4z2008/Qix) 9 | Node.Js、Golang、Machine Learning、PostgreSQL、Deep Learning http://ty4z2008.github.io/Qix. 10 | 11 | ##### [HelloSea.js](https://github.com/island205/HelloSea.js) 12 | 专注Sea.js,深入浅出分析Sea.js模块机制 http://island205.github.io/HelloSea.js/. 13 | 14 | ##### [tech_writing](https://github.com/xgfone/tech_writing) 15 | 专注Sea.js,深入浅出分析Sea.js模块机制 16 | 17 | ##### [build-web-application-with-golang](https://github.com/astaxie/build-web-application-with-golang) 18 | A golang ebook intro how to build a web with golang 19 | 20 | ##### EBook 21 | - [free tech ebooks from packtpub](https://github.com/tahmid-choyon/free-tech-ebooks-from-packtpub) 22 | -------------------------------------------------------------------------------- /snippet/docs/c&c++/README.md: -------------------------------------------------------------------------------- 1 | 2 | - [C & C++ 标准解读](http://en.cppreference.com/w/) 3 | - [《Effective C++》要点摘录](./effective-cpp-gist-excerpt.md) 4 | - [《More Effective C++》要点摘录](./more-effective-cpp-gist-excerpt.md) 5 | - [C++ 资源管理](./resource-management.md) 6 | - [C++ 支言碎语](./cpp.md) 7 | -------------------------------------------------------------------------------- /snippet/docs/c&c++/cpp.md: -------------------------------------------------------------------------------- 1 | 2 | ## C++语言 3 | 4 | 1、C/C++对无符号类型的建议: 5 | 尽量不要在你的代码中使用无符号类型,以免增加不必要的复杂性。尤其是,不要仅仅因为无符号数不存在负值 6 | 而用它来表示数量。 7 | 8 | 尽量使用像int那样的有符号类型,这样在涉及升级混合类型的复杂细节时,不必担心边界情况(如-1会被转换成 9 | 非常大的正数,从而会导致一个表达式永远为真或假)。 10 | 11 | 只有在使用位段(有时也称“位域”)和二进制掩码时,才可以使用无符号数。应该在表达式使用强制类型转换, 12 | 使操作数均为有符号数或无符号数,这样就不必由编译器来选择结果的类型了。 13 | 14 | 15 | ## STL 16 | 17 | 1、STL的基本观念就是将数据和操作分离。数据由容器类加以管理,操作则由可定制的算法定义之。迭代器在两者之间充当粘合剂,使任何算法都可以和任何容器交互运行。 18 | 19 | 2、泛型设计 20 | 21 | (1) 为了撰写尽可能与容器型别无关的泛型程序代码,最好不要使用随机存取迭代器的特有操作。 22 | (2) 为了写出适用于任何容器的泛型程序代码,应该使用operator != ,而非operator <。 23 | 24 | 3、STL容器元素必须满足以下三个基本要求: 25 | 26 | (1) 必须可透过copy构造函数进行复制; 27 | (2) 必须可透过assignment操作符完成赋值动作; 28 | (3) 必须可透过析构函数完成销毁动作。 29 | 30 | 这三个条件对任何class而言,其实都是隐式成立的。 31 | 32 | 另外,下面几个条件,也应当获得满足: 33 | 34 | (1) 对序列式容器而言,元素的default构造函数必须可用; 35 | (2) 对于某些动作,必须定义operator == 以执行相等测试; 36 | (3) 在关联式容器中,元素必须定义出排序准则。缺省情况下是operator <,透过仿函数less<>被调用。 37 | 38 | 4、所有容器都会建立元素副本,并返回该副本。STL只支持value语意,不支持reference语意。 39 | 40 | 5、STL的设计原则是效率优先,安全次之。STL几乎不检查逻辑错误。 41 | 42 | 43 | ## String 44 | 45 | 1、String对象的字符串尾部并没有一个特殊字符'\0'。在String中,字符'\0'和其它字符的地位完全相同。 46 | 47 | 2、当打算检验搜索函数的返回值时,应该使用`string::size_type`型别而不是`int`或`unsigned`;否则,与`string::npos`的比较动作将无法有效运行。 48 | 49 | 3、大部情况下,如果指定的索引超过实际字符数,会引发out_of_range异常。 50 | 51 | 4、千万不要以`NULL指标`取代`cahr *`作为参数,这样会导致奇异行为,因为`NULL`具有`整数`型别,在单整数型别的重载函数版本上会被解释为数字0或“其值为0”的字符。 52 | -------------------------------------------------------------------------------- /snippet/docs/compile/links.md: -------------------------------------------------------------------------------- 1 | 2 | #### 从零开始写个编译器吧系列 3 | - [Github](https://github.com/Moskize91/TaolanTutorial) 4 | - [Docs](https://zhuanlan.zhihu.com/p/19878087) 5 | 6 | -------------------------------------------------------------------------------- /snippet/docs/compile/parser_generator.md: -------------------------------------------------------------------------------- 1 | 2 | ## Parser Generator 3 | 4 | ### Tools 5 | ##### ANTLR 6 | ANTLR (ANother Tool for Language Recognition) is a powerful parser generator for reading, 7 | processing, executing, or translating structured text or binary files. 8 | 9 | - [GitHub Source](https://github.com/antlr/antlr4) 10 | - [Official Website](http://www.antlr.org/) 11 | 12 | ##### Grako 13 | Grako (for "grammar compiler") takes a grammar in a variation of EBNF as input, 14 | and outputs a memoizing PEG/Packrat parser in Python. 15 | 16 | - [Source](http://bitbucket.org/apalala/grako) 17 | 18 | ##### Ragel 19 | Ragel State Machine Compiler. 20 | 21 | - [Github Source](https://github.com/colmnet/ragel) 22 | 23 | ##### Peg 24 | Peg, Parsing Expression Grammar, is an implementation of a Packrat parser generator. 25 | 26 | - [Github Source](https://github.com/pointlander/peg) 27 | 28 | ##### Pigeon 29 | Command pigeon generates parsers in Go from a PEG grammar. 30 | 31 | - [Github Source](https://github.com/PuerkitoBio/pigeon) 32 | - [Introduction](http://0value.com/A-PEG-parser-generator-for-Go) 33 | 34 | ### Docs 35 | - [Packrat & PEG](http://bford.info/packrat/) 36 | - [Packrat Parsing](https://pdos.csail.mit.edu/~baford/packrat/thesis/) 37 | - [PEG Wiki](https://en.wikipedia.org/wiki/Parsing_expression_grammar) 38 | 39 | PEG(Parsing Expression Grammar,解析表达式文法) 与 CFG(Context-Free Grammar,上下文无关文法)的基本 40 | 区别就是:PEG 的选择符(choice operator)是顺序性的,即,对于 e1 / e2,如果 e1 成功匹配,e2 将会被忽略。 41 | 这将不会产生二义性,也即是,PEG 通过顺序性避免了二义性(这在 CFG 中可能会产生二义性)。 42 | -------------------------------------------------------------------------------- /snippet/docs/compute/README.md: -------------------------------------------------------------------------------- 1 | 2 | - [How to teach endian](./how-to-teach-endian.md) 3 | -------------------------------------------------------------------------------- /snippet/docs/db/sql/README.md: -------------------------------------------------------------------------------- 1 | - [处理百万级以上的数据时,提高查询速度的方法](./million-record.md) 2 | - [MySQL 的查询、子查询及连接查询](./mysql-select.md) 3 | - [MySQL 建表与索引使用规范详解](./mysql-table-and-index.md) 4 | - [理解MySQL——索引与优化](./mysql-index.md) 5 | - [SQL快速参考](./sql-quick-ref.md) 6 | - [高性能的 MySQL](http://www.ctolib.com/docs-high-performance-mysql-c-index) 7 | - [MySQL 连表查询](https://blog.ansheng.me/article/python-full-stack-way-mysql-even-table-query) 8 | - [我必须得告诉大家的MySQL优化原理](http://www.jianshu.com/p/d7665192aaaf) 9 | - [一分钟掌握数据库垂直拆分](http://mp.weixin.qq.com/s/ezD0CWHAr0RteC9yrwqyZA) 10 | - [数据库秒级平滑扩容架构方案](https://mp.weixin.qq.com/s/BLOneOs-cPxP_9b5eH8oQA) 11 | - [100亿数据1万属性数据架构设计](http://mp.weixin.qq.com/s/77rfe-vJ0Q4c1UgwSUJa8Q) 12 | - [58到家数据库30条军规解读](http://mp.weixin.qq.com/s/LElskWCs4d2ChGQANZ70Iw) 13 | - [业界难题:`跨库分页` 的四种方案](http://mp.weixin.qq.com/s/cMAXYBxmevFV_fwysZqP8w) 14 | - [100亿数据平滑数据迁移,不影响服务](https://mp.weixin.qq.com/s/EpxicEJWRyEOoa9V5UOOpg) 15 | - [细聊冗余表数据一致性](http://mp.weixin.qq.com/s/ALSDqOslGXx2Qz7e5YKtFg) 16 | - [mysql并行复制降低主从同步延时的思路与启示](http://mp.weixin.qq.com/s/t58Rwgiz_9ikqSuHvDAAZg) 17 | -------------------------------------------------------------------------------- /snippet/docs/db/sql/_static/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/db/sql/_static/1.jpg -------------------------------------------------------------------------------- /snippet/docs/db/sql/_static/10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/db/sql/_static/10.jpg -------------------------------------------------------------------------------- /snippet/docs/db/sql/_static/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/db/sql/_static/2.jpg -------------------------------------------------------------------------------- /snippet/docs/db/sql/_static/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/db/sql/_static/3.jpg -------------------------------------------------------------------------------- /snippet/docs/db/sql/_static/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/db/sql/_static/4.jpg -------------------------------------------------------------------------------- /snippet/docs/db/sql/_static/5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/db/sql/_static/5.jpg -------------------------------------------------------------------------------- /snippet/docs/db/sql/_static/6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/db/sql/_static/6.jpg -------------------------------------------------------------------------------- /snippet/docs/db/sql/_static/7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/db/sql/_static/7.jpg -------------------------------------------------------------------------------- /snippet/docs/db/sql/_static/8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/db/sql/_static/8.jpg -------------------------------------------------------------------------------- /snippet/docs/db/sql/_static/9.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/db/sql/_static/9.jpg -------------------------------------------------------------------------------- /snippet/docs/db/sql/_static/sql-quick-ref.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/db/sql/_static/sql-quick-ref.png -------------------------------------------------------------------------------- /snippet/docs/db/sql/sql-quick-ref.md: -------------------------------------------------------------------------------- 1 | 2 | ![SQL Quick Reference](./_static/sql-quick-ref.png) 3 | -------------------------------------------------------------------------------- /snippet/docs/distributed/README.md: -------------------------------------------------------------------------------- 1 | 2 | - [分布式系统——CAP理论](./cap-theory.md) 3 | - [分布式系统常见的事务处理机制](./distributed-transaction.md) 4 | - [分布式一致性算法](./consistency.md) 5 | - [etcd集群实例](./etcd-example.md) 6 | - [ZooKeeper原理](./zookeeper-theory.md) 7 | - [基于 Redis 的分布式锁到底安全吗?](https://gold.xitu.io/post/58b3a93c1b69e60058b49767) 8 | - [Dapper, a Large-Scale Distributed Systems Tracing Infrastructure](https://github.com/bigbully/Dapper-translation) | [英文原版论文下载](https://github.com/bigbully/Dapper-translation/raw/master/dapper%E5%88%86%E5%B8%83%E5%BC%8F%E8%B7%9F%E8%B8%AA%E7%B3%BB%E7%BB%9F%E5%8E%9F%E6%96%87.pdf) | [中文翻译阅读](http://bigbully.github.io/Dapper-translation) 9 | - [到底什么时候该使用MQ?](http://mp.weixin.qq.com/s/LqViglTO_h8UJqi3aD6P6w) 10 | - **gRPC** 11 | - [Protobuf 语法](https://segmentfault.com/a/1190000007917576) 12 | - [gRPC 服务发现 & 负载均衡](https://segmentfault.com/a/1190000008672912) 13 | - [gRPC 拦截器 Interceptor](https://segmentfault.com/a/1190000007997759) 14 | - [gRPC HTTP/JSON 协议转换](https://segmentfault.com/a/1190000008106582) 15 | -------------------------------------------------------------------------------- /snippet/docs/distributed/_static/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/distributed/_static/1.jpg -------------------------------------------------------------------------------- /snippet/docs/distributed/_static/10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/distributed/_static/10.jpg -------------------------------------------------------------------------------- /snippet/docs/distributed/_static/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/distributed/_static/2.jpg -------------------------------------------------------------------------------- /snippet/docs/distributed/_static/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/distributed/_static/3.jpg -------------------------------------------------------------------------------- /snippet/docs/distributed/_static/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/distributed/_static/4.jpg -------------------------------------------------------------------------------- /snippet/docs/distributed/_static/5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/distributed/_static/5.jpg -------------------------------------------------------------------------------- /snippet/docs/distributed/_static/6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/distributed/_static/6.jpg -------------------------------------------------------------------------------- /snippet/docs/distributed/_static/7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/distributed/_static/7.jpg -------------------------------------------------------------------------------- /snippet/docs/distributed/_static/8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/distributed/_static/8.jpg -------------------------------------------------------------------------------- /snippet/docs/distributed/_static/9.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/distributed/_static/9.jpg -------------------------------------------------------------------------------- /snippet/docs/docker/README.md: -------------------------------------------------------------------------------- 1 | 2 | - [Docker — 从入门到实践](https://github.com/yeasy/docker_practice) (点击 [GitBook](https://yeasy.gitbooks.io/docker_practice/content) 或 [Github](https://github.com/yeasy/docker_practice/blob/master/SUMMARY.md) 阅读) 3 | -------------------------------------------------------------------------------- /snippet/docs/document/README.md: -------------------------------------------------------------------------------- 1 | 2 | Documents 3 | ========= 4 | 5 | - [Markdown](./markdown) 6 | - [Cheat Sheet](./markdown/cheatsheet.md) 7 | - [Markdown 语法说明](http://www.appinn.com/markdown/)([快速入门版](http://www.appinn.com/markdown/basic.html)) 8 | - [Markdown & GFM](https://guides.github.com/features/mastering-markdown/) 9 | - Github Docs 10 | - [Basic writing and formatting syntax](https://help.github.com/articles/basic-writing-and-formatting-syntax/) 11 | - [Organizing information with tables](https://help.github.com/articles/organizing-information-with-tables/) 12 | - [reStructuredText](./reStructuredText) 13 | - [Quick reStructuredText](http://docutils.sourceforge.net/docs/user/rst/quickref.html) 14 | - [reStructuredText Markup Specification](http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html) 15 | - [reStructuredText 入门](http://sphinx-doc-zh.readthedocs.org/en/latest/rest.html) 16 | - [Sphinx](http://sphinx-doc-zh.readthedocs.org/en/latest/contents.html) 17 | - [YAML](http://www.yaml.org/spec/1.2/spec.html) 18 | - [YAML 语言教程](http://www.ruanyifeng.com/blog/2016/07/yaml.html) 19 | -------------------------------------------------------------------------------- /snippet/docs/document/markdown/README.md: -------------------------------------------------------------------------------- 1 | 2 | ## Markdown & GFM 3 | 4 | - [Cheat Sheet](./cheatsheet.md) 5 | - [Markdown 语法说明](http://www.appinn.com/markdown/)([快速入门版](http://www.appinn.com/markdown/basic.html)) 6 | - [Markdown & GFM](https://guides.github.com/features/mastering-markdown/) 7 | - Github Docs 8 | - [Basic writing and formatting syntax](https://help.github.com/articles/basic-writing-and-formatting-syntax/) 9 | - [Organizing information with tables](https://help.github.com/articles/organizing-information-with-tables/) 10 | -------------------------------------------------------------------------------- /snippet/docs/document/markdown/_static/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/document/markdown/_static/1.png -------------------------------------------------------------------------------- /snippet/docs/document/markdown/_static/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/document/markdown/_static/2.png -------------------------------------------------------------------------------- /snippet/docs/document/markdown/_static/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/document/markdown/_static/3.png -------------------------------------------------------------------------------- /snippet/docs/document/markdown/cheatsheet.md: -------------------------------------------------------------------------------- 1 | 2 | Markdown Base 3 | ============= 4 | 5 | [Markdown Base](http://daringfireball.net/projects/markdown/syntax "Markdown Base") 6 | 7 | ## Cheatsheet 8 | 9 | ![cheatsheet1](./_static/1.png) 10 | ![cheatsheet2](./_static/2.png) 11 | ![cheatsheet3](./_static/3.png) 12 | 13 | ## Others 14 | 15 | #### EMail 16 | The use is the same as LINK(\). 17 | 18 | #### Inline HTML 19 | 20 | For any markup that is not covered by Markdown’s syntax, you simply use HTML itself. There’s no need to preface it or delimit it to indicate that you’re switching from Markdown to HTML; you just use the tags. 21 | 22 | The only restrictions are that block-level HTML elements, e.g. `
, ,
, 

, etc.` must be separated from surrounding content by blank lines, and the start and end tags of the block should not be indented with tabs or spaces. Markdown is smart enough not to add extra (unwanted) `

` tags around HTML block-level tags. 23 | 24 | For example, to add an HTML table to a Markdown article: 25 | ``` 26 | This is a regular paragraph. 27 | 28 |

29 | 30 | 31 | 32 |
Foo
33 | 34 | This is another regular paragraph. 35 | ``` 36 | 37 | Note that Markdown formatting syntax is not processed within block-level HTML tags. E.g., you can’t use Markdown-style *emphasis* inside an HTML block. 38 | 39 | **`Span-level HTML tags, e.g. , , or can be used anywhere in a Markdown paragraph, list item, or header. If you want, you can even use HTML tags instead of Markdown formatting; e.g. if you’d prefer to use HTML
or tags instead of Markdown’s link or image syntax, go right ahead.`** 40 | 41 | #### Backslash Escapes 42 | Markdown provides backslash escapes for the following characters: 43 | ``` 44 | \ backslash 45 | ` backtick 46 | * asterisk 47 | _ underscore 48 | {} curly braces 49 | [] square brackets 50 | () parentheses 51 | # hash mark 52 | + plus sign 53 | - minus sign (hyphen) 54 | . dot 55 | ! exclamation mark 56 | ``` 57 | -------------------------------------------------------------------------------- /snippet/docs/document/reStructuredText/README.md: -------------------------------------------------------------------------------- 1 | 2 | reStructuredText 3 | ================ 4 | 5 | - [Quick reStructuredText](http://docutils.sourceforge.net/docs/user/rst/quickref.html) 6 | - [reStructuredText Markup Specification](http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html) 7 | - [reStructuredText 入门](http://sphinx-doc-zh.readthedocs.org/en/latest/rest.html) 8 | - [Sphinx](http://sphinx-doc-zh.readthedocs.org/en/latest/contents.html) 9 | -------------------------------------------------------------------------------- /snippet/docs/editor/vim/README.md: -------------------------------------------------------------------------------- 1 | VIM 2 | ====== 3 | - [VIM命令集](https://github.com/xgfone/dot-vimrc/blob/xgfone/docs/vim-doc.txt) 4 | - [VIM脚本语法摘录](./vim-script-syntax.md) 5 | - [VIM脚本编写第一部分:变量、值和表达式](./vim-write-script-first.md) 6 | - [VIM键盘映射(Map)](./vim-keyboard-map.md) 7 | - [vi/vim使用进阶](http://easwy.com/blog/archives/advanced-vim-skills-catalog/) 8 | - [Links](./vim/links.md) 9 | - [Others](./vim/others.md) 10 | - Plugins 11 | - [NERDTree](./vim-plugin-nerdtree.md) 12 | 13 | -------------------------------------------------------------------------------- /snippet/docs/editor/vim/_static/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/editor/vim/_static/1.png -------------------------------------------------------------------------------- /snippet/docs/editor/vim/links.md: -------------------------------------------------------------------------------- 1 | 2 | - [VIM命令集](https://github.com/xgfone/dot-vimrc/blob/xgfone/docs/vim-doc.txt) 3 | 4 | ---- 5 | 6 | ![VIM Commands](https://github.com/xgfone/dot-vimrc/blob/xgfone/docs/2.jpg) 7 | 8 | ![VIM Keyboard](https://github.com/xgfone/dot-vimrc/blob/xgfone/docs/1.jpg) 9 | -------------------------------------------------------------------------------- /snippet/docs/editor/vim/others.md: -------------------------------------------------------------------------------- 1 | 2 | ### ctags 3 | ctags -R --c++-kinds=+p --fields=+iaS --extra=+q . 4 | 5 | ### cscope 6 | ```shell 7 | # -R: 在生成索引文件时,搜索子目录树中的代码 8 | # -b: 只生成索引文件,不进入cscope的界面 9 | # -k: 在生成索引文件时,不搜索/usr/include目录 10 | # -q: 生成cscope.in.out和cscope.po.out文件,加快cscope的索引速度 11 | $ cscope -Rbkq 12 | ``` 13 | 14 | ```shell 15 | #!/bin/sh 16 | 17 | find . -name "*.h" -o -name "*.c"-o -name "*.cc" -o -name "*.cpp" -o -name "*.hpp" > cscope.files 18 | cscope -bkq -i cscope.files 19 | ctags -R --c++-kinds=+p --fields=+iaS --extra=+q . 20 | ``` 21 | -------------------------------------------------------------------------------- /snippet/docs/encoding/README.md: -------------------------------------------------------------------------------- 1 | 2 | - [XML参考手册](http://www.runoob.com/svg/svg-reference.html) 3 | -------------------------------------------------------------------------------- /snippet/docs/go/_static/package-init.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/go/_static/package-init.png -------------------------------------------------------------------------------- /snippet/docs/go/go-learning-note.md: -------------------------------------------------------------------------------- 1 | 2 | Go语言笔记 3 | ========= 4 | 5 | Go语言是由Google主导开发的完全开源的编程语言,主要开发人员由贝尔实验室原UNIX开发人员组成,其中就有B语言和UNIX之父(肯.汤普森,它和丹尼斯一起用C语言重写了UNIX系统,而且原贝尔实验室的C编译器就是由汤普森开发的——曾有个小故事,说是汤普森在C编译器中预留了一个BUG,在编译UNIX内核时,可以自动在UNIX系统中留下一个后门,这造成了汤普森可以入侵贝尔实验室里的任何一台UNIX系统)。**`Go语言被称为二十一世纪的、互联网时代的C语言`**。 6 | 7 | Go语言被设计为: 8 | 9 | (1)有C语言的速度,高性能; 10 | (2)能够做系统编程; 11 | (3)有动态语言的某些特性,如:垃圾回收机制——动态分配的内存会自动释放而不需要手工释放; 12 | (4)有面向对象的某些特性,如:支持属性和方法; 13 | (5)能省则省,不需要输入的字符一律可省略不写; 14 | (6)Erlang的高并发——通过goroutine来实现,用着更简单:只需要在函数或方法调用前添加一个go关键字即可。 15 | (7)去掉繁琐的语言概念和实现,如:面向对象中的构造、析构、继承、重载、多态等等,但Go通过struct包含、 16 | interface包含、interface赋值等分别实现了面向对象中的继承、重载(不包括运算符重载,Go不支持运算符重载)、 17 | 多态等功能,而且Go的实现更加简单; 18 | ........ 19 | 20 | 21 | ## 前言 22 | 23 | 除非特别指明,下文描述指 `GO1` 的语言规范。 24 | 25 | 在早期(即第一个正式版本GO1之前),GO 实现了gc、6c等编译工具,但从GO1开始,GO不再显示地提供这些工具,而提供了GO工具链go程序,它可以自动化查找依赖并编译大型软件,还可以修复、格式化程序,等等。另外,GO语言也为gcc编写了前端(即gccgo),因此也可以使用gccgo来编译GO程序。但是由于gccgo的滞后性等等原因,并不建议使用gccgo,而是直接使用go工具链,它专门被设计用来编译大型程序的,不需要像C/C++那样还要写大量的Makefile文件,go工具链自动查找、解决依赖关系。 26 | 27 | -------------------------------------------------------------------------------- /snippet/docs/go/go-std-lib.md: -------------------------------------------------------------------------------- 1 | 2 | 库 3 | === 4 | 5 | ## 1. time 6 | 7 | (1) 格式化时间时,必须使用Golang的诞生日:`2006-01-02 15:04:05`; 记忆方法:`6-1-2-3-4-5`。 8 | 9 | (2) 时间戳: 10 | ```go 11 | time.Now().Unix() // 1389058332 12 | ``` 13 | 14 | (3) str格式化时间: 15 | ```go 16 | time.Now().Format("2006-01-02 15:04:05") // 2014-01-07 09:42:20 17 | ``` 18 | 19 | (4) 时间戳转str格式化时间: 20 | ```go 21 | time.Unix(1389058332, 0).Format("2006-01-02 15:04:05") // 2014-01-07 09:32:12 22 | ``` 23 | 24 | (5) str格式化时间转时间戳: 25 | 26 | **方法一:** 27 | ```go 28 | time.Date(2014, 1, 7, 5, 50, 4, 0, time.Local).Unix() // 389045004 29 | ``` 30 | 31 | **方法二:** 32 | ```go 33 | the_time, err := time.Parse("2006-01-02 15:04:05", "2014-01-08 09:04:41") 34 | if err == nil { 35 | unix_time := the_time.Unix() 36 | fmt.Println(unix_time) // 1389171881 37 | } 38 | ``` 39 | -------------------------------------------------------------------------------- /snippet/docs/java/README.md: -------------------------------------------------------------------------------- 1 | 2 | - [Packages](./packages.md) 3 | -------------------------------------------------------------------------------- /snippet/docs/java/packages.md: -------------------------------------------------------------------------------- 1 | 2 | ##### [jOOQ](https://github.com/jOOQ/jOOQ) 3 | jOOQ is an innovative solution for a better integration of Java applications with popular databases 4 | like Oracle, Microsoft SQL Server, IBM DB2, or SAP Sybase. When using jOOQ, our customers benefit 5 | from a significant added value and ROI as their software developers can express database queries 6 | in a much simpler and faster way. 7 | 8 | ##### [Hystrix](https://github.com/Netflix/Hystrix) 9 | Hystrix is a latency and fault tolerance library designed to isolate points of access to remote systems, 10 | services and 3rd party libraries, stop cascading failure and enable resilience in complex distributed 11 | systems where failure is inevitable. 12 | -------------------------------------------------------------------------------- /snippet/docs/js/_static/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/js/_static/1.jpg -------------------------------------------------------------------------------- /snippet/docs/js/_static/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/js/_static/2.jpg -------------------------------------------------------------------------------- /snippet/docs/js/_static/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/js/_static/3.png -------------------------------------------------------------------------------- /snippet/docs/js/faq.md: -------------------------------------------------------------------------------- 1 | 2 | ## 1. `node-gpy` failed to build the C/C++ package on Windows. 3 | 4 | Run `npm install --global --production windows-build-tools`. 5 | 6 | **Notice:** Reference to https://github.com/nodejs/node-gyp#installation. 7 | 8 | 9 | ## 2. `shim` 和 `polyfill` 有什么区别? 10 | 11 | `shim` 是一个库,它将一个新的 API 引入到一个旧的环境中,而且仅靠旧环境中已有的技术实现,有时候也称 `shiv`。 12 | 13 | `polyfill` 是一段代码(或者插件),提供那些开发者们希望 **浏览器** 原生提供支持的功能。因此,一个 `polyfill` 就是一个用在浏览器 API 上的 `shim`。通常的做法是先检查当前浏览器是否支持某个 API,如果不支持的话就加载对应的 `polyfill`。然后新旧浏览器就都可以使用这个 API 了。 14 | 15 | **Reference:** https://remysharp.com/2010/10/08/what-is-a-polyfill. 16 | -------------------------------------------------------------------------------- /snippet/docs/js/javascript.md: -------------------------------------------------------------------------------- 1 | 2 | 1、一个语句不能以一个函数表达式开关。由于官方的语法假定以单词 function 开关的语句是一个 function 语句,因此解决此问题的方法是把函数表达式放在一个圆括号之内。如: 3 | ```js 4 | (function () { 5 | var variable; 6 | })(); 7 | ``` 8 | 9 | 2、JavaScript 中的每个异步函数都构建在其他某个或某些异步函数之上。凡是异步函数,从上到下(一直到原生代码)都是异步的!反之亦然:任何函数只要使用了异步的函数,就必须以异步的方式给出其操作结果。 10 | 11 | 3、请避免使用计时器方法来等待某个会变化的东西。如果同一个函数既返值又运行回调,则请确保回调在返值之后才运行。 12 | -------------------------------------------------------------------------------- /snippet/docs/js/webpack-plugins.md: -------------------------------------------------------------------------------- 1 | 2 | ## The Official Plugins 3 | 4 | - DefinePlugin | EnvironmentPlugin 5 | - DllPlugin 6 | - DedupePlugin 7 | - ProvidePlugin 8 | - UglifyJSPlugin 9 | - ExternalsPlugin 10 | - DllReferencePlugin 11 | - NamedModulesPlugin 12 | - CommonsChunkPlugin 13 | - MinChunkSizePlugin 14 | - HotModuleReplacementPlugin 15 | 16 | 17 | ## The Third-Party Plugins 18 | 19 | - [webpack-merge](https://github.com/survivejs/webpack-merge) 20 | 21 | Merge designed for Webpack. 22 | 23 | - [copy-webpack-plugin](https://github.com/kevlened/copy-webpack-plugin) 24 | 25 | Copy files and directories in webpack. 26 | 27 | - [extract-text-webpack-plugin](https://github.com/webpack-contrib/extract-text-webpack-plugin) 28 | 29 | Extract CSS text from bundle into a file. 30 | 31 | - [html-webpack-plugin](https://github.com/jantimon/html-webpack-plugin) 32 | 33 | Simplifies creation of HTML files to serve your webpack bundles. 34 | 35 | - [chunk-manifest-webpack-plugin](https://github.com/soundcloud/chunk-manifest-webpack-plugin) 36 | Allows exporting a manifest that maps entry chunk names to their output files, 37 | instead of keeping the mapping inside the webpack bootstrap. 38 | 39 | - [stats-webpack-plugin](https://github.com/unindented/stats-webpack-plugin) 40 | 41 | Write the stats of a build to a file. 42 | -------------------------------------------------------------------------------- /snippet/docs/kubernetes/README.md: -------------------------------------------------------------------------------- 1 | - [Kubernetes Handbook](https://github.com/feiskyer/kubernetes-handbook)(点击 [阅读](https://kubernetes.feisky.xyz/)) 2 | -------------------------------------------------------------------------------- /snippet/docs/linux/QoS/README.md: -------------------------------------------------------------------------------- 1 | 2 | - [理论篇](./qos-theory.md) 3 | - [应用篇](./qos-use.md) 4 | - [过滤器](./qos-filter.md) 5 | - [HTB使用例子](./htb-example.md) 6 | - [HTB使用例子2](./htb-example2.md) 7 | - [HTB入队规则手册————用户向导](./htb-user-guide.md) 8 | - [其它资源](./link.md) 9 | - [TC man](http://man7.org/linux/man-pages/man8/tc.8.html) 10 | - [TC U32 man](http://man7.org/linux/man-pages/man8/tc-u32.8.html) ([源码](https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/tree/tc/f_u32.c)) 11 | -------------------------------------------------------------------------------- /snippet/docs/linux/QoS/_static/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/QoS/_static/1.jpg -------------------------------------------------------------------------------- /snippet/docs/linux/QoS/_static/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/QoS/_static/2.jpg -------------------------------------------------------------------------------- /snippet/docs/linux/QoS/_static/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/QoS/_static/3.jpg -------------------------------------------------------------------------------- /snippet/docs/linux/QoS/_static/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/QoS/_static/4.jpg -------------------------------------------------------------------------------- /snippet/docs/linux/QoS/_static/5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/QoS/_static/5.jpg -------------------------------------------------------------------------------- /snippet/docs/linux/QoS/_static/6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/QoS/_static/6.jpg -------------------------------------------------------------------------------- /snippet/docs/linux/QoS/_static/7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/QoS/_static/7.jpg -------------------------------------------------------------------------------- /snippet/docs/linux/QoS/_static/8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/QoS/_static/8.jpg -------------------------------------------------------------------------------- /snippet/docs/linux/QoS/_static/9.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/QoS/_static/9.jpg -------------------------------------------------------------------------------- /snippet/docs/linux/QoS/_static/htb-queue-discipline-diagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/QoS/_static/htb-queue-discipline-diagram.png -------------------------------------------------------------------------------- /snippet/docs/linux/QoS/link.md: -------------------------------------------------------------------------------- 1 | 2 | [Linux QoS](http://web.opalsoft.net/qos/default.php?p=linux101-ds) 3 | -------------------------------------------------------------------------------- /snippet/docs/linux/QoS/tc-doc/cls_fw.txt: -------------------------------------------------------------------------------- 1 | The IPChains fwmark classifier 2 | ------------------------------ 3 | 4 | Handles. 5 | 6 | The handle for the fwmark is the "fwmark" set by ipchains 7 | or iptables. Like all filter handles it must be unique. 8 | 9 | Execution. 10 | 11 | The fwmark filter finds filter item whose handle equals 12 | the "fwmark" value ipchains or iptables set for the packet. 13 | If the filter item is found the packet is classified, 14 | otherwise not. 15 | 16 | Be warned that the fwmark currently (2.4.9) uses a primitive 17 | hash table to do the searching. The hash table is 256 bytes 18 | long, and the "hash function" just extracts the eight least 19 | significant bits. So don't use fwmark's that differ by 20 | largish powers of 2. 21 | 22 | Options. 23 | 24 | classid :: | flowid :: 25 | This is required. It :classifies: the packet. 26 | 27 | police :: 28 | :Police: the packet. 29 | 30 | Comments. 31 | 32 | IPChains is the most powerful packet recognition engine 33 | available in the kernel, and using it to set "fwmark" is a 34 | relatively straight forward job. "fwmark" is the easiest 35 | classifier to use by far. It is a unique combination - use 36 | it where you can. 37 | -------------------------------------------------------------------------------- /snippet/docs/linux/QoS/tc-doc/sch_bfifo.txt: -------------------------------------------------------------------------------- 1 | The bfifo queuing discipline 2 | ---------------------------- 3 | 4 | Parameters. 5 | 6 | limit NUMBER 7 | This is maximum number of bytes that can be on this queue. 8 | Enqueuing a packet when the queue is at or above this limit 9 | causes the packet to be dropped. A packet will be sent 10 | provided it is enqueued when the queue is below this limit, 11 | even if adding the packet will take the queue above this 12 | limit. If not specified this parameter defaults to the queue 13 | length of the underlying device multiplied by the maximum 14 | transmission unit for the device. These are the qlen and mtu 15 | parameters printed by "ip link list". 16 | 17 | Classes. The bfifo queuing discipline does not have classes. 18 | The packets are sent in the order they are received. 19 | 20 | Scheduling. The bfifo queuing discipline has not have a scheduler. 21 | 22 | Policing. Enqueuing a packet when the queue already contains, or 23 | has more than, the number of bytes defined by the limit parameter 24 | will cause the packet to be dropped. 25 | 26 | Rate limiting. The bfifo queuing discipline does not rate limit 27 | traffic. 28 | 29 | Classifier. The bfifo queuing discipline does not classify packets. 30 | 31 | 32 | Comments. 33 | 34 | - bfifo polices the length of the queue, ensuring it does not grow 35 | beyond the maximum limit defined by it parameter. That is all it 36 | does. 37 | -------------------------------------------------------------------------------- /snippet/docs/linux/QoS/tc-doc/sch_noop.txt: -------------------------------------------------------------------------------- 1 | The noop queuing discipline 2 | --------------------------- 3 | 4 | Parameters. 5 | None. 6 | 7 | Classes. The noop queuing discipline does not have classes. 8 | 9 | Scheduling. The noop queuing discipline has not have a scheduler. 10 | 11 | Policing. The noop queuing discipline drops all packets queued onto 12 | it. 13 | 14 | Rate limiting. The noop queuing discipline does not rate limit 15 | traffic. 16 | 17 | Classifier. The noop queuing discipline does not classify packets. 18 | 19 | 20 | Comments. 21 | 22 | - The noop queuing discipline is used internally by the traffic control 23 | engine. It is not possible to manually assign the noop queuing 24 | discipline to a device or class. 25 | 26 | - The noop queuing discipline is assigned to all devices when they are 27 | created and the device's link state (as printed by "ip link list") 28 | is down. When the link state is changed to up the noop queuing 29 | discipline, if still present, is replaced by a pfifo_fast or noqueue 30 | queuing discipline. 31 | 32 | - Yes, the noop queuing discipline really does drop, delete and discard 33 | all packets queued onto it. 34 | -------------------------------------------------------------------------------- /snippet/docs/linux/QoS/tc-doc/sch_noqueue.txt: -------------------------------------------------------------------------------- 1 | The noqueue queuing discipline 2 | ------------------------------ 3 | 4 | Parameters. 5 | None. 6 | 7 | Classes. The noqueue queuing discipline does not have classes. 8 | 9 | Scheduling. The noqueue queuing discipline has not have a scheduler. 10 | 11 | Policing. The noqueue queuing discipline drops all packets queued onto 12 | it. 13 | 14 | Rate limiting. The noqueue queuing discipline does not rate limit 15 | traffic. 16 | 17 | Classifier. The noqueue queuing discipline does not classify packets. 18 | 19 | 20 | Comments. 21 | 22 | - Although the noqueue queuing discipline does drop all packets 23 | queued onto it, in practice that never happens. Instead when 24 | a packet is sent over a device it checks if it is using the 25 | "noqueue" discipline. If so the device sends the packet 26 | immediately, or drops it if it can't be sent. Thus the 27 | noqueue discipline really means "don't queue this packet". 28 | 29 | - noqueue is the queuing discipline that is used by default 30 | for :virtual: devices, meaning it is the queuing discipline 31 | installed when a virtual device is first created. It is 32 | also the queuing discipline used after you "tc qdisc del" 33 | another queuing discipline from a virtual device. 34 | 35 | - You can _not_ manually change a queuing discipline for a 36 | device or class to noqueue using "tc qdisc add noqueue". You can 37 | get around this for virtual devices by deleting their queuing 38 | discipline. It is not possible to assign the noqueue queuing 39 | discipline to physical devices or classes. 40 | -------------------------------------------------------------------------------- /snippet/docs/linux/QoS/tc-doc/sch_pfifo.txt: -------------------------------------------------------------------------------- 1 | The pfifo queuing discipline 2 | ---------------------------- 3 | 4 | Parameters. 5 | 6 | limit NUMBER 7 | This is maximum number of packets that can be on this queue. 8 | Enqueuing a packet when the queue is at this limit causes the 9 | packet to be dropped. If not specified this parameter defaults 10 | to the queue length of the underlying device. This is the qlen 11 | parameter printed by "ip link list". 12 | 13 | Classes. The pfifo queuing discipline does not have classes. 14 | 15 | Scheduling. The pfifo queuing discipline has not have a scheduler. 16 | The packets are sent in the order they are received. 17 | 18 | Policing. Enqueuing a packet when the queue already contains the 19 | number of packets defined by the limit parameter will cause the 20 | packet to be dropped. 21 | 22 | Classifier. The pfifo queuing discipline does not classify packets. 23 | 24 | Rate limiting. The pfifo queuing discipline does not rate limit 25 | traffic. 26 | 27 | Comments. 28 | 29 | - pfifo polices the length of the queue, ensuring it does not grow 30 | beyond the maximum limit defined by it parameter. That is all it 31 | does. 32 | -------------------------------------------------------------------------------- /snippet/docs/linux/diskio/fio.md: -------------------------------------------------------------------------------- 1 | 2 | 测试磁盘IO读写性能 3 | ================ 4 | 5 | #### 随机读 6 | ```shell 7 | fio –bs=512 –ioengine=libaio –userspace_reap –time_based –runtime=60 \ 8 | –group_reporting –buffered=0 –direct=1 –randrepeat=0 –norandommap \ 9 | –ramp_time=6 –iodepth=16 –numjobs=16 –size=100G –name=randread –rw=randread \ 10 | –directory=/md –filename=fio-test.file –output=/data/log/fio-r.txt 11 | ``` 12 | 13 | #### 随机写 14 | ```shell 15 | fio –bs=512 –ioengine=libaio –userspace_reap –time_based –runtime=60 \ 16 | –group_reporting –buffered=0 –direct=1 –randrepeat=0 –norandommap \ 17 | –ramp_time=6 –iodepth=16 –numjobs=16 –size=100G –name=randwrite –rw=randwrite \ 18 | –directory=/md –filename=fio-test.file –output=/data/log/fio-w.txt 19 | ``` 20 | 21 | #### 混合读写 22 | ```shell 23 | fio –bs=512 –ioengine=libaio –userspace_reap –time_based –runtime=60 \ 24 | –group_reporting –buffered=0 –direct=1 –randrepeat=0 –norandommap \ 25 | –ramp_time=6 –iodepth=16 –numjobs=16 –size=100G –name=randmixed –rwmixwrite=20 –rw=randrw\ 26 | –directory=/md –filename=fio-test.file –output=/data/log/fio-m.txt 27 | ``` 28 | -------------------------------------------------------------------------------- /snippet/docs/linux/iproute2/_static/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/iproute2/_static/1.png -------------------------------------------------------------------------------- /snippet/docs/linux/iproute2/_static/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/iproute2/_static/2.png -------------------------------------------------------------------------------- /snippet/docs/linux/iproute2/_static/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/iproute2/_static/3.png -------------------------------------------------------------------------------- /snippet/docs/linux/iproute2/_static/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/iproute2/_static/4.png -------------------------------------------------------------------------------- /snippet/docs/linux/iproute2/_static/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/iproute2/_static/5.png -------------------------------------------------------------------------------- /snippet/docs/linux/iproute2/_static/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/iproute2/_static/6.png -------------------------------------------------------------------------------- /snippet/docs/linux/iproute2/_static/7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/iproute2/_static/7.jpg -------------------------------------------------------------------------------- /snippet/docs/linux/iproute2/_static/iproute2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/iproute2/_static/iproute2.png -------------------------------------------------------------------------------- /snippet/docs/linux/ipv4/system-config.md: -------------------------------------------------------------------------------- 1 | 2 | ## TCP高并发连接 3 | 对于想支持更高数量的TCP并发连接的通讯处理程序,就必须修改Linux对当前用户的进程同时打开的文件数量的软限制(soft limit)和硬限制(hardlimit)。其中软限制是指Linux在当前系统能够承受的范围内进一步限制用户同时打开的文件数;硬限制则是根据系统硬件资源状况(主要是系统内存)计算出来的系统最多可同时打开的文件数量。通常软限制小于或等于硬限制。 4 | 5 | 6 | ### 提高Linux系统级的最大打开文件数限制 7 | ```shell 8 | echo 1024000 > /proc/sys/fs/file-max 9 | ``` 10 | 这是Linux系统级硬限制,所有用户级的打开文件数(即所有用户打开文件数总和)限制都不应超过这个数值。通常这个系统级硬限制是Linux系统在启动时根据系统硬件资源状况计算出来的最佳的最大同时打开文件数限制,如果没有特殊需要,不应该修改此限制,除非想为用户级打开文件数限制设置超过此限制的值。 11 | 12 | 13 | ### 修改用户进程可打开文件数限制 14 | 使用`ulimit`命令查看、修改系统允许当前用户每个进程打开的文件数限制。 15 | ```shell 16 | ulimit -u [102400] 17 | ``` 18 | 如果系统回显类似于“`Operation notpermitted`”之类的话,说明上述修改失败,一般是因为`ulimit`指定的数值超过了Linux系统对该用户打开文件数的软限制或硬限制。因此,就需要修改Linux系统对用户的关于打开文件数的软限制和硬限制。 19 | 20 | (1) 修改`/etc/security/limits.conf`文件,在文件中添加如下行: 21 | ``` 22 | USERNAME soft nofile 102400 23 | USERNAME hard nofile 102400 24 | ``` 25 | 注:可用'`*`'号表示修改所有用户的限制。 26 | 27 | (2) 修改`/etc/pam.d/login`文件,在文件中添加如下行: 28 | ```shell 29 | session required /lib/security/pam_limits.so 30 | ``` 31 | 这是告诉Linux在用户完成系统登录后,应该调用`pam_limits.so`模块来设置系统对该用户可使用的各种资源数量的最大限制(包括用户可打开的最大文件数限制),而`pam_limits.so`模块就会从`/etc/security/limits.conf`文件中读取配置来设置这些限制值。 32 | 33 | 34 | ### 修改网络内核对TCP连接的有关限制 35 | ```shell 36 | ## /etc/sysctl.conf 37 | net.ipv4.ip_forward=1 38 | net.ipv4.ip_conntrack_max = 102400 39 | net.ipv4.ip_local_port_range = 1024 65536 40 | 41 | net.core.rmem_max = 16777216 42 | net.core.wmem_max = 16777216 43 | net.core.somaxconn = 262144 44 | net.core.netdev_max_backlog = 30000 45 | 46 | net.ipv4.route.flush=1 47 | net.ipv4.tcp_rmem = 4096 87380 16777216 48 | net.ipv4.tcp_wmem = 4096 65536 16777216 49 | net.ipv4.tcp_fin_timeout = 10 50 | net.ipv4.tcp_tw_recycle = 1 51 | net.ipv4.tcp_timestamps = 1 52 | net.ipv4.tcp_window_scaling = 0 53 | net.ipv4.tcp_sack = 0 54 | net.ipv4.tcp_no_metrics_save=1 55 | net.ipv4.tcp_syncookies = 0 56 | net.ipv4.tcp_max_orphans = 262144 57 | net.ipv4.tcp_max_syn_backlog = 262144 58 | net.ipv4.tcp_synack_retries = 2 59 | net.ipv4.tcp_syn_retries = 2 60 | ``` 61 | 然后执行如下命令使其生效: 62 | ```shell 63 | /sbin/sysctl -p /etc/sysctl.conf 64 | ``` 65 | -------------------------------------------------------------------------------- /snippet/docs/linux/kernel/README.md: -------------------------------------------------------------------------------- 1 | 2 | - [Linux Kernel Map](./_static/linux-kernel-map.png)(点击 [这里](https://github.com/xgfone/snippet/raw/master/snippet/docs/linux/kernel/_static/linux-kernel-map.png) 看大图) 3 | -------------------------------------------------------------------------------- /snippet/docs/linux/kernel/_static/linux-kernel-map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/kernel/_static/linux-kernel-map.png -------------------------------------------------------------------------------- /snippet/docs/linux/netfilter/_static/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/netfilter/_static/1.png -------------------------------------------------------------------------------- /snippet/docs/linux/netfilter/_static/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/netfilter/_static/10.png -------------------------------------------------------------------------------- /snippet/docs/linux/netfilter/_static/11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/netfilter/_static/11.png -------------------------------------------------------------------------------- /snippet/docs/linux/netfilter/_static/12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/netfilter/_static/12.png -------------------------------------------------------------------------------- /snippet/docs/linux/netfilter/_static/13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/netfilter/_static/13.png -------------------------------------------------------------------------------- /snippet/docs/linux/netfilter/_static/14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/netfilter/_static/14.png -------------------------------------------------------------------------------- /snippet/docs/linux/netfilter/_static/15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/netfilter/_static/15.png -------------------------------------------------------------------------------- /snippet/docs/linux/netfilter/_static/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/netfilter/_static/2.png -------------------------------------------------------------------------------- /snippet/docs/linux/netfilter/_static/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/netfilter/_static/3.png -------------------------------------------------------------------------------- /snippet/docs/linux/netfilter/_static/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/netfilter/_static/4.png -------------------------------------------------------------------------------- /snippet/docs/linux/netfilter/_static/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/netfilter/_static/5.png -------------------------------------------------------------------------------- /snippet/docs/linux/netfilter/_static/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/netfilter/_static/6.png -------------------------------------------------------------------------------- /snippet/docs/linux/netfilter/_static/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/netfilter/_static/7.png -------------------------------------------------------------------------------- /snippet/docs/linux/netfilter/_static/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/netfilter/_static/8.png -------------------------------------------------------------------------------- /snippet/docs/linux/netfilter/_static/9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/netfilter/_static/9.png -------------------------------------------------------------------------------- /snippet/docs/linux/netfilter/_static/p1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/netfilter/_static/p1.png -------------------------------------------------------------------------------- /snippet/docs/linux/netfilter/_static/p2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/netfilter/_static/p2.png -------------------------------------------------------------------------------- /snippet/docs/linux/netfilter/link.md: -------------------------------------------------------------------------------- 1 | 2 | [Iptables 指南 1.1.19](http://man.chinaunix.net/network/iptables-tutorial-cn-1.1.19.html) 3 | 4 | IPtables Rule Hook 5 | 6 | ![IPtables Rule Hook](./_static/p1.png) 7 | 8 | ------ 9 | 10 | NetFilter Hook Point 11 | 12 | ![NetFilter Hook Point](./_static/p2.png) 13 | -------------------------------------------------------------------------------- /snippet/docs/linux/netlink/_static/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/netlink/_static/1.jpg -------------------------------------------------------------------------------- /snippet/docs/linux/netlink/_static/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/netlink/_static/2.jpg -------------------------------------------------------------------------------- /snippet/docs/linux/netlink/_static/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/netlink/_static/3.jpg -------------------------------------------------------------------------------- /snippet/docs/linux/netlink/netlink-implementation-analyzation.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/netlink/netlink-implementation-analyzation.pdf -------------------------------------------------------------------------------- /snippet/docs/linux/others/README.md: -------------------------------------------------------------------------------- 1 | 2 | - [Linux Bridge - how it works](https://goyalankit.com/blog/linux-bridge) 3 | - [How to find namespaces in a Linux system](http://www.opencloudblog.com/?p=251) 4 | - [Linux Switching – Interconnecting Namespaces](http://www.opencloudblog.com/?p=66) 5 | - [Switching Performance – Connecting Linux Network Namespaces](http://www.opencloudblog.com/?p=96) 6 | - [Switching Performance – Chaining OVS bridges](http://www.opencloudblog.com/?p=386) 7 | - [Linux Socket Listen Backlog](./snippet/docs/linux/others/backlog.md) 8 | - [跟我一起修改 Gnome Shell theme](./snippet/docs/linux/others/customize-gnome-shell.md) 9 | - [Linux性能分析与调优](./snippet/docs/linux/others/linux-performance-analysis-and-optimization.md) 10 | - [设置 Linux 的分辨率](http://blog.csdn.net/smilematch/article/details/50482530)【[脚本](../../../bin/shell/set_display_resolution.py)】 11 | -------------------------------------------------------------------------------- /snippet/docs/linux/others/_static/backlog.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/others/_static/backlog.png -------------------------------------------------------------------------------- /snippet/docs/linux/others/_static/css-selector.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/others/_static/css-selector.png -------------------------------------------------------------------------------- /snippet/docs/linux/others/_static/gnome-shell-calemdar-fore.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/others/_static/gnome-shell-calemdar-fore.png -------------------------------------------------------------------------------- /snippet/docs/linux/others/_static/gnome-shell-calendar-post.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/others/_static/gnome-shell-calendar-post.png -------------------------------------------------------------------------------- /snippet/docs/linux/others/_static/gnome-shell-main.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/others/_static/gnome-shell-main.png -------------------------------------------------------------------------------- /snippet/docs/linux/others/_static/gnome-shell-min-width-fore.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/others/_static/gnome-shell-min-width-fore.png -------------------------------------------------------------------------------- /snippet/docs/linux/others/_static/gnome-shell-min-width-post.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/others/_static/gnome-shell-min-width-post.png -------------------------------------------------------------------------------- /snippet/docs/linux/others/_static/gnome-shell-overview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/others/_static/gnome-shell-overview.png -------------------------------------------------------------------------------- /snippet/docs/linux/others/_static/gnome-shell-status-icon-hpadding-fore.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/others/_static/gnome-shell-status-icon-hpadding-fore.png -------------------------------------------------------------------------------- /snippet/docs/linux/others/_static/gnome-shell-status-icon-hpadding-post.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/others/_static/gnome-shell-status-icon-hpadding-post.png -------------------------------------------------------------------------------- /snippet/docs/linux/others/_static/gnome-shell-toggle-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/others/_static/gnome-shell-toggle-1.png -------------------------------------------------------------------------------- /snippet/docs/linux/others/linux-info.md: -------------------------------------------------------------------------------- 1 | 2 | Linux 查看系统信息命令 3 | ==================== 4 | 5 | - `cat /etc/issue`:查看操作系统版本 6 | - `cat /proc/cpuinfo`:查看CPU相关参数 7 | - `cat /proc/partitions`:查看硬盘和分区 8 | - `cat /proc/meminfo`:查看内存信息 9 | - `cat /proc/version`:查看版本,类似uname -r 10 | - `cat /proc/ioports`:查看设备io端口 11 | - `cat /proc/interrupts`:查看中断 12 | - `cat /proc/pci`:查看pci设备的信息 13 | - `cat /proc/swaps`:查看所有swap分区的信息 14 | - `cat /proc/version`:查看内核 15 | - `cat /proc/loadavg`:查看系统负载磁盘和分区 16 | - `cat /proc/cpuinfo`:查看CPU信息 17 | - `crontab -l`:查看当前用户的计划任务服务 18 | - `chkconfig –list`:列出所有系统服务 19 | - `chkconfig –list | grep on`:列出所有启动的系统服务程序 20 | - `cut -d: -f1 /etc/passwd`:查看系统所有用户 21 | - `cut -d: -f1 /etc/group`:查看系统所有组 22 | - `df -h`:查看各分区使用情况 23 | - `dmesg | grep IDE`:查看启动时IDE设备检测状况网络 24 | - `du -sh <目录名>`:查看指定目录的大小 25 | - `env`:查看环境变量资源 26 | - `fdisk -l`:查看所有分区 27 | - `free -m`:查看内存使用量和交换区使用量 28 | - `grep MemTotal /proc/meminfo`:查看内存总量 29 | - `grep MemFree /proc/meminfo`:查看空闲内存量 30 | - `head -n 1 /etc/issue`:查看操作系统版本 31 | - `hdparm -i /dev/hda`:查看磁盘参数(仅适用于IDE设备) 32 | - `hostname`:查看计算机名 33 | - `id <用户名>`:查看指定用户信息 34 | - `ifconfig`:查看所有网络接口的属性 35 | - `iptables -L`:查看防火墙设置 36 | - `last`:查看用户登录日志 37 | - `lspci -tv`:列出所有PCI设备 38 | - `lsusb -tv`:列出所有USB设备 39 | - `lsmod`:列出加载的内核模块 40 | - `mount | column -t`:查看挂接的分区状态 41 | - `netstat -lntp`:查看所有监听端口 42 | - `netstat -antp`:查看所有已经建立的连接 43 | - `netstat -s`:查看网络统计信息进程 44 | - `ps -ef`:查看所有进程 45 | - `route -n`:查看路由表 46 | - `swapon -s`:查看所有交换分区 47 | - `top`:实时显示进程状态用户 48 | - `uname -a`:查看内核/操作系统/CPU信息 49 | - `uptime`:查看系统运行时间、用户数、负载 50 | - `w`:查看活动用户 51 | -------------------------------------------------------------------------------- /snippet/docs/linux/program/_static/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/program/_static/1.png -------------------------------------------------------------------------------- /snippet/docs/linux/program/_static/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/program/_static/10.png -------------------------------------------------------------------------------- /snippet/docs/linux/program/_static/11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/program/_static/11.png -------------------------------------------------------------------------------- /snippet/docs/linux/program/_static/12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/program/_static/12.png -------------------------------------------------------------------------------- /snippet/docs/linux/program/_static/13.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/program/_static/13.jpg -------------------------------------------------------------------------------- /snippet/docs/linux/program/_static/14.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/program/_static/14.jpg -------------------------------------------------------------------------------- /snippet/docs/linux/program/_static/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/program/_static/2.png -------------------------------------------------------------------------------- /snippet/docs/linux/program/_static/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/program/_static/3.jpg -------------------------------------------------------------------------------- /snippet/docs/linux/program/_static/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/program/_static/4.png -------------------------------------------------------------------------------- /snippet/docs/linux/program/_static/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/program/_static/5.png -------------------------------------------------------------------------------- /snippet/docs/linux/program/_static/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/program/_static/6.png -------------------------------------------------------------------------------- /snippet/docs/linux/program/_static/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/program/_static/7.png -------------------------------------------------------------------------------- /snippet/docs/linux/program/_static/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/program/_static/8.png -------------------------------------------------------------------------------- /snippet/docs/linux/program/_static/9.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/program/_static/9.jpg -------------------------------------------------------------------------------- /snippet/docs/linux/tap/README.md: -------------------------------------------------------------------------------- 1 | 2 | - [Tun/Tap Interface Tutorial](http://backreference.org/2010/03/26/tuntap-interface-tutorial/) 3 | - [虚拟网卡 TUN/TAP 驱动程序设计原理](./tap-tun.md) 4 | -------------------------------------------------------------------------------- /snippet/docs/linux/tap/_static/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/tap/_static/1.jpg -------------------------------------------------------------------------------- /snippet/docs/linux/tap/_static/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/tap/_static/2.jpg -------------------------------------------------------------------------------- /snippet/docs/linux/tap/_static/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/linux/tap/_static/3.jpg -------------------------------------------------------------------------------- /snippet/docs/network/nat/_static/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/network/nat/_static/1.png -------------------------------------------------------------------------------- /snippet/docs/network/nat/_static/10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/network/nat/_static/10.jpg -------------------------------------------------------------------------------- /snippet/docs/network/nat/_static/11.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/network/nat/_static/11.jpg -------------------------------------------------------------------------------- /snippet/docs/network/nat/_static/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/network/nat/_static/2.png -------------------------------------------------------------------------------- /snippet/docs/network/nat/_static/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/network/nat/_static/3.png -------------------------------------------------------------------------------- /snippet/docs/network/nat/_static/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/network/nat/_static/4.png -------------------------------------------------------------------------------- /snippet/docs/network/nat/_static/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/network/nat/_static/5.png -------------------------------------------------------------------------------- /snippet/docs/network/nat/_static/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/network/nat/_static/6.png -------------------------------------------------------------------------------- /snippet/docs/network/nat/_static/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/network/nat/_static/7.png -------------------------------------------------------------------------------- /snippet/docs/network/nat/_static/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/network/nat/_static/8.png -------------------------------------------------------------------------------- /snippet/docs/network/nat/_static/9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/network/nat/_static/9.png -------------------------------------------------------------------------------- /snippet/docs/network/others/userspace-net-stack.md: -------------------------------------------------------------------------------- 1 | 2 | #### [DPDK](http://dpdk.org/) 3 | DPDK is a set of libraries and drivers for fast packet processing. It was designed to run on any processors. 4 | The first supported CPU was Intel x86 and it is now extended to IBM Power 8, EZchip TILE-Gx and ARM. 5 | It runs mostly in Linux userland. A FreeBSD port is available for a subset of DPDK features. 6 | 7 | DPDK is not a networking stack and does not provide functions such as Layer-3 forwarding, firewalling, etc. 8 | 9 | #### [netmap](https://github.com/luigirizzo/netmap) 10 | NETMAP is a framework for very fast packet I/O from userspace. 11 | VALE is an equally fast in-kernel software switch using the netmap API. 12 | Both are implemented as a single kernel module for FreeBSD, Linux and since summer 2015, also for Windows. 13 | 14 | #### [mtcp](https://github.com/eunyoung14/mtcp) 15 | A Highly Scalable User-level TCP Stack for Multicore Systems 16 | -------------------------------------------------------------------------------- /snippet/docs/network/ovs-of/README.md: -------------------------------------------------------------------------------- 1 | - [OVS + DPDK](./ovs-dpdk.md) 2 | - **FAQ** 3 | - [Quality of Service (QoS)](./QoS.md) 4 | - [Dump Flows](./dump-flows.md) 5 | - [`in_port`](./in_port.md) 6 | - [Tunnel](./tunnel.md) 7 | - [Other](./others.md) 8 | - [其它学习资料](./link.md) 9 | -------------------------------------------------------------------------------- /snippet/docs/network/ovs-of/_static/OVS_Flow_Tables.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/network/ovs-of/_static/OVS_Flow_Tables.png -------------------------------------------------------------------------------- /snippet/docs/network/ovs-of/_static/OVS_flow_Tables_with_ARP_responder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/network/ovs-of/_static/OVS_flow_Tables_with_ARP_responder.png -------------------------------------------------------------------------------- /snippet/docs/network/ovs-of/in_port.md: -------------------------------------------------------------------------------- 1 | 2 | ### Q: How do I assign the OpenFlow Port to a fixed port number? 3 | 4 | A: Use 'ofport_request'. 5 | 6 | ovs-vsctl add-port br0 port_name -- set Interface port_name ofport_request=port_number 7 | ovs-ofctl mod-port br0 port_name up 8 | 9 | ### Q: How can I figure out the OpenFlow port number for a given port? 10 | ``` 11 | A: The OFPT_FEATURES_REQUEST message requests an OpenFlow switch to 12 | respond with an OFPT_FEATURES_REPLY that, among other information, 13 | includes a mapping between OpenFlow port names and numbers. From a 14 | command prompt, "ovs-ofctl show br0" makes such a request and 15 | prints the response for switch br0. 16 | 17 | The Interface table in the Open vSwitch database also maps OpenFlow 18 | port names to numbers. To print the OpenFlow port number 19 | associated with interface eth0, run: 20 | 21 | ovs-vsctl get Interface eth0 ofport 22 | 23 | You can print the entire mapping with: 24 | 25 | ovs-vsctl -- --columns=name,ofport list Interface 26 | 27 | but the output mixes together interfaces from all bridges in the 28 | database, so it may be confusing if more than one bridge exists. 29 | 30 | In the Open vSwitch database, ofport value -1 means that the 31 | interface could not be created due to an error. (The Open vSwitch 32 | log should indicate the reason.) ofport value [] (the empty set) 33 | means that the interface hasn't been created yet. The latter is 34 | normally an intermittent condition (unless ovs-vswitchd is not 35 | running). 36 | ``` 37 | -------------------------------------------------------------------------------- /snippet/docs/network/ovs-of/link.md: -------------------------------------------------------------------------------- 1 | 2 | [OpenFlow学习笔记](http://www.cnblogs.com/popsuper1982/p/3800558.html) 3 | 4 | [SDN与OpenFlow技术简介](http://www.cnblogs.com/popsuper1982/p/3800556.html) 5 | 6 | [Open vSwitch 安装及配置](http://www.cnblogs.com/popsuper1982/p/3800431.html) 7 | 8 | [基于 Open vSwitch 的 OpenFlow 实践](http://www.cnblogs.com/popsuper1982/p/3800525.html) 9 | 10 | [An overview of Openvswitch implementation](http://www.cnblogs.com/popsuper1982/p/3800560.html) 11 | 12 | [Network flow monitoring with Open vSwitch](http://www.cnblogs.com/popsuper1982/p/3800578.html) 13 | 14 | [Openvswitch手册(1): 架构,SSL, Manager, Bridge](http://www.cnblogs.com/popsuper1982/p/3800574.html) 15 | 16 | [Openvswitch手册(2): OpenFlow Controller](http://www.cnblogs.com/popsuper1982/p/3800576.html) 17 | 18 | [Openvswitch手册(3): sFlow, netFlow](http://www.cnblogs.com/popsuper1982/p/3800583.html) 19 | 20 | [Openvswitch手册(4): Mirror](http://www.cnblogs.com/popsuper1982/p/3800585.html) 21 | 22 | 另外两篇(关于Mirror) 23 | 24 | http://www.cnblogs.com/sting2me/p/4849851.html 25 | 26 | http://www.zouliblog.cn/?p=379 27 | 28 | 29 | [Openvswitch手册(5): VLAN and Bonding](http://www.cnblogs.com/popsuper1982/p/3800613.html) 30 | 31 | [Openvswitch手册(6): QoS](http://www.cnblogs.com/popsuper1982/p/3803807.html) 32 | 33 | [Openvswitch手册(7): Interfaces](http://www.cnblogs.com/popsuper1982/p/3805094.html) 34 | 35 | [Openvswitch手册(8): ovs-vsctl的DB的操作](http://www.cnblogs.com/popsuper1982/p/3805105.html) 36 | 37 | [Openvswitch手册(9): Flow](http://www.cnblogs.com/popsuper1982/p/3810271.html) 38 | 39 | [Ovs-flow-logic](https://wiki.openstack.org/wiki/Ovs-flow-logic) 40 | 41 | **OVS_Flow_Tables** ![OVS_Flow_Tables](./_static/OVS_Flow_Tables.png) 42 | 43 | **OVS_flow_Tables_with_ARP_responder** ![OVS_flow_Tables_with_ARP_responder](./_static/OVS_flow_Tables_with_ARP_responder.png) 44 | -------------------------------------------------------------------------------- /snippet/docs/network/ovs-of/others.md: -------------------------------------------------------------------------------- 1 | 2 | ### Q: How do I connect two bridges? 3 | ``` 4 | A: First, why do you want to do this? Two connected bridges are not 5 | much different from a single bridge, so you might as well just have 6 | a single bridge with all your ports on it. 7 | 8 | If you still want to connect two bridges, you can use a pair of 9 | patch ports. The following example creates bridges br0 and br1, 10 | adds eth0 and tap0 to br0, adds tap1 to br1, and then connects br0 11 | and br1 with a pair of patch ports. 12 | 13 | ovs-vsctl add-br br0 14 | ovs-vsctl add-port br0 eth0 15 | ovs-vsctl add-port br0 tap0 16 | ovs-vsctl add-br br1 17 | ovs-vsctl add-port br1 tap1 18 | ovs-vsctl \ 19 | -- add-port br0 patch0 \ 20 | -- set interface patch0 type=patch options:peer=patch1 \ 21 | -- add-port br1 patch1 \ 22 | -- set interface patch1 type=patch options:peer=patch0 23 | 24 | Bridges connected with patch ports are much like a single bridge. 25 | For instance, if the example above also added eth1 to br1, and both 26 | eth0 and eth1 happened to be connected to the same next-hop switch, 27 | then you could loop your network just as you would if you added 28 | eth0 and eth1 to the same bridge (see the "Configuration Problems" 29 | section below for more information). 30 | 31 | If you are using Open vSwitch 1.9 or an earlier version, then you 32 | need to be using the kernel module bundled with Open vSwitch rather 33 | than the one that is integrated into Linux 3.3 and later, because 34 | Open vSwitch 1.9 and earlier versions need kernel support for patch 35 | ports. This also means that in Open vSwitch 1.9 and earlier, patch 36 | ports will not work with the userspace datapath, only with the 37 | kernel module. 38 | ``` 39 | -------------------------------------------------------------------------------- /snippet/docs/network/ovs-of/tunnel.md: -------------------------------------------------------------------------------- 1 | 2 | ### Q: I created a GRE port using ovs-vsctl so why can't I send traffic or see the port in the datapath? 3 | 4 | A: On Linux kernels before 3.11, the OVS GRE module and Linux GRE module 5 | cannot be loaded at the same time. It is likely that on your system the 6 | Linux GRE module is already loaded and blocking OVS (to confirm, check 7 | dmesg for errors regarding GRE registration). To fix this, unload all 8 | GRE modules that appear in lsmod as well as the OVS kernel module. You 9 | can then reload the OVS module following the directions in INSTALL, 10 | which will ensure that dependencies are satisfied. 11 | 12 | ### Q: What destination UDP port does the VXLAN implementation in Open vSwitch use? 13 | 14 | A: By default, Open vSwitch will use the assigned IANA port for VXLAN, which 15 | is 4789. However, it is possible to configure the destination UDP port 16 | manually on a per-VXLAN tunnel basis. An example of this configuration is 17 | provided below. 18 | 19 | ovs-vsctl add-br br0 20 | ovs-vsctl add-port br0 vxlan1 -- set interface vxlan1 \ 21 | type=vxlan options:remote_ip=192.168.1.2 options:key=flow \ 22 | options:dst_port=8472 23 | -------------------------------------------------------------------------------- /snippet/docs/network/protocol/README.md: -------------------------------------------------------------------------------- 1 | 2 | - [数据链路层协议](./data-link-layer.md) 3 | - [交换机和路由器](./switch-router.md) 4 | 5 | ------ 6 | 7 | ![VLAN Tag](./_static/vlan_tag.png) 8 | 9 | ![Protocol Layer](./_static/tcpip.png) 10 | -------------------------------------------------------------------------------- /snippet/docs/network/protocol/_static/ethernet.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/network/protocol/_static/ethernet.jpg -------------------------------------------------------------------------------- /snippet/docs/network/protocol/_static/tcpip.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/network/protocol/_static/tcpip.png -------------------------------------------------------------------------------- /snippet/docs/network/protocol/_static/vlan_tag.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/network/protocol/_static/vlan_tag.png -------------------------------------------------------------------------------- /snippet/docs/network/tcp/_static/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/network/tcp/_static/1.png -------------------------------------------------------------------------------- /snippet/docs/network/tunnel/_static/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/network/tunnel/_static/1.jpg -------------------------------------------------------------------------------- /snippet/docs/network/tunnel/_static/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/network/tunnel/_static/10.png -------------------------------------------------------------------------------- /snippet/docs/network/tunnel/_static/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/network/tunnel/_static/2.jpg -------------------------------------------------------------------------------- /snippet/docs/network/tunnel/_static/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/network/tunnel/_static/3.jpg -------------------------------------------------------------------------------- /snippet/docs/network/tunnel/_static/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/network/tunnel/_static/4.jpg -------------------------------------------------------------------------------- /snippet/docs/network/tunnel/_static/5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/network/tunnel/_static/5.jpg -------------------------------------------------------------------------------- /snippet/docs/network/tunnel/_static/6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/network/tunnel/_static/6.jpg -------------------------------------------------------------------------------- /snippet/docs/network/tunnel/_static/7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/network/tunnel/_static/7.jpg -------------------------------------------------------------------------------- /snippet/docs/network/tunnel/_static/8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/network/tunnel/_static/8.jpg -------------------------------------------------------------------------------- /snippet/docs/network/tunnel/_static/9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/network/tunnel/_static/9.png -------------------------------------------------------------------------------- /snippet/docs/network/tunnel/vtun-usage-and-src-analysis.md: -------------------------------------------------------------------------------- 1 | 2 | VTun Usage 3 | ========== 4 | TODO 5 | 6 | 7 | VTun src Analysis 8 | ================= 9 | 10 | 本文目标立足于代码层次的大致流程分析,但不会一句一句地分析源代码。如下图: 11 | 12 | ![IMG1](./_static/9.png) 13 | 14 | ![IMG2](./_static/10.png) 15 | 16 | ### 注 17 | 18 | (1)`Vtun`经过编译之后,生成的可执行程序是`vtund`。`Vtund`是个一般程序,运行在用户空间,和普通进程没有什么太大的区别。 19 | 20 | (2)`Vtund`以 `-s` 选项启动时,则是服务器模式;如果没有 `-s` 选项,则是客户端登录模式。 21 | 22 | (3)当客户端和服务器都运行到`tunnel`函数时,以后的代码则是二者共用的、相同的,换句话说就是,在`tunnel`以后的代码,不再区分到底是客户端还是服务器端,其处理是一样的。 23 | 24 | (4)在`Vtund`启动时(不管是以`服务器方式`还是以`客户端方式`),会读取配置文件,从配置文件中构建一个主机链表`host_list`(一个全局变量),其中保存了在配置文件列出的所有主机的信息。 25 | 26 | (5)当`Vtund`以客户端启动时,在`main`主函数中会首先在`host_list`主机链表中查找在命令行提供的主机名(即是登录名)。如果找不到,则退出(即登录失败);如果查找到,则会将该主机信息保存到全局变量`lfd_host`中(但`lfd_host`是个指针,可以通过它来访问主机信息)。 27 | 28 | (6)当`Vtund`以服务器启动时,当认证客户端信息时,它也会在`host_list`中查找客户端提供的主机名。如果找不到,则认证失败;如果找到了,则会将该主机信息保存到全局变量`lfd_host`中,同时会清空`host_list`链表。 29 | 30 | (7)`Vtund`中有两个全局变量——`vtun`和`host_list`;配置文件分为三种类型——`options`、`default`和`XXX`,其中`XXX`是主机名(可以有无限多个)。`options`是设置一些一般属性,它的值会被读取到`vtun`全局变量中;每个主机信息都有一些属性信息,当在`XXX`中没有给出时,则使用`default`中的属性信息,换句话说就是,_**default是XXX在没有给出属性信息时的默认信息**_。**`XXX主机信息会被构建一个主机链表放在host_list全局变量中,当查找主机(find_host)时,凡是不匹配的主机信息都会被清除`**。 31 | 32 | (8)根据`(6)`和`(7)`,我们会发现,一个`Vtund服务器`对应一个`Vtund客户端`,换句话说就是,**`一个Vtund服务器只能接受到一个客户端的登录,多个Vtund客户端不能登录到同一个Vtund服务器中`**。 33 | 34 | (9)在配置文件中的主机信息中,可以有`up`和`down`命令链,`up`命令链用于在建立隧道之前初始化一些设备,`down`命令链用于在结束隧道之后释放一些初始化设备时占用的设备资源。 35 | 36 | (10)`Vtun`支持`TTY`、`PIPE`、`TUN`、`TAP`四种设备;`Vtund`不会在一启动之后就打开相应的设备,而是在客户端连接上服务器并认证成功后,在`tunnel`函数中建立隧道时打开的;一旦打开设备,就几乎等同于建立了隧道——随时等待 `select IO机制`通知`Vtund`进程数据可读。隧道的大致含义是通过Socket把压缩、加密之后的数据在两台计算机之间进行传递,这就相当于在两台计算机之间建立了一条只有这两台计算机才能识别的安全通信信道。 37 | 38 | (11)`Vtund`在以`服务器方式`启动时,如果认证失败,Vtund的退出并不意味着整个Vtund程序退出了,而是与客户端的一次连接结束了:每当客户端连接到Vtund服务器时,服务器都会fork一个新的子进程来与客户端交互,退出的也就是这个子进程,而主进程仍然没有结束,而是在监听着客户端的到来。但是,有个问题(疑问??),在第一个客户端连接时,VTund服务器端已经把 host_list 全局变量给清空了,后续无论有多少个客户端来到来,都是认证失败。不知道这就有什么意义! 39 | 40 | 41 | ### 参考 42 | 43 | Tun/Tap interface tutorial:http://backreference.org/2010/03/26/tuntap-interface-tutorial/ 。 44 | -------------------------------------------------------------------------------- /snippet/docs/openstack/README.md: -------------------------------------------------------------------------------- 1 | 2 | ![OpenStack Tunnel Flows](./_static/tunnel-flows.png) 3 | -------------------------------------------------------------------------------- /snippet/docs/openstack/_static/tunnel-flows.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/openstack/_static/tunnel-flows.png -------------------------------------------------------------------------------- /snippet/docs/package/fpm.md: -------------------------------------------------------------------------------- 1 | 2 | 用FPM快速制作RPM包 3 | ================= 4 | 5 | #### 一、安装FPM 6 | ```shell 7 | yum -y install ruby rubygems ruby-devel 8 | gem sources --add https://ruby.taobao.org/ --remove https://rubygems.org/ 9 | gem install fpm 10 | ``` 11 | 12 | #### 二、把NodeJS打包成RPM包 13 | ```shell 14 | # 下载并编译 NodeJS 15 | wget http://nodejs.org/dist/v0.10.12/node-v0.10.12.tar.gz # 去nodejs官网下载最新源码包 16 | tar zxvf node-v0.10.12.tar.gz -C /dev/shm/ # 解压 17 | cd /dev/shm/node-v0.10.12/ # 进入源码目录 18 | ./configure --prefix=/usr --dest-cpu=x64 --dest-os=linux # 指定配置参数 19 | make -j24 # 使用多核编译 20 | mkdir /dev/shm/node-root # 创建安装目录 21 | make -j24 install DESTDIR=/dev/shm/node-root # 指定安装路径 22 | 23 | # 使用 FPM 制作 RPM 包 24 | fpm -f --verbose -s dir -t rpm --category 'Development/Languages' \ 25 | --license 'BSD' -m 'higkoo' --epoch 0 -v 0.10.12 \ 26 | --url 'nodejs.org' --description 'Node.js real-time applications' \ 27 | -n nodejs -C /dev/shm/node-root -p ~/rpmbuild/RPMS/x86_64/ \ 28 | --no-rpm-sign --iteration 1.el6 \ 29 | -d 'openssl >= 0.9.8' -d 'libstdc++ >= 4.4.3' \ 30 | usr/bin usr/lib usr/share 31 | 32 | # 查看RPM包信息 33 | rpm -qpi ~/rpmbuild/RPMS/x86_64/nodejs-0.10.12-1.x86_64.rpm 34 | ``` 35 | 36 | #### 三、其它 37 | ``` 38 | https://github.com/jordansissel/fpm/wiki 39 | https://github.com/jordansissel/fpm/wiki/ConvertingPython 40 | ``` 41 | -------------------------------------------------------------------------------- /snippet/docs/python/_static/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/python/_static/1.png -------------------------------------------------------------------------------- /snippet/docs/python/_static/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/python/_static/2.jpg -------------------------------------------------------------------------------- /snippet/docs/python/_static/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/python/_static/3.png -------------------------------------------------------------------------------- /snippet/docs/python/_static/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/python/_static/4.jpg -------------------------------------------------------------------------------- /snippet/docs/python/_static/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/python/_static/5.png -------------------------------------------------------------------------------- /snippet/docs/python/link.md: -------------------------------------------------------------------------------- 1 | 2 | - [How To Use Linux epoll with Python](http://scotdoyle.com/python-epoll-howto.html) 3 | - [Python的内存管理](http://www.cnblogs.com/vamei/p/3232088.html) 4 | - Python 3.5 协程究竟是个啥(又译:Python 3.5 协程原理) ([中文版](http://blog.rainy.im/2016/03/10/how-the-heck-does-async-await-work-in-python-3-5/) | [英文版 ](http://www.snarky.ca/how-the-heck-does-async-await-work-in-python-3-5)) 5 | - [Openstack Eventlet分析(一)](http://www.choudan.net/2013/08/18/OpenStack-eventlet%E5%88%86%E6%9E%90(%E4%B8%80).html) 6 | - [Openstack Eventlet分析(二)](http://www.choudan.net/2013/08/19/OpenStack-eventlet%E5%88%86%E6%9E%90(%E4%BA%8C).html) 7 | - [Openstack Eventlet分析(三)](http://www.choudan.net/2013/10/02/OpenStack-eventlet%E5%88%86%E6%9E%90(%E4%B8%89).html) 8 | - [Openstack并行性能加速(翻译)](http://www.choudan.net/2013/12/24/OpenStack%E5%B9%B6%E8%A1%8C%E6%80%A7%E8%83%BD%E5%8A%A0%E9%80%9F(%E7%BF%BB%E8%AF%91).html) 9 | 10 | ----- 11 | 12 | ## Software And Package 13 | 14 | ##### [PyInstaller](http://www.pyinstaller.org/) 15 | PyInstaller bundles a Python application and all its dependencies into a single package. 16 | The user can run the packaged app without installing a Python interpreter or any modules. 17 | 18 | ##### [Arrow](https://github.com/crsmithdev/arrow) 19 | Better dates & times for Python。 20 | 21 | ##### [invoke](https://github.com/pyinvoke/invoke/) 22 | Simple Python task execution 23 | 24 | ##### [Markdown](https://github.com/waylan/Python-Markdown) 25 | A Python implementation of John Gruber’s Markdown. 26 | 27 | ##### [twisted-csp](https://github.com/ubolonton/twisted-csp) 28 | Go-style concurrency for Twisted 29 | 30 | ##### [ItChat](https://github.com/littlecodersh/ItChat) 31 | A complete and graceful API for Wechat. 微信个人号接口、微信机器人及命令行微信,三十行即可自定义个人号机器人。 32 | 33 | ##### [fire](https://github.com/google/python-fire) 34 | Python Fire is a library for automatically generating command line interfaces (CLIs) from absolutely any Python object. 35 | 36 | ##### [dpkt](https://github.com/kbandla/dpkt) 37 | fast, simple packet creation / parsing, with definitions for the basic TCP/IP protocols. 38 | -------------------------------------------------------------------------------- /snippet/docs/python/python-advance-app.md: -------------------------------------------------------------------------------- 1 | 2 | 十一、高级应用 3 | =========== 4 | 5 | 1、Twisted是一个完全事件驱动的网络框架,允许你使用和开发完全异步的网络应用程序和协议。系统中有:网络协议、线程、安全和认证、聊天/即时通讯、数据库管理、关系数据库集成、Web/Internet、电子邮件、命令行参数、图形界面集成等等。 6 | 7 | 8 | 2、Django是用python语言写的开源web开发框架(open source web framework),它鼓励快速开发,并遵循MVC设计。Django的主要目的是简便、快速的开发数据库驱动的网站。它强调代码复用,多个组件可以很方便的以“插件”形式服务于整个框架,Django有许多功能强大的第三方插件,你甚至可以很方便的开发出自己的工具包。这使得Django具有很强的可扩展性。它还强调快速开发和`DRY(Do Not Repeat Yourself)`原则。 9 | -------------------------------------------------------------------------------- /snippet/docs/python/python-appendix.md: -------------------------------------------------------------------------------- 1 | 2 | 附录 3 | === 4 | 5 | 感谢“`Python高级编程`”QQ群中的“`广州-刘明`”网友指出了对“`yield语法`”一节中有关`Generator`的看法。 6 | 7 | 在写技术文章时,不可避免地要涉及到有关技术问题的描述。在描述时,所使用的句子类型(长句、短句)、词汇等都会或多或少地影响对问题的描述。在翻译C99标准中的有关“作用域”等章节时,我就曾遇到过一个问题——到底使用短句还是长句来翻译。在使用短句翻译时,笔者自感觉自己的文笔不好,不能把各短句精妙地连接起来,让读者一目了然。后来,为了尽量让读者不引起歧义,笔者使用带有多级修饰词的长句来描述、说明问题,如:结构体、联合体和枚举的标志的作用域正好开始于在声明标志的类型指定符中的标识的出现处之后,每个枚举常量的作用域正好开始于在一个枚举列表中的所定义的枚举符的出现处之后,任何其他标识符的作用域正好开始于它的声明符的完成处之后。 8 | 9 | 笔者会尽量避免各种错误和误解,并随时更新内容。如有错误或容易使人误解的地方,请各位网友指正。 10 | -------------------------------------------------------------------------------- /snippet/docs/python/python-exception.md: -------------------------------------------------------------------------------- 1 | 2 | 七、异常 3 | ====== 4 | 5 | 1、经常会失败的运算一般都应该包装在`try`语句内,除非你希望这类运算失败时终止程序,而不是被捕捉或是忽略。如果是一个重大的错误更是如此。 6 | 7 | 2、应该在`try/finally`中实现终止动作,从而保证它们的执行,除非环境管理器作为一个`with/as`选项可用。 8 | 9 | 3、偶尔,把对大型函数的调用包装在单个`try`语句内,而不是让函数本身零散着放入若干`try`语句中,这样会更方便。 10 | 11 | 4、可以在 `try` 语句后面添加 `else` 语句,且`else`语句只有在未抛出异常的情况下才会被执行。 12 | -------------------------------------------------------------------------------- /snippet/docs/python/python-operator-overload.md: -------------------------------------------------------------------------------- 1 | 2 | 八、运算符重载 3 | =========== 4 | 5 | 1、为了确保一个定制显示在所有的环境中都显示而不管容器是什么,请编写`__repr__`而不是`__str__`;前者在所有的情况下都运行,即使是后者不适用的的情况也是如此。 6 | -------------------------------------------------------------------------------- /snippet/docs/python/python-preface.md: -------------------------------------------------------------------------------- 1 | 2 | Python学习笔记摘要 3 | ================ 4 | 5 | 本文由`xgfone`整理、写作而成,如有网络转载或用于商业,请注明以下版权声明: 6 | 7 | Copyright © 2012-2016 xgfone(三界). All Rights Reserved. 8 | 9 | 10 | 写在前面 11 | ====== 12 | 13 | 本文并不打算写成一个Python入门教材,至少目前是这样;本文主要提炼Python语法要点,讲解一些比较难以理解的部分,作为一个入门者的提高,以帮助一些已入门者迅速理解、掌握Python语言精髓。因此,要想理解本文内容,需要有Python基础知识,可以参阅Python官方手册的[快速入门教程](http://docs.python.org/3/tutorial/index.html),也可以看其他的入门教材,这里特别推荐Vamei的“[Python快速教程](http://www.cnblogs.com/vamei/archive/2012/09/13/2682778.html)”。 14 | 15 | 本文没有讲解基础语法,比如Python字面值、表达式、语句、如何定义一个函数或类、如何调用一个函数以及如何使用类对象,但本文详细提炼了部分重点语法、讲解了一些难点和高级语法,如yield语法、装饰器、属性管理、元类等等,已入门者可以把它作为一个手册。本文参考了《Python学习手册(第四版)》(中文版)(下文简称为《学四》)和Python的[官方手册](http://docs.python.org/)。 16 | 17 | 如果没有特殊说明,本文所讲的语法、知识都是基于Python官方的实现——C实现,即`CPython`;而且,如果没有特殊说明,本文基于的Python版本默认为`3.X`。 18 | 19 | 前言 20 | === 21 | 22 | **Python 是动态的强类型语言;Python 的类型系统属于 Duck(鸭子)类型。** 23 | 24 | ### 动态类型与静态类型 25 | 简单地说,声明或定义一个变量或对象时,如果不需要指定类型,而是由语言动态判断,则该语言为动态类型语言;否则为静态类型语言。 比如:`Python`、`Ruby`、`JavaScript` 等是动态类型语言,`C/C++`、`Java`、`C#`、`Go` 等是静态类型语言。 26 | 27 | ### 强类型与弱类型 28 | 简单地说,当一个变量或对象的属性没有定义时,如果解析器或编译器不判断为错误,而是给出一个默认值,那么该语言为弱类型语言;否则为强类型语言。比如:`JavaScript`、`Shell` 为弱类型语言,`C/C++`、`Java`、`C#`、`Python`、`Go` 等为强类型语言。 29 | 30 | ### Duck 类型 31 | 简单地说,Duck 类型就是:**`一个对象有效的语义,不是由继承自指定的类(通过类继承)或实现特定的接口(如 Java 中 interface),而是由该对象的当前方法和属性的集合来决定;在 Duck 类型中,关注的并不是对象的类型本身,而是该对象是如何使用`**。 32 | 33 | 比如:在 Python 中,定义了一个类型 A 以及它的一个实例 a,类型 A 及其父类中并没有定义方法 `print()`,但并不代表实例 a 不能调用它;在 Duck 类型中,可以在类型 A 定义外向它的方法方法和属性集合中添加一个方法 `print()`,此时就可以调用 `print()` 了,如: 34 | ```python 35 | class A: pass 36 | a = A() 37 | a.printf = lambda: "hello" # 向实例 a 的方法和属性集体中添加一个方法 printf 38 | print a.printf() # 打印字符串 "hello" 到终端上 39 | A.pp = lambda self: "hello" # 向类型 A 的方法和属性集体中添加一个方法 pp 40 | print a.pp() # 打印字符串 "hello" 到终端上 41 | ``` 42 | 细心的读者可能发现: 43 | 44 | (1)为实例 a 添加方法时,lambda 表达式没有指定参数,而为类型 A 添加方法时,lambda 表达式却指定了参数; 45 | 46 | (2)为类型 A 添加了方法但没有为实例 a 添加该方法,而实例 a 却能调用该方法。 47 | 48 | 关于第一个问题,请参见下文`第五大节中的第 17 小节`——方法的调用;简单地说,这是关于名字绑定(Name Binding)以及方法调用的问题。关于第二个问题,这实例属性名或方法名查找的问题,请参见下文`第五大节中的第 15 小节`和`第六大节中关于”作用域与命名空间“的第 9 小节`。 49 | -------------------------------------------------------------------------------- /snippet/docs/python/python-type.md: -------------------------------------------------------------------------------- 1 | 2 | 二、数据类型 3 | ========== 4 | 5 | ## 1、set与frozenset集合 6 | 无论是`set`类型还是`frozenset`类型,其元素都必须是不可修改的数据;`set`和`frozenset`的区别在于是否可以向集合中添加元素,或者从集合中删除元素。 7 | 8 | 9 | ## 2、浅拷贝与深拷贝 10 | 无条件值的分片以及字典`copy`方法只能做顶层复制;也就是说,不能够复制嵌套的数据结构(如果有的话)。如果需要一个深层嵌套的数据结构的完整的、完全的拷贝,则就要使用标准库中的copy模块。 11 | 12 | 13 | ## 3、可修改序列重复能够增加层次深度 14 | 可修改序列重复就好像是多次将一个序列回到自己身上;但是,当可变序列被嵌套时,效果却有些出入,即:可变序列改变时,被嵌套的序列都跟着改变。如: 15 | ```python 16 | >>> L = [1, 2, 3] 17 | >>> X = L * 3 18 | >>> Y = [L] * 3 19 | >>> X 20 | [1, 2, 3, 1, 2, 3, 1, 2, 3] 21 | >>> Y 22 | [[1, 2, 3], [1, 2, 3], [1, 2, 3]] 23 | >>> L[1] = 0 24 | >>> X 25 | [1, 2, 3, 1, 2, 3, 1, 2, 3] 26 | >>> Y 27 | [[1, 0, 3], [1, 0, 3], [1, 0, 3]] 28 | ``` 29 | -------------------------------------------------------------------------------- /snippet/docs/rust/README.md: -------------------------------------------------------------------------------- 1 | 2 | Rust 3 | ==== 4 | 5 | - [Rust Packages](./packages.md) 6 | - [Rust参考手册(表达式和Item部分未翻译)](./ref.md) 7 | - [杂记](./notes.md) 8 | - `String` vs `&str` 9 | - [String vs &str in Rust functions](http://hermanradtke.com/2015/05/03/string-vs-str-in-rust-functions.html) 10 | - [Creating a Rust function that accepts String or &str](http://hermanradtke.com/2015/05/06/creating-a-rust-function-that-accepts-string-or-str.html) 11 | - [Creating a Rust function that returns a &str or String](http://hermanradtke.com/2015/05/29/creating-a-rust-function-that-returns-string-or-str.html) 12 | - [Writing an OS in Rust ](http://os.phil-opp.com/) 13 | - [Rust Example](http://rustbyexample.com) 14 | -------------------------------------------------------------------------------- /snippet/docs/shell/shell-appendix.md: -------------------------------------------------------------------------------- 1 | 2 | 附录 3 | === 4 | 5 | ## 参考书籍 6 | 7 | 1. 《GNU Bash Manual》(4.2版本),Free Software Foundation 8 | 2. 《Mastering UNIX Shell Scripting(SECOND EDITION)》, RandalK. Michael,清华大学出版社 9 | 3. 《Shell脚本学习指南》, Arnold Robbins,Nelson H.F. Beebe, O’ReillyTaiwan 10 | 4. 《鸟哥的Linux私房菜:基础学习篇(第三版)》,鸟哥著,王世江改编,人民邮电出版社 11 | -------------------------------------------------------------------------------- /snippet/docs/shell/shell-argument.md: -------------------------------------------------------------------------------- 1 | 2 | 第五部分 参数 3 | =========== 4 | 5 | ## 16 位置参数 6 | 7 | 语法 | 含义 8 | -----|-------------------------------------------------- 9 | ${n} | 命令行某个单独的参数;当1<=n<=9时,也可以简记作$n。 10 | $0 | 当前程序名。 11 | $# | 命令行参数的数目,用十进制数表示。 12 | $* | 当$*放在双引号中时,命令行上的所有参数将被视为单个字符。 即”$*”等同于”$1 $2 $3 ….”。 $IFS的第一个字符用来作为分隔符,以分隔不同的值来建立字符串。 如果没有设置$IFS,就用空格来分隔;如果$IFS为空,则参数不使用中间分隔符来链接。 13 | $@ | 与$*相同,但有区别:将所有命令行参数各自视为单独的个体,也就是单独字符串。 即”$@”等同于”$1”“$2”“$3” ……。 这是将参数传递给其他程序的最佳方式,因为它会保留所有内嵌在每个参数里的任何空白。 如果”$@”出现在一个单词中, ”$@”扩展后的第一部分”$1”将与原单词的前部分连接, ”$@”扩展后的最后一部分”$n”与原单词的后部分连接。 14 | $$ | 当前shell的进程号;在子shell中,它扩展成当前shell的进程ID,而不是子shell的进程 (参见shell内置变量BASH PID)。 15 | $? | 上一条命令的退出状态。 16 | $! | 最近发出的后台命令的进程号。 17 | $- | 当前执行的选项(参阅set内置命令)。默认时,hB代表脚本,himBH代表交互式shell。 18 | $_ | 初值被设置为调用这个shell的文件名,然后把每个命令设置为前一条命令的最后一个单词。 19 | 20 | **说明:** 21 | 22 | 位置参数不能用赋值表达式赋值,但可以被set内建命令重新赋值。如果没有位置参数,则”$*”和”$@”不进行扩展。 23 | 24 | 25 | ## 17 数组 26 | 27 | Bash提供了一维的索引式数组变量和关联式数组变量。数组的大小没有最大值限制。索引式数组通过使用非负整数(包括算术表达式)来引用,关联数组通过任意的字符串来引用。数组能隐式自动创建,也能使用内建命令declare来创建。 28 | 29 | 如果使用形如:`name[subscript]=value`的形式来给变量赋值,则一个索引数组将自动被创建;下标subscript可以是算术表达式,但必须计算成一个大于或等于0的整数。此外,还可以通过使用`declare -a name`来显示地声明一个索引式数组。`declare -a name[subscript]`也是被允许的,但下标subscript将被忽略。关联式数组是通过使用`declare -A name`来创建。 30 | 31 | 数组可以使用复合赋值的形式来赋值,如:`name=(value_1 …… value_2)`,其中的每个值等同于`[subscript]=string`的形式。索引式数组赋值不需要中括号和下标。当赋值给一个索引式数组时,如果提供可选的中括号和下标,则那个下标索引指定的数组变量元素将被赋值;否则,被赋值的元素的索引为在已被赋值的最后一个元素的索引上加1,**索引起始于0**。 32 | 33 | 当给关联式数组赋值时,下标是必须的。单独数组元素赋值可以使用`name[subscript]=value`。 34 | 35 | 数组的每个元素都可以使用`${name[subscript]}`来引用。大括号是必须的,以避免与路径我扩展的冲突。如果subscript为`*`或`@`,`${name[@]}`或`${name[*]}`扩展成name的所有成员(参见`$*`或`$@`)。 36 | 37 | 引用一个没有下标的数组变量,等同于引用一个下标为0的数组。 38 | 39 | `unset`内建命令可用销毁数组变量。`unset name[subscript]`销毁下标subscript处的数组元素。`unset name`或`unset name[@]` 或 `unset name[*]`除整个数组。 40 | -------------------------------------------------------------------------------- /snippet/docs/shell/shell-builtin-command.md: -------------------------------------------------------------------------------- 1 | 2 | 第十部分 Shell内建命令 3 | =================== 4 | 5 | ## 30 Shell内建命令 6 | 待写。 7 | -------------------------------------------------------------------------------- /snippet/docs/shell/shell-environment-var.md: -------------------------------------------------------------------------------- 1 | 2 | 第十一部分 环境变量 3 | =============== 4 | 5 | ## 31 环境变量 6 | 待写。 7 | -------------------------------------------------------------------------------- /snippet/docs/shell/shell-history.md: -------------------------------------------------------------------------------- 1 | 2 | 第八部分 历史 3 | =========== 4 | 5 | ## 27 历史 6 | 待写。 7 | 8 | 9 | ## 28 历史扩展 10 | 待写。 11 | -------------------------------------------------------------------------------- /snippet/docs/shell/shell-lexical-preview.md: -------------------------------------------------------------------------------- 1 | 2 | 第一部分 词法预览 3 | ============== 4 | 5 | ## 1 控制字符 6 | ```shell 7 | || & && ; ;; ( ) | |& 8 | ``` 9 | 10 | ## 2 元字符 11 | 元字符在没有引用时具有特殊含义 12 | ```shell 13 | | & ; ( ) < > space tab 14 | ``` 15 | 16 | ## 3 保留字 17 | ```shell 18 | ! case do done elif esac fi for function if in select then until while { } time [[ ]] 19 | ``` 20 | 注:保留字除其特有含义之外,不能另作他用。 21 | 22 | ## 4 注释 23 | 24 | Shell中的注释以`#`开头,在`#`之后同行上的所有字符序列都将被shell忽略。 25 | 26 | `#`能在非交互式shell(如脚本)中正常使用,没有什么限制;但在交互式shell中有限制。要在交互式shell中使用`#`进行注释,必须启用`interactive_comments`选项;若没有启动该选项,交互式shell不允许进行注释。在交互式shell中,`interactive_comments`选项默认被启用。 27 | -------------------------------------------------------------------------------- /snippet/docs/shell/shell-preface.md: -------------------------------------------------------------------------------- 1 | 2 | 前 言 3 | ==== 4 | 5 | 本文是笔者在学习shell(bash)中整理出来的,其中的知识可能来源于某本书中,也可能来源于网上(笔者不清楚时,会上网搜索一下答案)。 6 | 7 | 本文几乎包括了大部分shell知识,但还没有包括shell的方方面面,还有待完善。出现加粗的红色“`待写`”二字之处,均为有待完成。 8 | 9 | 原则上,shell是相通的,尤其是遵循POSIX标准的;但是shell又有多种,每一种又有自己的特点,这就导致了不同shell之间的细微差别以及语法差别。 10 | 11 | 笔者现在主要学习的是`bash(GNU Bourne-Again Shell)`,所以本文整理的主要也是bash,以bash的man手册页所示为基准。正如前面所说,shell是相通的。所以,笔者假定,总体上本文中的内容适用于多种shell,但如果某些地方有冲突或问题,则表明该处内容不适用于您所用的shell,但肯定的是能适用于bash的。如果还有问题,可以与我联系: xgfone@126.com 。 12 | 13 | 对于shell,笔者还未完全精通,水平有限,本文可能有某些瑕疵、错误,欢迎各位好友指正。 14 | 15 | 16 | 版权(COPYRIGHT) 17 | =============== 18 | 19 | Shell Script Programming(Shell脚本编程) 如何编写Shell脚本 20 | ``` 21 | ©COPYRIGHT xgfone 2011-2016 22 | 23 | Permissionis granted to copy, distribute and/or modify this document under theterms of the GNU Free 24 | Documentation License, Version 1.3 or any laterversion published by the Free Software Foundation; 25 | with no InvariantSections, no Front-Cover Texts, and no Back-Cover Texts. A copy ofthe license is 26 | included in the section entitled "GNU FreeDocumentation License". 27 | ``` 28 | -------------------------------------------------------------------------------- /snippet/docs/shell/shell-readline.md: -------------------------------------------------------------------------------- 1 | 2 | 第九部分 Readline 3 | ================ 4 | 5 | ## 29 Readline 6 | 待写。 7 | -------------------------------------------------------------------------------- /snippet/docs/shell/shell-redirection.md: -------------------------------------------------------------------------------- 1 | 2 | 第七部分 重定向 3 | ============= 4 | 5 | ## 26 重定向(redirection) 6 | 7 | ### 26.1 I/O重定向 8 | 9 | 语法 | 含义 10 | ----------|----------------------------------------------------------------- 11 | \>file | 把标准输出写到file,如果目标文件file不存在时,会新建一个; 如果目标文件file已经存在,它就会被覆盖,原本的数据都会丢失。 如果noclobber选项被设置,且文件file已经存在,则重定向失败。 12 | n>file | 把文件描述符n中的内容输出到file中。 13 | \>\|file | 即使已设置noclobber,也强行把标准输出写到file中。 14 | n>\| file | 即使已设置noclobber,也强行把文件描述符n中的内容输出到file中。 15 | \>>file | 把标准输出写到file中。如果目标文件file已经存在,则追加到file的结尾处; 如果file不存在,则新建一个。 16 | n>> file | 把文件描述符n中的内容追回到file中。 17 | \& n | 复制标准输出到文件描述符n。 20 | \<& n | 复制文件描述符n中的内容到标准输入。 21 | &> file | 把标准输出和标准错误输出到file中,在语义上等价于: >file 2>&1。 22 | &>> file | 把标准输出和标准错误追加到file中,在语义上等价于: >>file 2>&1。 23 | \<& - | 关闭标准输入。 24 | \>& - | 关闭标准输出。 25 | n> & - | 关闭文件描述符n的输出。 26 | n< & - | 关闭文件描述符n的输入。 27 | \<> file | 使用file作为标准输入和标准输出。如果file不存在,会新建一个。 28 | 29 | 30 | ### 26.2 说明 31 | 32 | 重定向是按从左到右的顺序进行处理的。 33 | 如果打开或创建文件失败,将引起重定向失败。 34 | 35 | 36 | ### 26.3 标准文件描述符 37 | 38 | 文件描述符 | 名字 | 通用缩写 | 典型默认 39 | ---------|------------|----------|---------- 40 | 0 | 标准输入 | stdin | 键盘 41 | 1 | 标准输出 | stdout | 屏幕 42 | 2 | 标准错误输出 | stderr | 屏幕 43 | 44 | -------------------------------------------------------------------------------- /snippet/docs/shell/shell-reference.md: -------------------------------------------------------------------------------- 1 | 2 | 第三部分 引用 3 | =========== 4 | 5 | ## 11 引用 6 | 7 | ### 11.1 单引号(') 8 | 9 | 语法 | 作用 10 | ----|--------- 11 | '' | 除了另有一个 '之外,在'和'之间的所有字符按原样取出。 12 | 13 | 14 | ### 11.2 反斜杠(\) 15 | 16 | 语法 | 作用 17 | ----|------------ 18 | \c | 对 \后的特殊字符c进行转义,即对c按字面意思进行解释。 19 | 20 | 21 | ### 11.3 双引号(”) 22 | 23 | 语法 | 作用 24 | ------|-------------------------------------------------------- 25 | “ “ | 除了下列字符保持其特殊含义之外,在”和”之间的所有字符都按原样取出。 26 | 27 | $ 将发生变量置换 28 | ` 将发生命令置换 29 | \ 只有当其后跟着$、`、“、\或时,“ \”才保留它的特殊含义。 30 | 31 | **说明:** 32 | 33 | (1) 如果历史机制被启用,除非在双引号中的!被反斜杠转义字符(\)转义,否则历史扩展将完成。 34 | (2) $'sting'被特殊对待,它将扩展成string,其中的反斜杠转义字符将被C标准指定的代替。 35 | (3) $”string”将引发字符串被转换,根据当前区域设置(“本地化”)。 36 | 如果当前区域设置是C或POSIX,美元符号($)将被忽略。如果字符串被替换,则替换部分被双引号所引住。 37 | (4) 特殊字符*与@在双引号中有特殊含义(位置参数)。 38 | 39 | 40 | ## 12 反斜杠转义字符序列 41 | 42 | 语法 | 语义 43 | -----|--------------------------------- 44 | \a | alert(bell) 响铃 45 | \b | backspace 退格 46 | \e | an escape character 字符ESC 47 | \f | form feed 换页 48 | \n | new line 换行 49 | \r | carriage return 回车 50 | \v | vertical tab 垂直制表符 51 | \t | horizontal tab 水平制表符 52 | \\ | backslash 反斜杠 53 | \' | single quote 单引号 54 | \” | double quote 双引号 55 | \nnn | 一个八比特字符(n为八进制数) 56 | \xHH | H是十六进制值 57 | \cx | 一个Ctrl-x字符 58 | -------------------------------------------------------------------------------- /snippet/docs/swift/README.md: -------------------------------------------------------------------------------- 1 | - [Ownership Manifesto(所有权宣言)](https://github.com/apple/swift/blob/master/docs/OwnershipManifesto.md)(阅读 [中文版](https://onevcat.com/2017/02/ownership)) 2 | - [Packages](./packages.md) 3 | -------------------------------------------------------------------------------- /snippet/docs/swift/packages.md: -------------------------------------------------------------------------------- 1 | 2 | ##### [CleanroomLogger](https://github.com/emaloney/CleanroomLogger) 3 | CleanroomLogger provides an extensible Swift-based logging API that is simple, 4 | lightweight and performant. 5 | 6 | -------------------------------------------------------------------------------- /snippet/docs/tool/README.md: -------------------------------------------------------------------------------- 1 | 2 | ##### [gitignore](https://github.com/github/gitignore) 3 | A collection of useful .gitignore templates 4 | 5 | --- 6 | 7 | - [Diff & Patch](./diff&patch.md) 8 | - [tmux 使用手册](http://louiszhai.github.io/2017/09/30/tmux) ([备用](https://blog.csdn.net/chenqiuge1984/article/details/80132042)) 9 | 10 | --- 11 | 12 | ##### [you-get](https://github.com/soimort/you-get) 13 | Dumb downloader that scrapes the web https://you-get.org/ 14 | 15 | ##### [elvish](https://github.com/elves/elvish) 16 | An experimental Unix shell. 17 | 18 | ##### [thefuck](https://github.com/nvbn/thefuck) 19 | Magnificent app which corrects your previous console command. 20 | 21 | ##### [fpm](https://github.com/jordansissel/fpm) 22 | Effing package management! 23 | Build packages for multiple platforms (deb, rpm, etc) with great ease and sanity. 24 | 25 | ##### [tsunami-udp](https://github.com/cheetahmobile/tsunami-udp) 26 | tsunami-udp 是一款专为网络加速诞生的小工具。 用TCP进行传输控制、用UDP进行数据传输。 27 | 28 | ##### [Markdown Online Editor](https://github.com/pandao/editor.md) 29 | The open source embeddable online markdown editor. 30 | 31 | ##### [Open Falcon](https://github.com/open-falcon/of-release) 32 | - [Open Falcon Doc](http://book.open-falcon.org/) 33 | 34 | ##### [aria2](https://github.com/tatsuhiro-t/aria2) 35 | aria2 is a lightweight multi-protocol & multi-source, cross platform download utility operated in 36 | command-line. It supports HTTP/HTTPS, FTP, SFTP, BitTorrent and Metalink. 37 | - See [dep](./script/install-aria2-dep.sh) 38 | 39 | ------ 40 | 41 | ## Mac OS 42 | 43 | ##### [IINA](https://github.com/lhc70000/iina) 44 | IINA is a modern video player for macOS. 45 | -------------------------------------------------------------------------------- /snippet/docs/tool/script/install-aria2-dep.sh: -------------------------------------------------------------------------------- 1 | aptitude install libtool autoconf autopoint 2 | aptitude install libgnutls-dev libgmp-dev libssh2-1-dev libc-ares-dev libxml2-dev zlib1g-dev libsqlite3-dev pkg-config libssl-dev 3 | -------------------------------------------------------------------------------- /snippet/docs/vcs/README.md: -------------------------------------------------------------------------------- 1 | - [Conventional Commits(约定式提交)](https://github.com/conventional-changelog/conventionalcommits.org)(阅读[英文版](https://conventionalcommits.org/lang/en) | [中文版](https://conventionalcommits.org/lang/zh-Hans)) 2 | - [SVN搭建与简单使用](./build-svn-server.md) 3 | - [Git服务器架设](./build-git-server.md) 4 | - [Git HTTP代理](./git-http-proxy.md) 5 | - [Git学习笔记](./git-learning-note.md) 6 | - [Git rebase详解](./git-rebase.md) 7 | - [Github Guide](./github-guide.md) 8 | - [git-extras](https://github.com/tj/git-extras) ( [安装](https://github.com/tj/git-extras/blob/master/Installation.md) ) 9 | - [Git 思维导图](./_static/git-shortcut.jpg)(点击 [这里](https://github.com/xgfone/snippet/raw/master/snippet/docs/vcs/_static/git-shortcut.jpg) 看大图) 10 | - [使用 `5W1H` 写出高可读的 Git Commit Message](./git-commit-message.md) 11 | - [图解Git](https://marklodato.github.io/visual-git-guide/index-zh-cn.html) 12 | - [一个小时学会 Git](http://www.cnblogs.com/best/p/7474442.html) 13 | -------------------------------------------------------------------------------- /snippet/docs/vcs/_static/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/vcs/_static/1.png -------------------------------------------------------------------------------- /snippet/docs/vcs/_static/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/vcs/_static/10.png -------------------------------------------------------------------------------- /snippet/docs/vcs/_static/11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/vcs/_static/11.png -------------------------------------------------------------------------------- /snippet/docs/vcs/_static/12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/vcs/_static/12.png -------------------------------------------------------------------------------- /snippet/docs/vcs/_static/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/vcs/_static/2.png -------------------------------------------------------------------------------- /snippet/docs/vcs/_static/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/vcs/_static/3.png -------------------------------------------------------------------------------- /snippet/docs/vcs/_static/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/vcs/_static/4.png -------------------------------------------------------------------------------- /snippet/docs/vcs/_static/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/vcs/_static/5.png -------------------------------------------------------------------------------- /snippet/docs/vcs/_static/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/vcs/_static/6.png -------------------------------------------------------------------------------- /snippet/docs/vcs/_static/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/vcs/_static/7.png -------------------------------------------------------------------------------- /snippet/docs/vcs/_static/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/vcs/_static/8.png -------------------------------------------------------------------------------- /snippet/docs/vcs/_static/9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/vcs/_static/9.png -------------------------------------------------------------------------------- /snippet/docs/vcs/_static/git-server-method.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/vcs/_static/git-server-method.png -------------------------------------------------------------------------------- /snippet/docs/vcs/_static/git-shortcut.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/vcs/_static/git-shortcut.jpg -------------------------------------------------------------------------------- /snippet/docs/vcs/_static/repo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/vcs/_static/repo.png -------------------------------------------------------------------------------- /snippet/docs/vcs/git-http-proxy.md: -------------------------------------------------------------------------------- 1 | 2 | 如何让 Git 使用 HTTP 代理服务器 3 | =========================== 4 | 5 | 如果是 `git clone http://` 或 `git clone https://` 的话直接把代理服务器加到环境变量就可以了: 6 | ```shell 7 | $ export http_proxy="http://username:password@squid.vpsee.com:3128/" 8 | $ export https_proxy="http://username:password@squid.vpsee.com:3128/" 9 | ``` 10 | 11 | 如果是 `git clone git://` 的话麻烦一些(可能有的 git 源不提供 http/https 的方式),需要先安装 `socat`,然后创建一个叫做 gitproxy 的脚本并填上合适的服务器地址、端口号等,最后配置 git 使用 gitproxy 脚本: 12 | ```shell 13 | $ sudo apt-get install socat 14 | $ sudo vi /usr/bin/gitproxy 15 | #!/bin/bash 16 | PROXY=squid.vpsee.com 17 | PROXYPORT=3128 18 | PROXYAUTH=username:password 19 | exec socat STDIO PROXY:$PROXY:$1:$2,proxyport=$PROXYPORT,proxyauth=$PROXYAUTH 20 | $ sudo chmod +x /usr/bin/gitproxy 21 | $ git config --global core.gitproxy gitproxy 22 | ``` 23 | 24 | From: http://www.cnblogs.com/popsuper1982/p/3800557.html 25 | -------------------------------------------------------------------------------- /snippet/docs/web/README.md: -------------------------------------------------------------------------------- 1 | - [浏览器 HTTP 协议缓存机制详解](./browse-http-cache.md) 2 | - [URL 中的 `#`](./url_hash.md) 3 | - [URL 编码的奥秘](https://aotu.io/notes/2017/06/15/The-mystery-of-URL-encoding) 4 | - **大型网站技术架构** 5 | - [大型网站技术架构的演进](./website-evolution.md) 6 | - [大型网站技术架构-入门梳理](./website-evolution-summary.md) 7 | - **CSS** 8 | - [CSS 选择器](./css-selector.md) 9 | - [Bootstrap 速查表](http://www.ctolib.com/cheatsheets-Bootstrap-ch.html) 10 | - [16种方法实现水平居中垂直居中](http://louiszhai.github.io/2016/03/12/css-center/) 11 | - [CSS实战之Flex详解以及其在微信中的兼容实现](https://segmentfault.com/a/1190000004139009) 12 | - [让PC页面自动伸缩,以适应所有设备](http://blog.freeedit.cn/2017/05/09/HTML-0001-make-the-PC-page-Flexible) 13 | - [CSS 定位 浮动](https://segmentfault.com/a/1190000003856280) 14 | - [CSS Position 定位属性](http://www.cnblogs.com/polk6/archive/2013/07/26/3214847.html) 15 | - [CSS float 浮动属性](http://www.cnblogs.com/polk6/p/3142187.html) 16 | - **HTML** 17 | - [HTML 获取屏幕、浏览器、页面的高度宽度](http://www.cnblogs.com/polk6/p/5051935.html) 18 | - [HTML 鼠标坐标和元素坐标](http://www.cnblogs.com/polk6/p/6624779.html) 19 | - [移动前端开发之 viewport 的深入理解](http://www.cnblogs.com/2050/p/3877280.html) 20 | - **Other** 21 | - [HTML5 大文件上传](https://hhqqnu.github.io/2017/02/08/Html5%E5%A4%A7%E6%96%87%E4%BB%B6%E4%B8%8A%E4%BC%A0/) | [BaiDu Web Uploader](http://fex.baidu.com/webuploader) 22 | - [文件上传那些事儿](http://www.admin10000.com/document/13589.html) 23 | -------------------------------------------------------------------------------- /snippet/docs/web/_static/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/web/_static/1.png -------------------------------------------------------------------------------- /snippet/docs/web/_static/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/web/_static/10.png -------------------------------------------------------------------------------- /snippet/docs/web/_static/11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/web/_static/11.png -------------------------------------------------------------------------------- /snippet/docs/web/_static/12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/web/_static/12.png -------------------------------------------------------------------------------- /snippet/docs/web/_static/13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/web/_static/13.png -------------------------------------------------------------------------------- /snippet/docs/web/_static/14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/web/_static/14.png -------------------------------------------------------------------------------- /snippet/docs/web/_static/15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/web/_static/15.png -------------------------------------------------------------------------------- /snippet/docs/web/_static/16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/web/_static/16.png -------------------------------------------------------------------------------- /snippet/docs/web/_static/17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/web/_static/17.png -------------------------------------------------------------------------------- /snippet/docs/web/_static/18.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/web/_static/18.jpg -------------------------------------------------------------------------------- /snippet/docs/web/_static/19.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/web/_static/19.png -------------------------------------------------------------------------------- /snippet/docs/web/_static/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/web/_static/2.png -------------------------------------------------------------------------------- /snippet/docs/web/_static/20.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/web/_static/20.jpg -------------------------------------------------------------------------------- /snippet/docs/web/_static/20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/web/_static/20.png -------------------------------------------------------------------------------- /snippet/docs/web/_static/21.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/web/_static/21.png -------------------------------------------------------------------------------- /snippet/docs/web/_static/22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/web/_static/22.png -------------------------------------------------------------------------------- /snippet/docs/web/_static/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/web/_static/3.png -------------------------------------------------------------------------------- /snippet/docs/web/_static/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/web/_static/4.png -------------------------------------------------------------------------------- /snippet/docs/web/_static/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/web/_static/5.png -------------------------------------------------------------------------------- /snippet/docs/web/_static/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/web/_static/6.png -------------------------------------------------------------------------------- /snippet/docs/web/_static/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/web/_static/7.png -------------------------------------------------------------------------------- /snippet/docs/web/_static/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/web/_static/8.png -------------------------------------------------------------------------------- /snippet/docs/web/_static/9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/docs/web/_static/9.png -------------------------------------------------------------------------------- /snippet/docs/windows/README.md: -------------------------------------------------------------------------------- 1 | ## 1. Windows 10 关闭 Cortana 2 | 打开注册表(regedit): 3 | 4 | 在 HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\Windows Search 下添加 AllowCortana 选项,值为 0(类型为 DWORD(32))。 5 | -------------------------------------------------------------------------------- /snippet/example/c-c++/OICQ-20120820.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/example/c-c++/OICQ-20120820.tar.gz -------------------------------------------------------------------------------- /snippet/example/c-c++/fragroute/fragroute-1.2.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/example/c-c++/fragroute/fragroute-1.2.tar.gz -------------------------------------------------------------------------------- /snippet/example/c-c++/fragroute/fragtest.8.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | FRAGTEST(8) FRAGTEST(8) 5 | 6 | 7 | NAME 8 | fragtest - test IP fragment reassembly behaviour 9 | 10 | SYNOPSIS 11 | fragtest TESTS ... host 12 | 13 | DESCRIPTION 14 | fragtest probes the remote host to determine its TCP/IP 15 | stack behaviour. 16 | 17 | The TESTS may include any of the following (or may be 18 | specified as all to perform them all): 19 | 20 | ping Send an ICMP echo request to the host. 21 | 22 | ip-opt Send ICMP echo requests with different IP options, 23 | to see which IP options are supported. 24 | 25 | frag Send an ICMP echo request as 8-byte fragments. 26 | 27 | frag-new 28 | Send an ICMP echo request as 8-byte fragments with 29 | an overlapping 16-byte fragment, favoring newer 30 | data in reassembly. 31 | 32 | frag-old 33 | Send an ICMP echo request as 8-byte fragments with 34 | an overlapping 16-byte fragment, favoring older 35 | data in reassembly. 36 | 37 | frag-timeout 38 | Send an ICMP echo request as 8-byte fragments, 39 | omitting the last fragment, and wait for an ICMP 40 | time-exceeded-in-reassembly reply. 41 | 42 | SEE ALSO 43 | fragroute(8) 44 | 45 | AUTHOR 46 | Dug Song 47 | 48 | BUGS 49 | Firewalls or other filtering network devices may block IP 50 | fragments, packets with IP options, ICMP echo traffic, 51 | etc. 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 1 65 | 66 | 67 | -------------------------------------------------------------------------------- /snippet/example/c-c++/sendip/sendip-2.5.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/example/c-c++/sendip/sendip-2.5.tar.gz -------------------------------------------------------------------------------- /snippet/example/c-c++/sendip/sendip-source-analyzation.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/example/c-c++/sendip/sendip-source-analyzation.doc -------------------------------------------------------------------------------- /snippet/example/c-c++/tcpipiv1.tar.Z: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/example/c-c++/tcpipiv1.tar.Z -------------------------------------------------------------------------------- /snippet/example/dockerfile/python36.dockerfile: -------------------------------------------------------------------------------- 1 | # Python 3.6 Dockerfile 2 | 3 | # Builder 4 | FROM centos:7 as builder 5 | LABEL maintainer "xgfone@126.com" 6 | 7 | ENV ROOT=/root 8 | 9 | RUN yum groupinstall -y 'Development Tools' 10 | RUN yum install -y openssl-devel zlib-devel sqlite-devel readline-devel wget 11 | 12 | # Install Python 3.6 13 | RUN wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz -P /root 14 | RUN tar xf $ROOT/Python-3.6.5.tgz -C $ROOT 15 | WORKDIR $ROOT/Python-3.6.5 16 | RUN ./configure --enable-optimizations 17 | RUN make install 18 | 19 | # Update pip3 20 | RUN pip3 install --upgrade pip 21 | 22 | 23 | # Python 3.6 Image 24 | FROM centos:7 25 | 26 | ENV ROOT=/root 27 | 28 | RUN yum install -y wget curl tcpdump net-tools telnet vim nc mtr strace ltrace lsof htop iotop 29 | RUN yum install -y openssl zlib sqlite readline 30 | 31 | COPY --from=builder /usr/local/bin/python3* /usr/local/bin/ 32 | COPY --from=builder /usr/local/include/python3.6m /usr/local/include/python3.6m 33 | COPY --from=builder /usr/local/lib/python3.6 /usr/local/lib/python3.6 34 | COPY --from=builder /usr/local/share/man/man1/python3.6* /usr/local/share/man/man1/ 35 | COPY --from=builder /usr/local/bin/pip3* /usr/local/bin/ 36 | 37 | # Reset the work directory. 38 | WORKDIR $ROOT 39 | -------------------------------------------------------------------------------- /snippet/example/go/project/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/example/go/project/README.md -------------------------------------------------------------------------------- /snippet/example/go/project/cmd/project/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "project/project" 4 | 5 | func main() { 6 | project.Main() 7 | } 8 | -------------------------------------------------------------------------------- /snippet/example/go/project/glide.yaml: -------------------------------------------------------------------------------- 1 | package: project 2 | owners: 3 | - name: xgfone 4 | email: xgfone@126.com 5 | import: 6 | # The packages which have no dependence. 7 | - package: github.com/jessevdk/go-flags 8 | version: v1.1 9 | - package: github.com/xgfone/go-tools 10 | version: v0.34.1 11 | 12 | # The packages which have dependency. 13 | # The depended packages precede the dependent packages. 14 | - package: github.com/mattn/go-isatty 15 | version: v0.0.1 16 | - package: github.com/mattn/go-colorable 17 | version: v0.0.6 18 | - package: github.com/inconshreveable/log15 19 | version: 46a701a619de90c65a78c04d1a58bf02585e9701 20 | - package: github.com/xgfone/go-utils 21 | version: 0.1 22 | 23 | # Others 24 | # - package: golang.org/x/sys 25 | # version: 478fcf54317e52ab69f40bb4c7a1520288d7f7ea 26 | # repo: https://github.com/golang/sys 27 | # vcs: git 28 | # - package: github.com/fatih/structs 29 | # version: dc3312cb1a4513a366c4c9e622ad55c32df12ed3 30 | # - package: github.com/go-stack/stack 31 | # version: v1.5.2 32 | -------------------------------------------------------------------------------- /snippet/example/go/project/project/conf/conf.go: -------------------------------------------------------------------------------- 1 | package conf 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | 7 | flags "github.com/jessevdk/go-flags" 8 | ) 9 | 10 | // Config is the type of the global configuration. 11 | type Config struct { 12 | Version bool `short:"v" long:"version" description:"Print the version information"` 13 | Level string `short:"l" long:"level" value-name:"LEVEL" default:"debug" description:"The level of the logging"` 14 | LogFile string `short:"f" long:"logfile" value-name:"LOGFILE" default:"" description:"The path of the logging file"` 15 | } 16 | 17 | // Conf is the global configuration option. 18 | var Conf = Config{} 19 | 20 | // ParseConfig parses the configuration. 21 | func ParseConfig(version string) { 22 | if _, err := flags.Parse(&Conf); err != nil { 23 | if err.(*flags.Error).Type == flags.ErrTag { 24 | fmt.Println(err) 25 | } 26 | os.Exit(1) 27 | } 28 | 29 | if Conf.Version && len(version) > 0 { 30 | fmt.Printf("Version: %v\n", version) 31 | os.Exit(0) 32 | } 33 | 34 | // TODO ... 35 | } 36 | -------------------------------------------------------------------------------- /snippet/example/go/project/project/enter.go: -------------------------------------------------------------------------------- 1 | package project 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "os/signal" 7 | "project/project/conf" 8 | "syscall" 9 | 10 | "github.com/xgfone/go-tools/lifecycle/server" 11 | "github.com/xgfone/go-utils/log" 12 | ) 13 | 14 | var version = "1.0.0" 15 | 16 | // Main the enter of the cmd tracerapi. 17 | func Main() { 18 | // Parse the configuration 19 | conf.ParseConfig(version) 20 | 21 | // Initialize the logging 22 | logger, err := log.NewLogger(conf.Conf.Level, conf.Conf.LogFile) 23 | if err != nil { 24 | fmt.Fprintln(os.Stderr, "Failed to initialize logging:", err) 25 | os.Exit(-1) 26 | } 27 | log.SetDefaultLogger(logger) 28 | 29 | go func() { 30 | ss := make(chan os.Signal, 1) 31 | signal.Notify(ss, os.Interrupt, syscall.SIGTERM, syscall.SIGQUIT) 32 | <-ss 33 | server.Shutdown() 34 | }() 35 | 36 | // TODO 37 | 38 | // Run for ever 39 | server.RunForever() 40 | log.Info("The program exits") 41 | } 42 | -------------------------------------------------------------------------------- /snippet/example/go/snippet/port_range_test.go: -------------------------------------------------------------------------------- 1 | package snippet 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func ExamplePortRuleMasking() { 8 | ports := PortRuleMasking(1000, 1999) 9 | fmt.Println(len(ports)) 10 | fmt.Println(ports[0]) 11 | fmt.Println(ports[1]) 12 | fmt.Println(ports[2]) 13 | fmt.Println(ports[3]) 14 | fmt.Println(ports[4]) 15 | fmt.Println(ports[5]) 16 | fmt.Println(ports[6]) 17 | 18 | // Unordered output: 19 | // 7 20 | // 0x03e8/0xfff8 21 | // 0x03f0/0xfff0 22 | // 0x0400/0xfe00 23 | // 0x0600/0xff00 24 | // 0x0700/0xff80 25 | // 0x0780/0xffc0 26 | // 0x07c0/0xfff0 27 | } 28 | -------------------------------------------------------------------------------- /snippet/example/go/snippet/value_test.go: -------------------------------------------------------------------------------- 1 | package snippet 2 | 3 | import "fmt" 4 | 5 | func ExampleValues() { 6 | vs := NewValues() 7 | vs.Set("name", 123) 8 | value := vs.Get("name") 9 | 10 | fmt.Println(value) 11 | 12 | // Output: 13 | // 123 14 | } 15 | 16 | func ExampleValues_On() { 17 | vs := NewValues() 18 | vs.On("", func(n string, v interface{}) { fmt.Println("all", n, v) }) 19 | vs.On("n1", func(n string, v interface{}) { fmt.Println("name1", n, v) }) 20 | vs.On("n2", func(n string, v interface{}) { fmt.Println("name2", n, v) }) 21 | vs.Set("n1", 123) 22 | 23 | // Output: 24 | // all n1 123 25 | // name1 n1 123 26 | } 27 | 28 | func ExampleValues_Off() { 29 | vs := NewValues() 30 | 31 | cb := func(n string, v interface{}) { fmt.Println("on1", n, v) } 32 | vs.On("", func(n string, v interface{}) { fmt.Println("all", n, v) }) 33 | vs.On("n1", cb) 34 | vs.On("n2", func(n string, v interface{}) { fmt.Println("on2", n, v) }) 35 | vs.Set("n1", 123) 36 | vs.Off("n1", cb) 37 | vs.Set("n1", 456) 38 | 39 | // Output: 40 | // all n1 123 41 | // on1 n1 123 42 | // all n1 456 43 | } 44 | -------------------------------------------------------------------------------- /snippet/example/go/src/listenport/client/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "net" 6 | 7 | "github.com/xgfone/argparse" 8 | "github.com/xgfone/go-tools/parse" 9 | ) 10 | 11 | type Default struct { 12 | Proto string `default:"tcp" help:"The name of the protocol, such as tcp, tcp4, tcp6, udp, udp4, or udp6, etc." validate:"validate_str_array" array:"tcp,tcp4,tcp6,udp,udp4,udp6"` 13 | Ip string `default:"127.0.0.1" help:"The IP to listen to." validate:"validate_ip"` 14 | Port int `default:"80" help:"The port to listen to." validate:"validate_num_range" min:"1" max:"65535"` 15 | } 16 | 17 | var conf Default 18 | 19 | func udp(proto, ipport string) { 20 | if _conn, err := net.Dial(proto, ipport); err != nil { 21 | fmt.Println(err) 22 | return 23 | } else { 24 | conn := _conn.(*net.UDPConn) 25 | defer conn.Close() 26 | buf := []byte("test") 27 | conn.Write(buf) 28 | //conn.WriteToUDP(buf, addr) 29 | } 30 | } 31 | 32 | func tcp(proto, ipport string) { 33 | if _conn, err := net.Dial(proto, ipport); err != nil { 34 | fmt.Println(err) 35 | return 36 | } else { 37 | conn := _conn.(*net.TCPConn) 38 | defer conn.Close() 39 | buf := []byte("test") 40 | conn.Write(buf) 41 | } 42 | } 43 | 44 | func main() { 45 | parser := argparse.NewParser() 46 | parser.Register(&conf) 47 | parser.Parse(nil) 48 | 49 | ipport := net.JoinHostPort(conf.Ip, parse.String(conf.Port)) 50 | if conf.Proto == "tcp" || conf.Proto == "tcp4" || conf.Proto == "tcp6" { 51 | tcp(conf.Proto, ipport) 52 | } else if conf.Proto == "udp" || conf.Proto == "udp4" || conf.Proto == "udp6" { 53 | udp(conf.Proto, ipport) 54 | } else { 55 | fmt.Printf("Don't support the protocol: %v\n", conf.Proto) 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /snippet/example/go/src/listenport/server/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "net" 6 | 7 | "github.com/xgfone/argparse" 8 | "github.com/xgfone/go-tools/net/server" 9 | "github.com/xgfone/go-tools/parse" 10 | ) 11 | 12 | type Default struct { 13 | Proto string `default:"tcp" help:"The name of the protocol, such as tcp, tcp4, tcp6, udp, udp4, or udp6, etc." validate:"validate_str_array" array:"tcp,tcp4,tcp6,udp,udp4,udp6"` 14 | Ip string `default:"0.0.0.0" help:"The IP to listen to." validate:"validate_ip"` 15 | Port int `default:"80" help:"The port to listen to." validate:"validate_num_range" min:"1" max:"65535"` 16 | } 17 | 18 | var ( 19 | conf Default 20 | ) 21 | 22 | func tcp(conn *net.TCPConn) { 23 | addr := conn.RemoteAddr() 24 | fmt.Printf("Receives an connection: %v\n", addr) 25 | 26 | buf := make([]byte, 1024) 27 | for { 28 | if n, err := conn.Read(buf); err != nil { 29 | if err.Error() == "EOF" { 30 | fmt.Printf("The connection [%v] close\n", addr) 31 | } else { 32 | fmt.Println(err) 33 | } 34 | 35 | break 36 | } else { 37 | quit := strings.Lower(strings.Trim(string(buf[:n]))) 38 | if quit == "quit" || quit == "exit" { 39 | fmt.Printf("The client[%v] exit\n", addr) 40 | } else { 41 | fmt.Printf("Receive the data from %v: %v\n", addr, buf[:n]) 42 | } 43 | } 44 | } 45 | } 46 | 47 | func udp(buf []byte, addr *net.UDPAddr) []byte { 48 | fmt.Printf("Receive the data from %v: %v\n", addr, buf) 49 | return nil 50 | } 51 | 52 | func main() { 53 | parser := argparse.NewParser() 54 | parser.Register(&conf) 55 | parser.Parse(nil) 56 | 57 | var err error 58 | ipport := net.JoinHostPort(conf.Ip, parse.String(conf.Port)) 59 | 60 | if conf.Proto == "tcp" || conf.Proto == "tcp4" || conf.Proto == "tcp6" { 61 | err = server.TCPServerForever(conf.Proto, ipport, 0, tcp) 62 | } else if conf.Proto == "udp" || conf.Proto == "udp4" || conf.Proto == "udp6" { 63 | err = server.UDPServerForever(conf.Proto, ipport, 8192, udp, nil) 64 | } else { 65 | fmt.Printf("Don't support the protocol: %v\n", conf.Proto) 66 | } 67 | 68 | if err != nil { 69 | fmt.Println(err) 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /snippet/example/go/xml.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/xml" 5 | "fmt" 6 | "strings" 7 | ) 8 | 9 | /* 10 | * 11 | * 12 | * 13 | * Loading video… 14 | * what 15 | * 16 | */ 17 | var xmls = ` Loading video… what ` 18 | 19 | func main() { 20 | buf := strings.NewReader(xmls) 21 | decoder := xml.NewDecoder(buf) 22 | 23 | for t, err := decoder.Token(); err == nil; t, err = decoder.Token() { 24 | switch token := t.(type) { 25 | case xml.StartElement: 26 | fmt.Printf("StartElement: Name=%s Attr=[", token.Name) 27 | for _, attr := range token.Attr { 28 | fmt.Printf("Name=%s Value=%s, ", attr.Name, attr.Value) 29 | } 30 | fmt.Printf("]\n") 31 | case xml.EndElement: 32 | fmt.Printf("EndElement: Name: %s\n", token.Name) 33 | case xml.CharData: 34 | fmt.Printf("CharData: %s\n", string(token)) 35 | case xml.Comment: 36 | fmt.Printf("Comment: %s\n", string(token)) 37 | case xml.ProcInst: 38 | fmt.Printf("ProcInst: Target=%v Inst=%s\n", token.Target, string(token.Inst)) 39 | case xml.Directive: 40 | fmt.Printf("Directive: %s\n", string(token)) 41 | default: 42 | fmt.Printf("Error\n") 43 | } 44 | } 45 | // Output: 46 | /* 47 | ProcInst: Target=xml Inst=version="1.0" encoding="UTF-8" 48 | CharData: 49 | Comment: Comment 1 50 | CharData: 51 | StartElement: Name={ resources} Attr=[] 52 | CharData: 53 | StartElement: Name={ string} Attr=[Name={ name} Value=VideoLoading, ] 54 | CharData: Loading video… 55 | EndElement: Name: { string} 56 | CharData: 57 | StartElement: Name={ string} Attr=[Name={ name} Value=ApplicationName, ] 58 | CharData: what 59 | EndElement: Name: { string} 60 | CharData: 61 | EndElement: Name: { resources} 62 | */ 63 | } 64 | -------------------------------------------------------------------------------- /snippet/example/linux/flow_hash_list.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/example/linux/flow_hash_list.tar.gz -------------------------------------------------------------------------------- /snippet/example/linux/netfilter/Makefile: -------------------------------------------------------------------------------- 1 | target = test_nf 2 | obj-m := $(target).o 3 | KERNELDIR = /lib/modules/`uname -r`/build 4 | #KERNELDIR = /usr/src/kernels/`uname -r` 5 | default: 6 | $(MAKE) -C $(KERNELDIR) M=`pwd` modules 7 | 8 | install: 9 | insmod $(target).ko 10 | 11 | uninstall: 12 | rmmod $(target) 13 | 14 | clean: 15 | rm -rf *.o *.mod.c *.ko.* 16 | rm -rf Module.symvers .*cmd .tmp_versions modules.order 17 | 18 | -------------------------------------------------------------------------------- /snippet/example/linux/timer.c: -------------------------------------------------------------------------------- 1 | 2 | // The Kernel Timer 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #define TIMER_MAJOR 234 10 | #define DEVICE_NAME "timer_test" 11 | 12 | // 1. 定义timer结构 13 | struct timer_list timer; 14 | 15 | static void func_timer(unsigned long data) 16 | { 17 | // 4. 修改定时器的超时参数并重启 18 | mod_timer(&timer, jiffies + HZ); 19 | printk("current jiffies is %ld\n", jiffies); 20 | } 21 | 22 | struct file_operations timer_ops = { 23 | .owner = THIS_MODULE, 24 | }; 25 | 26 | static int __init timer_init(void) 27 | { 28 | register_chrdev(TIMER_MAJOR, DEVICE_NAME, &timer_ops); 29 | 30 | // 2. 初始化定时器 31 | setup_timer(&timer, func_timer, 0); 32 | #if 0 33 | init_timer(&timer); 34 | timer.data = 0; 35 | timer.expires = jiffies + HZ; 36 | timer.function = func_timer; 37 | #endif 38 | 39 | // 3. 添加激活计时器 40 | add_timer(&timer); 41 | 42 | printk("timer_init\n"); 43 | return 0; 44 | } 45 | 46 | static void __exit timer_exit(void) 47 | { 48 | // 4. 删除定时器 49 | del_timer(&timer); 50 | unregister_chrdev(TIMER_MAJOR, DEVICE_NAME); 51 | } 52 | 53 | module_init(timer_init); 54 | module_exit(timer_exit); 55 | MODULE_LICENSE("GPL"); 56 | MODULE_DESCRIPTION("TEST Kernel Timer"); 57 | MODULE_AUTHOR("XXXX "); 58 | 59 | /********************************************************/ 60 | // # insmod timer_test.ko 61 | // timer_init 62 | // timer_init 63 | // current jiffies is 220614 64 | // current jiffies is 220614 65 | // current jiffies is 220714 66 | // current jiffies is 220714 67 | -------------------------------------------------------------------------------- /snippet/example/nodejs/webpack/.eslintrc.js: -------------------------------------------------------------------------------- 1 | const eslint_config = { 2 | "extends": "eslint:recommended", 3 | "parserOptions": { 4 | "ecmaVersion": 6, 5 | "sourceType": "module", 6 | "ecmaFeatures": { 7 | "jsx": true, 8 | } 9 | }, 10 | "rules": { 11 | // enable additional rules 12 | "indent": ["error", 4], 13 | "linebreak-style": ["error", "unix"], 14 | "quotes": ["error", "single"], 15 | "semi": ["error", "always"], 16 | 17 | // override default options for rules from base configurations 18 | "comma-dangle": ["error", "always"], 19 | "no-cond-assign": ["error", "always"], 20 | 21 | // disable rules from base configurations 22 | "no-console": "off", 23 | } 24 | }; 25 | 26 | module.exports = eslint_config; 27 | -------------------------------------------------------------------------------- /snippet/example/nodejs/webpack/build/config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const process = require('process'); 3 | const _ = require('lodash'); 4 | 5 | const DEV_DIR = 'dev'; 6 | const DIST_DIR = 'dist'; 7 | 8 | const ROOT = path.join(__dirname, '..'); 9 | const resolve_path = (...dirs) => path.join(ROOT, ...dirs); 10 | const resolve_dll = (file) => path.join(config.DLL_OUTPUT_PATH, file); 11 | 12 | const config = { 13 | ROOT, 14 | ESLINT: false, 15 | APP_ROOT: resolve_path('src'), 16 | get DEBUG() { 17 | return process.env.NODE_ENV != 'production'; 18 | }, 19 | 20 | TARGET: 'web', 21 | 22 | // For Entry Points 23 | // The path is the relative path to ROOT. 24 | ENTRY: { 25 | // Set up an ES6-ish environment 26 | // babel: 'babel-polyfill', 27 | 28 | index1: ['./src/index1.js'], 29 | index2: ['./src/index2.js'], 30 | }, 31 | 32 | // For Output 33 | get OUTPUT_PUBLIC_PATH() { 34 | // const DIST_DIR = 'http://static.example.com/static/'; 35 | return config.DEBUG ? `/${DEV_DIR}/` : `/${DIST_DIR}/`; 36 | }, 37 | get OUTPUT_PATH() { 38 | const subdir = config.DEBUG ? DEV_DIR : DIST_DIR; 39 | return resolve_path(subdir); 40 | }, 41 | 42 | // For DLL 43 | DLL_NAMES: ['vendor'], 44 | DLL_OUTPUT_PATH: resolve_path('dll'), 45 | 46 | // For Development 47 | DEV_HOST: '0.0.0.0', 48 | DEV_PORT: 8000, 49 | 50 | // For Other Plugin Options 51 | HTML_TEMPLATE_PATH: ROOT, 52 | UGLIFY_JS_OPTION: { 53 | exclude: /\.min\.js$/, 54 | sourceMap: true, 55 | comments: false, 56 | mangle: false, 57 | beautify: false, 58 | compress: { 59 | warnings: false, 60 | drop_console: true, 61 | collapse_vars: true, 62 | reduce_vars: true, 63 | }, 64 | }, 65 | 66 | // Some convenient functions 67 | resolve_path, 68 | resolve_dll, 69 | path_join: path.join, 70 | } 71 | 72 | module.exports = config; 73 | -------------------------------------------------------------------------------- /snippet/example/nodejs/webpack/build/webpack.dev.config.js: -------------------------------------------------------------------------------- 1 | const webpack = require('webpack'); 2 | const webpack_merge = require('webpack-merge'); 3 | const config = require('./config'); 4 | const webpack_base_config = require('./webpack.base.config'); 5 | 6 | const webpack_dev_config = { 7 | // How Source Maps are generated. 8 | devtool: 'cheap-module-eval-source-map', 9 | 10 | output: { 11 | filename: '[name]-[hash].js', // webpack-dev-server does not support [chunkhash]. 12 | }, 13 | 14 | plugins: [ 15 | new webpack.HotModuleReplacementPlugin(), 16 | new webpack.NoEmitOnErrorsPlugin(), 17 | ], 18 | 19 | devServer: { 20 | port: config.DEV_PORT, 21 | host: config.DEV_HOST, 22 | publicPath: config.OUTPUT_PUBLIC_PATH, 23 | contentBase: [config.ROOT], 24 | 25 | watchContentBase: true, 26 | watchOptions: { 27 | aggregateTimeout: 3000, // 1s 28 | ignored: /node_modules/, 29 | poll: 3000 // Check for changes every 3 seconds. Or true. 30 | }, 31 | 32 | hot: true, 33 | inline: true, // Livereload 34 | historyApiFallback: true, 35 | }, 36 | } 37 | 38 | const webpack_config = webpack_merge.smart(webpack_base_config, webpack_dev_config); 39 | module.exports = webpack_config; 40 | -------------------------------------------------------------------------------- /snippet/example/nodejs/webpack/build/webpack.dll.config.js: -------------------------------------------------------------------------------- 1 | const webpack = require("webpack"); 2 | const config = require('./config'); 3 | 4 | const webpack_dll_config = { 5 | cache: true, 6 | target: config.TARGET, 7 | context: config.ROOT, 8 | devtool: 'cheap-module-source-map', 9 | 10 | output: { 11 | path: config.DLL_OUTPUT_PATH, 12 | filename: '[name]-[chunkhash].js', 13 | library: "[name]", 14 | }, 15 | 16 | entry: (() => { 17 | let result = {}; 18 | config.DLL_NAMES.forEach((name) => { 19 | result[name] = [config.resolve_dll(name + '.js')]; 20 | }); 21 | return result; 22 | })(), 23 | 24 | plugins: [ 25 | new webpack.DefinePlugin({ 26 | 'process.env.NODE_ENV': JSON.stringify('production'), 27 | }), 28 | new webpack.optimize.UglifyJsPlugin(config.UGLIFY_JS_OPTION), 29 | new webpack.DllPlugin({ 30 | path: config.resolve_dll('[name]-manifest.json'), 31 | name: "[name]", 32 | // context: config.DLL_OUTPUT_PATH, 33 | }), 34 | ], 35 | }; 36 | 37 | module.exports = webpack_dll_config; 38 | -------------------------------------------------------------------------------- /snippet/example/nodejs/webpack/build/webpack.production.config.js: -------------------------------------------------------------------------------- 1 | const process = require('process'); 2 | const webpack = require('webpack'); 3 | const webpack_merge = require('webpack-merge'); 4 | 5 | process.env.NODE_ENV = 'production'; 6 | const config = require('./config'); 7 | const webpack_base_config = require('./webpack.base.config'); 8 | 9 | const webpack_production_config = { 10 | // How Source Maps are generated. 11 | devtool: 'cheap-module-source-map', 12 | 13 | plugins: [ 14 | new webpack.DefinePlugin({ 15 | 'process.env.NODE_ENV': JSON.stringify('production'), 16 | }), 17 | new webpack.optimize.UglifyJsPlugin(config.UGLIFY_JS_OPTION), 18 | ], 19 | } 20 | 21 | const webpack_config = webpack_merge.smart(webpack_base_config, webpack_production_config); 22 | module.exports = webpack_config; 23 | -------------------------------------------------------------------------------- /snippet/example/nodejs/webpack/dll/vendor.js: -------------------------------------------------------------------------------- 1 | // require('jquery'); 2 | // require('lodash'); -------------------------------------------------------------------------------- /snippet/example/nodejs/webpack/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Webpack Demo 5 | 6 | 7 | 8 |
9 |
10 | 11 | 14 | 15 | -------------------------------------------------------------------------------- /snippet/example/nodejs/webpack/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "project", 3 | "version": "1.0.0", 4 | 5 | "scripts": { 6 | "clean": "echo 'clean ....'", 7 | "start": "npm run clean && npm run build:dll && npm run build:dev", 8 | "rebuild": "npm run clean && npm run build:dll && npm run build", 9 | "build": "webpack --progress --colors --config build/webpack.production.config.js", 10 | "build:dev": "webpack-dev-server --progress --colors --config build/webpack.dev.config.js", 11 | "build:dll": "webpack --progress --colors --config build/webpack.dll.config.js" 12 | }, 13 | 14 | "devDependencies": { 15 | "webpack": "^2.2.1", 16 | "webpack-dev-server": "^2.4.1", 17 | "babel-core": "^6.23.1", 18 | "babel-loader": "^6.3.2", 19 | "babel-preset-es2015": "^6.22.0", 20 | "babel-preset-es2016": "^6.22.0", 21 | "babel-preset-es2017": "^6.22.0", 22 | "babel-preset-react": "^6.23.0", 23 | "babel-polyfill": "^6.23.0", 24 | "babel-runtime": "^6.23.0", 25 | "babel-plugin-transform-runtime": "^6.23.0", 26 | "html-webpack-plugin": "^2.28.0", 27 | // "extract-text-webpack-plugin": "^2.0.0", 28 | "copy-webpack-plugin": "^4.0.1", 29 | "eslint": "^3.15.0", 30 | "eslint-loader": "^1.6.1", 31 | "eslint-plugin-react": "^6.10.0" 32 | }, 33 | "dependencies": { 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /snippet/example/nodejs/webpack/src/index1.js: -------------------------------------------------------------------------------- 1 | import $ from 'jquery'; 2 | 3 | console.log("index1", $); -------------------------------------------------------------------------------- /snippet/example/nodejs/webpack/src/index2.js: -------------------------------------------------------------------------------- 1 | import $ from 'jquery'; 2 | 3 | console.log("index2", $); -------------------------------------------------------------------------------- /snippet/example/python/api_proxy.py: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | 3 | import threading 4 | 5 | 6 | class APIProxy(object): 7 | def __init__(self, load_api, *args, use_tpool=False, **kwargs): 8 | self._load_api = load_api 9 | self._use_tpool = use_tpool 10 | self._args = args 11 | self._kwargs = kwargs 12 | 13 | self._db_api = None 14 | self._lock = threading.Lock() 15 | 16 | @property 17 | def _api(self): 18 | if not self._db_api: 19 | with self._lock: 20 | if not self._db_api: 21 | db_api = self._load_api(*self._args, **self._kwargs) 22 | if self._use_tpool: 23 | from eventlet import tpool 24 | self._db_api = tpool.Proxy(db_api) 25 | else: 26 | self._db_api = db_api 27 | return self._db_api 28 | 29 | def __getattr__(self, name): 30 | return getattr(self._api, name) 31 | -------------------------------------------------------------------------------- /snippet/example/python/bt/ItMetadata.py: -------------------------------------------------------------------------------- 1 | #coding: utf8 2 | import threading 3 | import traceback 4 | import random 5 | import time 6 | import os 7 | import socket 8 | 9 | import libtorrent as lt 10 | 11 | threading.stack_size(200 * 1024) 12 | socket.setdefaulttimeout(30) 13 | 14 | 15 | def fetch_torrent(session, ih, timeout): 16 | name = ih.upper() 17 | url = 'magnet:?xt=urn:btih:%s' % (name,) 18 | params = { 19 | 'save_path': '/tmp/downloads/', 20 | 'storage_mode': lt.storage_mode_t(2), 21 | 'paused': False, 22 | 'auto_managed': False, 23 | 'duplicate_is_error': True} 24 | try: 25 | handle = lt.add_magnet_uri(session, url, params) 26 | except Exception: 27 | return None 28 | handle.set_sequential_download(1) 29 | meta = None 30 | down_path = None 31 | for i in range(0, timeout): 32 | if handle.has_metadata(): 33 | info = handle.get_torrent_info() 34 | down_path = '/tmp/downloads/%s' % info.name() 35 | meta = info.metadata() 36 | break 37 | time.sleep(1) 38 | if down_path and os.path.exists(down_path): 39 | os.system('rm -rf "%s"' % down_path) 40 | session.remove_torrent(handle) 41 | return meta 42 | 43 | 44 | def download_metadata(address, binhash, metadata_queue, timeout=40): 45 | metadata = None 46 | start_time = time.time() 47 | try: 48 | session = lt.session() 49 | r = random.randrange(10000, 50000) 50 | session.listen_on(r, r + 10) 51 | session.add_dht_router('router.bittorrent.com', 6881) 52 | session.add_dht_router('router.utorrent.com', 6881) 53 | session.add_dht_router('dht.transmission.com', 6881) 54 | session.add_dht_router('127.0.0.1', 6881) 55 | session.start_dht() 56 | metadata = fetch_torrent(session, binhash.encode('hex'), timeout) 57 | session = None 58 | except Exception: 59 | traceback.print_exc() 60 | finally: 61 | metadata_queue.put((binhash, address, metadata, 'lt', start_time)) 62 | -------------------------------------------------------------------------------- /snippet/example/python/bt/metautils.py: -------------------------------------------------------------------------------- 1 | #coding: utf8 2 | import os 3 | import binascii 4 | 5 | 6 | cats = { 7 | u'video': u'Videos', 8 | u'image': u'Images', 9 | u'document': u'Books', 10 | u'music': u'Musics', 11 | u'package': u'Packages', 12 | u'software': u'Softwares', 13 | } 14 | 15 | 16 | def get_label(name): 17 | if name in cats: 18 | return cats[name] 19 | return u'Others' 20 | 21 | 22 | def get_label_by_crc32(n): 23 | for k in cats: 24 | if binascii.crc32(k) & 0xFFFFFFFFL == n: 25 | return k 26 | return u'other' 27 | 28 | 29 | def get_extension(name): 30 | return os.path.splitext(name)[1] 31 | 32 | 33 | def get_category(ext): 34 | ext = ext + '.' 35 | cats = { 36 | u'video': '.avi.mp4.rmvb.m2ts.wmv.mkv.flv.qmv.rm.mov.vob.asf.3gp.mpg.mpeg.m4v.f4v.', 37 | u'image': '.jpg.bmp.jpeg.png.gif.tiff.', 38 | u'document': '.pdf.isz.chm.txt.epub.bc!.doc.ppt.', 39 | u'music': '.mp3.ape.wav.dts.mdf.flac.', 40 | u'package': '.zip.rar.7z.tar.gz.iso.dmg.pkg.', 41 | u'software': '.exe.app.msi.apk.' 42 | } 43 | for k, v in cats.iteritems(): 44 | if ext in v: 45 | return k 46 | return u'other' 47 | 48 | 49 | def get_detail(y): 50 | if y.get('files'): 51 | y['files'] = [z for z in y['files'] if not z['path'].startswith('_')] 52 | else: 53 | y['files'] = [{'path': y['name'], 'length': y['length']}] 54 | y['files'].sort(key=lambda z: z['length'], reverse=True) 55 | bigfname = y['files'][0]['path'] 56 | ext = get_extension(bigfname).lower() 57 | y['category'] = get_category(ext) 58 | y['extension'] = ext 59 | -------------------------------------------------------------------------------- /snippet/example/python/call_retry.py: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 2 | 3 | import time 4 | import functools 5 | 6 | 7 | class Retry(object): 8 | def __init__(self, max_retries=2, retry_interval=1, max_retry_interval=5, 9 | increase_retry_interval=True): 10 | self._max_retries = max_retries 11 | self._retry_interval = retry_interval 12 | self._max_retry_interval = max_retry_interval 13 | self._increase_retry_interval = increase_retry_interval 14 | 15 | def __call__(self, func): 16 | @functools.wraps(func) 17 | def wrapper(*args, **kwargs): 18 | return self.call(func, *args, **kwargs) 19 | 20 | return wrapper 21 | 22 | def call(self, func, *args, **kwargs): 23 | interval = self._retry_interval 24 | remaining_retries = self._max_retries 25 | 26 | while True: 27 | try: 28 | return func(*args, **kwargs) 29 | except (IOError, OSError): 30 | if remaining_retries <= 0: 31 | raise 32 | time.sleep(interval) 33 | if self._increase_retry_interval: 34 | interval = min(interval * 2, self._max_retry_interval) 35 | remaining_retries -= 1 36 | -------------------------------------------------------------------------------- /snippet/example/python/falcon_app.py: -------------------------------------------------------------------------------- 1 | import logging 2 | import traceback 3 | import falcon 4 | 5 | LOG = logging.getLogger("gunicorn.error") 6 | 7 | 8 | def _add_route(app, uri_template, resource, *args): 9 | if not app: 10 | app = globals()["application"] 11 | if callable(resource): 12 | method_map = {method.upper(): resource for method in args or ["GET"]} 13 | falcon.routing.set_default_responders(method_map) 14 | app._router.add_route(uri_template, method_map, resource) 15 | else: 16 | app.add_route(uri_template, resource) 17 | 18 | 19 | def add_route(uri_template, resource, *args, app=None): 20 | _add_route(app or globals()["application"], uri_template, resource, *args) 21 | 22 | 23 | def append_exception_handler(app, handler, exc=Exception): 24 | app._error_handlers.append((exc, handler)) 25 | 26 | 27 | def falcon_default_exception_handler(ex, req, resp, params): 28 | resp.content_type = falcon.MEDIA_TEXT 29 | resp.status = falcon.HTTP_500 30 | resp.body = str(ex) 31 | LOG.error("Get an exception: method=%s, url=%s, err=%s, traceback=\n%s", 32 | req.method, req.path, ex, traceback.format_exc()) 33 | -------------------------------------------------------------------------------- /snippet/example/python/greentaskpool.py: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | 3 | import logging 4 | 5 | LOG = logging.getLogger(__name__) 6 | 7 | 8 | class GreenTaskPool(object): 9 | from threading import Thread 10 | 11 | def __init__(self, size=10000, use_eventlet=False, use_gevent=False, 12 | auto_detection=False): 13 | self._size = size 14 | 15 | if use_eventlet: 16 | eventlet = __import__("eventlet") 17 | self._pool = self._init_eventlet(eventlet) 18 | elif use_gevent: 19 | gevent = __import__("gevent") 20 | self._pool = self._init_gevent(gevent) 21 | elif auto_detection: 22 | try: 23 | eventlet = __import__("eventlet") 24 | self._pool = self._init_eventlet(eventlet) 25 | except ImportError: 26 | try: 27 | gevent = __import__("gevent") 28 | self._init_gevent(gevent) 29 | except ImportError: 30 | self._pool = None 31 | LOG.warning("Use threading.Thread to execute the task.") 32 | else: 33 | self._pool = None 34 | LOG.warning("Use threading.Thread to execute the task.") 35 | 36 | self._spawn = self._pool.spawn if self._pool else GreenTaskPool._spawn_thread 37 | 38 | def _init_eventlet(self, eventlet): 39 | eventlet.monkey_patch(all=True) 40 | return eventlet.GreenPool(size=self._size) 41 | 42 | def _init_gevent(self, gevent): 43 | gevent.monkey.patch_all(httplib=True, sys=True) 44 | return gevent.pool.Pool(size=self._size) 45 | 46 | @staticmethod 47 | def _spawn_thread(func, *args, **kwargs): 48 | t = GreenTaskPool.Thread(target=func, args=args, kwargs=kwargs) 49 | t.daemon = True 50 | t.start() 51 | return t 52 | 53 | def spawn(self, func, *args, **kwargs): 54 | return self._spawn(func, *args, **kwargs) 55 | -------------------------------------------------------------------------------- /snippet/example/python/gunicorn-conf.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- encoding: utf-8 -*- 3 | # Notice: This config file is a Python module file. 4 | 5 | import os 6 | import multiprocessing 7 | import gunicorn.glogging 8 | 9 | 10 | # [Gunicorn Setting Section] 11 | appname = "{APPNAME}" 12 | bind = "0.0.0.0:8000" 13 | pidfile = "/var/run/{appname}.pid".format(appname=appname) 14 | logfile = "/log/{appname}/{appname}.log".format(appname=appname) 15 | 16 | # Create the necessary directories. 17 | os.makedirs("/log/{appname}".format(appname=appname), exist_ok=True) 18 | 19 | # Configure Base 20 | daemon = True 21 | proc_name = appname 22 | raw_env = "APP_CONFIG={0}".format(__file__) 23 | 24 | # Configure Worker 25 | worker_connections = 10000 26 | workers = multiprocessing.cpu_count() * 2 27 | try: 28 | import eventlet as _ 29 | worker_class = "eventlet" 30 | except ImportError: 31 | import gevent as _ 32 | worker_class = "gevent" 33 | 34 | # Configure Logging 35 | filehandler = { 36 | "class": "logging.handlers.RotatingFileHandler", 37 | "formatter": "generic", 38 | "filename": logfile, 39 | "maxBytes": 1024 ** 3, # 1GB 40 | "backupCount": 30, 41 | } 42 | logconfig_dict = gunicorn.glogging.CONFIG_DEFAULTS.copy() 43 | logconfig_dict["handlers"]["console"] = filehandler 44 | logconfig_dict["handlers"]["error_console"] = filehandler 45 | 46 | 47 | # [App Setting] 48 | -------------------------------------------------------------------------------- /snippet/example/python/gunicorn-logrotate.conf: -------------------------------------------------------------------------------- 1 | /path/to/{APPNAME}.log { 2 | size 1G 3 | rotate 90 4 | missingok 5 | compress 6 | delaycompress 7 | notifempty 8 | postrotate 9 | ps aux | grep gunicorn | grep master | grep {APPNAME} | awk '{print $2}' | xargs kill -USR1 > /dev/null 2>&1 || true 10 | endscript 11 | } 12 | -------------------------------------------------------------------------------- /snippet/example/python/gunicorn_app.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- encoding: utf-8 -*- 3 | 4 | __VERSION__ = "1.0.0" 5 | if __name__ == "__main__": 6 | print(__VERSION__) 7 | import os 8 | os._exit(0) 9 | 10 | import os 11 | import os.path 12 | import logging 13 | 14 | from gunicorn._compat import execfile_ as execpyfile 15 | 16 | LOG = logging.getLogger("gunicorn.error") 17 | 18 | 19 | def get_config_file(filename="app_config.py", dir=None): 20 | _dir = dir if dir else os.path.dirname(dir) 21 | path = os.path.join(_dir, filename) 22 | if os.path.exists(path): 23 | return path 24 | if not _dir or _dir == "/": 25 | raise OSError("Cannot find the config file '%s'" % filename) 26 | return get_config_file(filename=filename, dir=os.path.dirname(_dir)) 27 | 28 | 29 | def load_app_config(name="APP_CONFIG"): 30 | config_file = os.environ.get(name, None) or get_config_file(name.lower() + ".py") 31 | if not os.path.exists(config_file): 32 | raise RuntimeError("'%r' doest't exist" % config_file) 33 | cfg = {"__builtins__": __builtins__, "__file__": config_file} 34 | execpyfile(config_file, cfg, cfg) 35 | return cfg 36 | -------------------------------------------------------------------------------- /snippet/example/python/lifemanager.py: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | 3 | import time 4 | import logging 5 | 6 | from threading import Lock 7 | 8 | LOG = logging.getLogger(__name__) 9 | 10 | 11 | class LifeManager(object): 12 | 13 | def __init__(self): 14 | self._callbacks = [] 15 | self._should_stop = False 16 | self._lock = Lock() 17 | self._stopped = False 18 | 19 | def register(self, func, *args, **kwargs): 20 | with self._lock: 21 | if self._stopped: 22 | raise RuntimeError("have stopped") 23 | self._callbacks.append((func, args, kwargs)) 24 | 25 | def stop(self): 26 | with self._lock: 27 | if self._stopped: 28 | return 29 | self._stopped = True 30 | for func, args, kwargs in self._callbacks: 31 | try: 32 | func(*args, **kwargs) 33 | except Exception as err: 34 | LOG.error("Failed to execute %s: %s", func.__name__, err) 35 | self._should_stop = True 36 | 37 | def is_stopped(self): 38 | with self._lock: 39 | return self._stopped 40 | 41 | def run_forever(self): 42 | while True: 43 | with self._lock: 44 | if self._should_stop: 45 | break 46 | time.sleep(1) 47 | 48 | def wait(self): 49 | if self.is_stopped(): 50 | return 51 | self._wait() 52 | 53 | def _wait(self): 54 | lock = Lock() 55 | lock.acquire() 56 | self.register(lock.release) 57 | lock.acquire() 58 | lock.release() 59 | -------------------------------------------------------------------------------- /snippet/example/python/oslo_messaging/client.py: -------------------------------------------------------------------------------- 1 | # encoding: utf8 2 | 3 | import oslo_messaging 4 | 5 | 6 | class TestClient(object): 7 | def __init__(self, transport): 8 | target = oslo_messaging.Target(topic='test', version='2.0') 9 | self._client = oslo_messaging.RPCClient(transport, target) 10 | 11 | def test(self, ctxt, arg): 12 | #cctxt = self._client.prepare(version='2.5') 13 | return self._client.call(ctxt, 'test', arg=arg) 14 | 15 | 16 | transport = oslo_messaging.get_transport(cfg.CONF) 17 | target = oslo_messaging.Target(topic='test', version='2.0') 18 | 19 | client = oslo_messaging.RPCClient(transport, target) 20 | client.call(ctxt, 'test', arg=arg) 21 | 22 | client = oslo_messaging.RPCClient(transport, target, retry=None) 23 | try: 24 | client.prepare(retry=0).cast(ctxt, 'ping') 25 | except oslo_messaging.MessageDeliveryFailure: 26 | LOG.error("Failed to send ping message") 27 | -------------------------------------------------------------------------------- /snippet/example/python/osloconfig.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | import sys 3 | 4 | from oslo_config import cfg 5 | 6 | _ROOTS = ["root"] 7 | _DEFAULT_LOG_LEVELS = ['root=INFO'] 8 | _DEFAULT_LOG_FORMAT = "%(asctime)s - %(name)s - %(funcName)s - %(levelname)s - %(message)s" 9 | 10 | 11 | def parse_args_with_log(project, argv=None, version=None, conf=None, log=True, 12 | default_config_files=None, default_log_format=None, 13 | default_log_levels=None): 14 | 15 | conf = conf if conf else cfg.CONF 16 | argv = argv if argv else sys.argv[1:] 17 | 18 | if not log: 19 | conf(argv, project=project, version=version, 20 | default_config_files=default_config_files) 21 | return 22 | 23 | from oslo_log import log 24 | 25 | if project not in _ROOTS: 26 | _DEFAULT_LOG_LEVELS.append('%s=INFO' % project) 27 | _ROOTS.append(project) 28 | log_fmt = default_log_format if default_log_format else _DEFAULT_LOG_FORMAT 29 | log_lvl = default_log_levels if default_log_levels else _DEFAULT_LOG_LEVELS 30 | 31 | log.set_defaults(log_fmt, log_lvl) 32 | log.register_options(conf) 33 | 34 | # (TODO): Configure the options of the other libraries, which must be called 35 | # before parsing the configuration file. 36 | 37 | conf(argv, project=project, version=version, 38 | default_config_files=default_config_files) 39 | 40 | log.setup(conf, project, version) 41 | -------------------------------------------------------------------------------- /snippet/example/python/oslolog.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | """ 3 | Use the library 'oslo.log' to configure the logging. 4 | 5 | Applications should use oslo.log’s configuration functions to register 6 | logging-related configuration options and configure the root and other default 7 | loggers. 8 | 9 | (1) Call register_options() before parsing command line options. 10 | (2) Call set_defaults() before configuring logging. 11 | (3) Call setup() to configure logging for the application. 12 | 13 | ## Example 14 | 15 | import sys 16 | from oslo_log import log 17 | 18 | 19 | def set_log(conf, project, args=None, version="unknown", default_log_levels=None, 20 | logging_config_file=None): 21 | # Register the command line and configuration options used by oslo.log. 22 | log.register_options(conf) 23 | 24 | # Set default values for the configuration options used by oslo.log. 25 | log.set_defaults(default_log_levels=default_log_levels) 26 | 27 | # Parse the command line options. 28 | args = args if args else sys.argv[1:] 29 | conf(args, project=project, version=version) 30 | 31 | # Setup logging for the current application. 32 | if logging_config_file: 33 | log._load_log_config(logging_config_file) 34 | else: 35 | log.setup(conf, project, version) 36 | 37 | """ 38 | -------------------------------------------------------------------------------- /snippet/example/python/password.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import random 4 | 5 | 6 | # Default symbols to use for passwords. Avoids visually confusing characters. 7 | # ~6 bits per symbol 8 | DEFAULT_PASSWORD_SYMBOLS = ('23456789', # Removed: 0,1 9 | 'ABCDEFGHJKLMNPQRSTUVWXYZ', # Removed: I, O 10 | 'abcdefghijkmnopqrstuvwxyz') # Removed: l 11 | 12 | 13 | # ~5 bits per symbol 14 | EASIER_PASSWORD_SYMBOLS = ('23456789', # Removed: 0, 1 15 | 'ABCDEFGHJKLMNPQRSTUVWXYZ') # Removed: I, O 16 | 17 | 18 | def generate_password(length, symbolgroups=DEFAULT_PASSWORD_SYMBOLS): 19 | """Generate a random password from the supplied symbol groups. 20 | 21 | At least one symbol from each group will be included. Unpredictable 22 | results if length is less than the number of symbol groups. 23 | 24 | Believed to be reasonably secure (with a reasonable password length!) 25 | 26 | """ 27 | r = random.SystemRandom() 28 | 29 | # NOTE(jerdfelt): Some password policies require at least one character 30 | # from each group of symbols, so start off with one random character 31 | # from each symbol group 32 | password = [r.choice(s) for s in symbolgroups] 33 | # If length < len(symbolgroups), the leading characters will only 34 | # be from the first length groups. Try our best to not be predictable 35 | # by shuffling and then truncating. 36 | r.shuffle(password) 37 | password = password[:length] 38 | length -= len(password) 39 | 40 | # then fill with random characters from all symbol groups 41 | symbols = ''.join(symbolgroups) 42 | password.extend([r.choice(symbols) for _i in range(length)]) 43 | 44 | # finally shuffle to ensure first x characters aren't from a 45 | # predictable group 46 | r.shuffle(password) 47 | 48 | return ''.join(password) 49 | -------------------------------------------------------------------------------- /snippet/example/python/ping_ip.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # 3 | # For Python 3.3+ 4 | # 5 | 6 | import sys 7 | import queue 8 | import threading 9 | import ipaddress 10 | import subprocess 11 | 12 | OPT = "-n 1 -w 1000" if sys.platform in ("win32", "cygwin") else "-c 1 -W 1" 13 | 14 | 15 | def ping_ip(ip, results): 16 | ok = True 17 | try: 18 | subprocess.check_output("ping {0} {1}".format(OPT, ip), shell=True) 19 | except Exception: 20 | ok = False 21 | results.put(ip) 22 | print("Test {:15} --> {}".format(ip, "OK" if ok else "X")) 23 | 24 | 25 | def _ping_ips(ips): 26 | tasks = [] 27 | results = queue.Queue() 28 | for ip in ips: 29 | t = threading.Thread(target=ping_ip, args=(ip, results), daemon=True) 30 | t.start() 31 | tasks.append(t) 32 | 33 | for t in tasks: 34 | t.join() 35 | 36 | ips = [] 37 | while True: 38 | try: 39 | ips.append(results.get_nowait()) 40 | results.task_done() 41 | except Exception: 42 | break 43 | return ips 44 | 45 | 46 | def ping_ips(ips, size=1000): 47 | results = [] 48 | while ips: 49 | results.extend(_ping_ips(ips[:size])) 50 | ips = ips[size:] 51 | 52 | return results 53 | 54 | 55 | def parse_ips(args): 56 | ips = set() 57 | for v in args: 58 | for ip in v.split(","): 59 | ip = ip.strip() 60 | if not ip: 61 | continue 62 | if "/" not in ip: 63 | ips.add(ip) 64 | continue 65 | for ip in ipaddress.IPv4Network(ip, strict=False).hosts(): 66 | ips.add(str(ip)) 67 | 68 | return sorted(ips) 69 | 70 | 71 | if __name__ == "__main__": 72 | ips = parse_ips(sys.argv[1:]) 73 | failed_ips = ping_ips(ips) 74 | print("\nFailed IPs:\n {}".format(failed_ips)) 75 | -------------------------------------------------------------------------------- /snippet/example/python/project/PKG-INFO: -------------------------------------------------------------------------------- 1 | Metadata-Version: 1.1 2 | Name: {PROJECT} 3 | Version: 0.1 4 | Summary: {SUMMARY} 5 | Home-page: {HOME_URL} 6 | Author: xgfone 7 | Author-email: xgfone@126.com 8 | Maintainer: xgfone 9 | Maintainer-email: xgfone@126.com 10 | License: Apache License 2.0 11 | platform = UNIX/Linux 12 | Description: README.rst 13 | Classifier: License :: OSI Approved :: Apache Software License 14 | Classifier: Programming Language :: Python 15 | Classifier: Programming Language :: Python :: 2 16 | Classifier: Programming Language :: Python :: 2.6 17 | Classifier: Programming Language :: Python :: 2.7 18 | Classifier: Programming Language :: Python :: 3 19 | Classifier: Programming Language :: Python :: 3.3 20 | Classifier: Programming Language :: Python :: 3.4 21 | Classifier: Programming Language :: Python :: 3.5 22 | Classifier: Programming Language :: Python :: 3.6 23 | -------------------------------------------------------------------------------- /snippet/example/python/project/README.rst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/example/python/project/README.rst -------------------------------------------------------------------------------- /snippet/example/python/project/doc/Introduction.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/example/python/project/doc/Introduction.txt -------------------------------------------------------------------------------- /snippet/example/python/project/logging.ini: -------------------------------------------------------------------------------- 1 | [loggers] 2 | keys=root,{PROJECT} 3 | 4 | [handlers] 5 | keys=consoleHandler,fileHandler 6 | 7 | [formatters] 8 | keys=simpleFormatter 9 | 10 | [logger_root] 11 | level=DEBUG 12 | handlers=fileHandler,consoleHandler 13 | 14 | [logger_{PROJECT}] 15 | level=INFO 16 | handlers=fileHandler,consoleHandler 17 | propagate=0 18 | # The `qualname` entry is the hierarchical channel name of the logger, 19 | # that is to say the name used by the application to get the logger 20 | qualname={PROJECT} 21 | 22 | [handler_consoleHandler] 23 | class=StreamHandler 24 | level=DEBUG 25 | formatter=simpleFormatter 26 | args=(sys.stderr,) 27 | 28 | [handler_fileHandler] 29 | class=handlers.TimedRotatingFileHandler 30 | level=INFO 31 | formatter=simpleFormatter 32 | # 'S': Seconds 33 | # 'M': Minutes 34 | # 'H': Hours 35 | # 'D': Days 36 | # 'W0'-'W6': Weekday (0=Monday) 37 | # 'midnight': Roll over at midnight 38 | args=('/var/log/{PROJECT}/{PROJECT}.log', 'midnight', 1, 31) 39 | 40 | [formatter_simpleFormatter] 41 | format=%(asctime)s - %(pathame)s - %(module)s - %(funcName)s - %(levelname)s - %(message)s 42 | datefmt=%Y-%m-%d %H:%M:%S 43 | -------------------------------------------------------------------------------- /snippet/example/python/project/project.conf: -------------------------------------------------------------------------------- 1 | [DEFAULT] 2 | 3 | # The log level, such as DEBUG, INFO, etc. 4 | #log_level = DEBUG 5 | 6 | # The path of the log file. 7 | #log_file = 8 | -------------------------------------------------------------------------------- /snippet/example/python/project/project/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/example/python/project/project/__init__.py -------------------------------------------------------------------------------- /snippet/example/python/project/project/_options.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | from __future__ import absolute_import, print_function, unicode_literals, division 3 | 4 | from oslo_config import cfg 5 | 6 | CONF = cfg.CONF 7 | 8 | global_opts = [ 9 | cfg.StrOpt("log_file", default="", help="The path of the log file."), 10 | cfg.StrOpt("log_level", default="DEBUG", help="The log level, such as DEBUG, INFO, etc."), 11 | ] 12 | -------------------------------------------------------------------------------- /snippet/example/python/project/project/common/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/example/python/project/project/common/__init__.py -------------------------------------------------------------------------------- /snippet/example/python/project/project/db/__init__.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | from __future__ import absolute_import, print_function, unicode_literals, division 3 | 4 | from oslo_config import cfg 5 | from oslo_db import concurrency 6 | from oslo_log import log as logging 7 | 8 | CONF = cfg.CONF 9 | LOG = logging.getLogger(__name__) 10 | 11 | _BACKEND_MAPPING = {'sqlalchemy': "{PROJECT}.db.sqlalchemy.api"} 12 | IMPL = concurrency.TpoolDbapiWrapper(CONF, backend_mapping=_BACKEND_MAPPING) 13 | api = IMPL 14 | # import threading 15 | # from oslo_db import api 16 | # 17 | # _IMPL = None 18 | # _LOCK = threading.Lock() 19 | # def get_api(): 20 | # global _IMPL, _LOCK 21 | # if not _IMPL: 22 | # with _LOCK: 23 | # if not _IMPL: 24 | # _IMPL = api.DBAPI.from_config(conf=CONF, 25 | # backend_mapping=_BACKEND_MAPPING) 26 | # return _IMPL 27 | 28 | 29 | #################################### 30 | # API Interface 31 | def get_data(id): 32 | return IMPL.get_data(id) 33 | 34 | 35 | def set_data(data): 36 | return IMPL.set_data(data) 37 | -------------------------------------------------------------------------------- /snippet/example/python/project/project/db/sqlalchemy/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/example/python/project/project/db/sqlalchemy/__init__.py -------------------------------------------------------------------------------- /snippet/example/python/project/project/db/sqlalchemy/api.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | from __future__ import absolute_import, print_function, unicode_literals, division 3 | 4 | import sys 5 | import logging 6 | 7 | from oslo_config import cfg 8 | from oslo_db import options as oslo_db_options 9 | 10 | from .base import get_session, get_engine 11 | from . import models 12 | 13 | LOG = logging.getLogger(__name__) 14 | CONF = cfg.CONF 15 | 16 | CONF.register_opts(oslo_db_options.database_opts, 'database') 17 | 18 | 19 | def get_backend(): 20 | """The backend is this module itself.""" 21 | return sys.modules[__name__] 22 | 23 | 24 | ########################################################### 25 | # Utility Functions 26 | def get_attr(obj, name): 27 | if hasattr(obj, name): 28 | return getattr(obj, name) 29 | return obj[name] 30 | 31 | 32 | class RowRroxy(object): 33 | def __init__(self, obj, *args, **kwargs): 34 | self._obj = obj 35 | self._args = args 36 | self._kwargs = kwargs 37 | 38 | def __getattr__(self, name): 39 | return get_attr(self._obj, name) 40 | 41 | def __eq__(self, other): 42 | for k in iter(self._obj): 43 | if getattr(self._obj, k) != getattr(other._obj, k): 44 | return False 45 | return True 46 | 47 | def __ne__(self, other): 48 | return not self.__eq__(other) 49 | 50 | 51 | ############################################################### 52 | # API Interfaces 53 | def get_data(_id): 54 | model = models.TestData 55 | session = get_session(CONF.database) 56 | query = session.query(model) 57 | obj = query.filter_by(id=_id).first() 58 | if obj: 59 | return { 60 | "id": obj.id, 61 | "data": obj.data 62 | } 63 | else: 64 | return None 65 | 66 | 67 | def set_data(data): 68 | model = models.TestData 69 | session = get_session(CONF.database) 70 | obj = model(data=data) 71 | obj.save(session) 72 | return { 73 | "id": obj.id, 74 | } 75 | -------------------------------------------------------------------------------- /snippet/example/python/project/project/db/sqlalchemy/models.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | from __future__ import absolute_import, print_function, unicode_literals, division 3 | 4 | import logging 5 | 6 | from sqlalchemy.ext.declarative import declarative_base 7 | from oslo_db.sqlalchemy import models 8 | from sqlalchemy import create_engine 9 | from sqlalchemy import Column, String, Integer, DateTime 10 | from sqlalchemy.sql import fun 11 | 12 | LOG = logging.getLogger(__name__) 13 | BASE = declarative_base() 14 | 15 | 16 | class TestData(models.ModelBase, BASE): 17 | __tablename__ = 'test_data' 18 | 19 | id = Column(Integer, primary_key=True, autoincrement=True) 20 | data = Column(String(256), nullable=False) 21 | create_time = Column(DateTime, server_default=func.now(), nullable=False) 22 | 23 | def __init__(self, *args, **kwargs): 24 | super(TestData, self).__init__() 25 | for k, v in kwargs.items(): 26 | setattr(self, k, v) 27 | 28 | def create_tables(engine=None): 29 | if not engine: 30 | try: 31 | import sys 32 | engine = sys.argv[1] 33 | except IndexError: 34 | engine = "sqlite:///:memory:" 35 | engine = create_engine(engine, echo=True) 36 | BASE.metadata.create_all(engine) 37 | 38 | 39 | if __name__ == '__main__': 40 | create_tables("sqlite:///:memory:") 41 | -------------------------------------------------------------------------------- /snippet/example/python/project/project/main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # encoding: utf-8 3 | from __future__ import absolute_import, print_function, unicode_literals, division 4 | 5 | try: 6 | import gevent.monkey 7 | gevent.monkey.patch_all(httplib=True, sys=True, Event=True) 8 | except ImportError: 9 | pass 10 | 11 | import logging 12 | 13 | from oslo_config.cfg import CONF 14 | from {PROJECT}._option import global_opts 15 | from {PROJECT}.common.logging import init_logging 16 | from {PROJECT}.common import utils 17 | 18 | LOG = logging.getLogger(__name__) 19 | CONF.register_cli_opts(global_opts) 20 | 21 | 22 | def main(project="example", version=None): 23 | CONF(project=project, version=get_version(project, version)) 24 | 25 | init_logging(logging.getLogger(project), level=CONF.log_level, 26 | log_file=CONF.log_file) 27 | 28 | # TODO 29 | 30 | 31 | if __name__ == '__main__': 32 | main() 33 | -------------------------------------------------------------------------------- /snippet/example/python/project/requirements.txt: -------------------------------------------------------------------------------- 1 | # The order of packages is significant, because pip processes them in the order 2 | # of appearance. Changing the order has an impact on the overall integration 3 | # process, which may cause wedges in the gate later. 4 | 5 | pbr>=1.4 6 | setuptools>=16.0 7 | six>=1.9.0 8 | oslo.config>=2.1.0 # Apache-2.0 9 | # gevent>=1.2.0 10 | # PyMySQL 11 | # SQLAlchemy 12 | # oslo.service 13 | # oslo.db 14 | -------------------------------------------------------------------------------- /snippet/example/python/project/setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | name = {PROJECT} 3 | 4 | [files] 5 | packages = 6 | {PROJECT} 7 | 8 | [entry_points] 9 | {PROJECT}.{XX}.{YY}.{ZZ} = 10 | # {AA}, {BB}, {CC} are modules, and {ATTR} is the attribution of the module. 11 | {AA} = {BB}.{CC}:{ATTR} 12 | {DD} = {EE}:{ATTR} 13 | 14 | console_scripts = 15 | # {CALLABLE} is a callable object. 16 | {CMD1} = {AA}.{BB}:{CALLABLE} 17 | {CMD2} = {CC}.{DD}.{EE}:{CALLABLE} 18 | 19 | [global] 20 | setup-hooks = 21 | 22 | [build_sphinx] 23 | all_files = 1 24 | build-dir = doc/build 25 | source-dir = doc/source 26 | 27 | [egg_info] 28 | tag_build = 29 | tag_date = 0 30 | tag_svn_revision = 0 31 | 32 | [wheel] 33 | universal = 1 34 | 35 | [pbr] 36 | # Have pbr generate the module indexes like sphinx autodoc 37 | autodoc_index_modules = True 38 | 39 | # Exclude modules that won't build with autodoc (or that we don't want doc'ed); 40 | # this requires updating the exclude_patterns variable in doc/source/conf.py 41 | #autodoc_exclude_modules = 42 | # {PROJECT}.test.* 43 | # {PROJECT}.{XX}.* 44 | 45 | # Treat sphinx warnings as errors during the docs build; this helps us keep 46 | # the documentation clean. 47 | warnerrors = true 48 | -------------------------------------------------------------------------------- /snippet/example/python/project/setup.py: -------------------------------------------------------------------------------- 1 | import setuptools 2 | setuptools.setup(setup_requires=['pbr>=1.4'], pbr=True) 3 | -------------------------------------------------------------------------------- /snippet/example/python/project/test/test.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | from __future__ import absolute_import, print_function, unicode_literals, division 3 | -------------------------------------------------------------------------------- /snippet/example/python/ratelimit.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | from threading import Thread 4 | from queue import Queue 5 | 6 | 7 | class RateLimiter: 8 | def __init__(self, limit, delay=0.01): 9 | num = int(limit * delay) 10 | if num < 1: 11 | raise ValueError("limit * delay < 1") 12 | 13 | self._limit_num = limit 14 | self._delay = delay 15 | self._num_per_delay = num 16 | self._queue = Queue(limit) 17 | 18 | self._thread = Thread(target=self._start) 19 | self._thread.daemon = True 20 | self._thread.start() 21 | 22 | def _start(self): 23 | total = int(self._limit_num * self._delay) 24 | while True: 25 | diff = total - self._queue.qsize() 26 | while diff > 0: 27 | self._queue.put(None) 28 | diff -= 1 29 | time.sleep(self._delay) 30 | 31 | def get_token(self): 32 | self._queue.get() 33 | self._queue.task_done() 34 | 35 | 36 | if __name__ == "__main__": 37 | num = 100 38 | r = RateLimiter(10, 0.1) 39 | while num: 40 | r.get_token() 41 | print(num) 42 | num -= 1 43 | -------------------------------------------------------------------------------- /snippet/example/python/scrapy/crawler/README: -------------------------------------------------------------------------------- 1 | [USAGE] 2 | $ scrapy crawl image -a site=1seke -a start_urls=XXX -a subdir=YYY 3 | $ scrapy crawl text -a site=1bboo -a start_urls=XXX -a min=30 -a subdir=YYY 4 | see settings.py 5 | -------------------------------------------------------------------------------- /snippet/example/python/scrapy/crawler/crawler/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/example/python/scrapy/crawler/crawler/__init__.py -------------------------------------------------------------------------------- /snippet/example/python/scrapy/crawler/crawler/items.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | from scrapy.item import Item, Field 3 | 4 | 5 | class ImageItem(Item): 6 | group = Field() 7 | image_urls = Field() 8 | images = Field() 9 | 10 | 11 | class TextItem(Item): 12 | title = Field() 13 | texts = Field() 14 | -------------------------------------------------------------------------------- /snippet/example/python/scrapy/crawler/crawler/linkextractors.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | from __future__ import unicode_literals, print_function 3 | 4 | from scrapy.linkextractors import LinkExtractor 5 | from scrapy.link import Link 6 | from scrapy.selector import Selector 7 | 8 | from crawler.utils import URL 9 | # from crawler import settings 10 | 11 | NEXT = ["next", "下一页"] 12 | 13 | 14 | class NextLinkExtractor(LinkExtractor): 15 | def __init__(self, spider, *args, **kwargs): 16 | super(NextLinkExtractor, self).__init__(*args, **kwargs) 17 | self.spider = spider 18 | 19 | @property 20 | def css_selector(self): 21 | return self.spider.css_selector 22 | 23 | def get_css(self, css_name, default=None): 24 | return self.spider.get_css(css_name, default) 25 | 26 | def extract_next_links(self, response): 27 | hxs = Selector(response) 28 | next_css = self.get_css("next_css") 29 | if not next_css: 30 | return [] 31 | 32 | _next = hxs.css(next_css) 33 | for n in _next: 34 | nl = n.xpath('text()').extract()[0].lower() 35 | if nl in NEXT: 36 | url = n.xpath('@href').extract()[0] 37 | return [url] 38 | return [] 39 | 40 | def extract_links(self, response): 41 | hxs = Selector(response) 42 | list_css = self.get_css("list_css") 43 | if not list_css: 44 | return [] 45 | 46 | urls = [] 47 | try: 48 | links = hxs.css(list_css).xpath('@href').extract() 49 | for url in links: 50 | urls.append(url) 51 | next_url = self.extract_next_links(response) 52 | urls.extend(next_url) 53 | except Exception as err: 54 | self.logger.error("%s" % err) 55 | 56 | rtn = [] 57 | for url in urls: 58 | url = URL.s_get_full_url(URL(url), URL(response.url)) 59 | if url: 60 | rtn.append(Link(url=url)) 61 | 62 | return rtn 63 | -------------------------------------------------------------------------------- /snippet/example/python/scrapy/crawler/crawler/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 | -------------------------------------------------------------------------------- /snippet/example/python/scrapy/crawler/crawler/spiders/imagespide.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | from __future__ import unicode_literals, print_function 3 | 4 | from scrapy.selector import Selector 5 | from crawler.items import ImageItem 6 | from crawler.spiders.base import BaseSpider 7 | 8 | 9 | class ImageSpider(BaseSpider): 10 | name = "image" 11 | custom_settings = { 12 | "ITEM_PIPELINES": { 13 | 'crawler.pipelines.ImageGroupPipeline': 2, 14 | } 15 | } 16 | 17 | def handle_page(self, response): 18 | hxs = Selector(response) 19 | image_css = self.get_css("image_css") 20 | group_css = self.get_css("group_css") 21 | if not group_css or not image_css: 22 | return [] 23 | return self.extract_item(hxs, image_css, group_css) 24 | 25 | def extract_item(self, hxs, file_css, group_css): 26 | item = ImageItem() 27 | item["image_urls"] = hxs.css(file_css).xpath('@src').extract() 28 | if not item["image_urls"]: 29 | return [] 30 | 31 | try: 32 | item["group"] = hxs.css(group_css).xpath('text()').extract()[0] 33 | except Exception: 34 | item["group"] = None 35 | 36 | return [item] 37 | -------------------------------------------------------------------------------- /snippet/example/python/scrapy/crawler/crawler/spiders/textspider.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | from __future__ import unicode_literals, print_function 3 | 4 | from scrapy.selector import Selector 5 | from crawler.items import TextItem 6 | from crawler.spiders.base import BaseSpider 7 | 8 | 9 | class TextSpider(BaseSpider): 10 | name = "text" 11 | custom_settings = { 12 | "ITEM_PIPELINES": { 13 | 'crawler.pipelines.TextPipeline': 2, 14 | } 15 | } 16 | 17 | def handle_page(self, response): 18 | hxs = Selector(response) 19 | # text_css = self.css_selector["text_css"] 20 | # title_css = self.css_selector["title_css"] 21 | text_css = self.get_css("text_css") 22 | title_css = self.get_css("title_css") 23 | if not text_css or not title_css: 24 | return [] 25 | item = TextItem() 26 | 27 | try: 28 | item["title"] = hxs.css(title_css).xpath('text()').extract()[0] 29 | except Exception: 30 | return [] 31 | 32 | item["texts"] = hxs.css(text_css).xpath('text()').extract() 33 | if not item["texts"]: 34 | return [] 35 | 36 | return [item] 37 | -------------------------------------------------------------------------------- /snippet/example/python/scrapy/crawler/scrapy.cfg: -------------------------------------------------------------------------------- 1 | # Automatically created by: scrapy startproject 2 | # 3 | # For more information about the [deploy] section see: 4 | # http://doc.scrapy.org/en/latest/topics/scrapyd.html 5 | 6 | [settings] 7 | default = crawler.settings 8 | 9 | [deploy] 10 | #url = http://localhost:6800/ 11 | project = crawler 12 | -------------------------------------------------------------------------------- /snippet/example/python/sqlalchemy-orm-example.py: -------------------------------------------------------------------------------- 1 | # encoding: utf8 2 | from __future__ import print_function 3 | 4 | from sqlalchemy.orm import sessionmaker 5 | from sqlalchemy import create_engine, Column, Integer, String 6 | from sqlalchemy.ext.declarative import declarative_base 7 | 8 | Base = declarative_base() 9 | 10 | 11 | class User(Base): 12 | __tablename__ = 'users' 13 | 14 | id = Column(Integer, primary_key=True) 15 | name = Column(String) 16 | fullname = Column(String) 17 | password = Column(String) 18 | 19 | def __repr__(self): 20 | return "" % (self.name, 21 | self.fullname, self.password) 22 | 23 | 24 | engine = create_engine('sqlite:///:memory:', echo=True) 25 | Base.metadata.create_all(engine) 26 | Session = sessionmaker(bind=engine) 27 | session = Session() 28 | 29 | ed_user = User(name='ed', fullname='Ed Jones', password='edspassword') 30 | session.add(ed_user) 31 | session.add_all([ 32 | User(name='wendy', fullname='Wendy Williams', password='foobar'), 33 | User(name='mary', fullname='Mary Contrary', password='xxg527'), 34 | User(name='fred', fullname='Fred Flinstone', password='blah')]) 35 | session.commit() 36 | 37 | print(session.query(User).offset(1).limit(2).all()) 38 | # SELECT users.id AS users_id, users.name AS users_name, users.fullname AS users_fullname, \ 39 | # users.password AS users_password FROM users LIMIT 2 OFFSET 1 40 | 41 | _User = User 42 | for row in session.query(_User, _User.name).all(): 43 | #print("ROW:", row.User, row.name) 44 | print("ROW:", row[0], row[1]) 45 | 46 | #ed_user.name = "ed2" 47 | #session.commit() 48 | with session.begin(subtransactions=True): 49 | ed_user.name = "ed2" 50 | 51 | session.delete(ed_user) 52 | -------------------------------------------------------------------------------- /snippet/example/python/stevedore.md: -------------------------------------------------------------------------------- 1 | 2 | [Using Stevedore in Your Application](http://docs.openstack.org/developer/stevedore/tutorial/index.html) 3 | ====== 4 | 5 | - [Guidelines for Naming Plugins](http://docs.openstack.org/developer/stevedore/tutorial/naming.html) 6 | - Names and Namespaces 7 | - [Creating Plugins](http://docs.openstack.org/developer/stevedore/tutorial/creating_plugins.html) 8 | - [Loading the Plugins](http://docs.openstack.org/developer/stevedore/tutorial/loading.html) -------------------------------------------------------------------------------- /snippet/example/python/version.py: -------------------------------------------------------------------------------- 1 | import pbr.version 2 | 3 | 4 | def get_version(program_name): 5 | return pbr.version.VersionInfo(program_name).version_string() 6 | -------------------------------------------------------------------------------- /snippet/example/shell/openvpn.sh: -------------------------------------------------------------------------------- 1 | CONFIG_PATH=~/bin/openvpn/config/group 2 | PASSWD_FILE=~/bin/openvpn/pass.txt 3 | NAME=biggeryun 4 | VPN_IP=127.0.0.1 5 | VPN_PORT=1194 6 | 7 | sudo openvpn \ 8 | --client \ 9 | --dev tun \ 10 | --proto tcp \ 11 | --daemon ${NAME} \ 12 | --remote ${VPN_IP} ${VPN_PORT} \ 13 | --resolv-retry infinite \ 14 | --nobind \ 15 | --persist-key \ 16 | --persist-tun \ 17 | --ca ${CONFIG_PATH}/ca.crt \ 18 | --tls-auth ${CONFIG_PATH}/ta.key 1 \ 19 | --auth-user-pass ${PASSWD_FILE} \ 20 | --comp-lzo \ 21 | --verb 5 22 | 23 | ps aux | grep "openvpn" | grep "$NAME" | grep -v "grep" >/dev/null 2>&1 24 | if [ $? -ne 0 ]; then 25 | echo "Failed to connect to openvpn[$NAME]" 26 | else 27 | echo "Connect to openvpn[$NAME] successfully" 28 | fi 29 | -------------------------------------------------------------------------------- /snippet/example/templates/html5.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Your Website 7 | 8 | 9 | 10 |
11 | 16 |
17 | 18 |
19 | 26 | 27 |
28 |
29 |

Article title

30 |

Posted on by Writer - 6 comments

31 |
32 |

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.

33 |
34 |
35 | 36 | 40 | 41 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /snippet/example/templates/sublimetext-sftp-config.json: -------------------------------------------------------------------------------- 1 | { 2 | // The tab key will cycle through the settings when first created 3 | // Visit http://wbond.net/sublime_packages/sftp/settings for help 4 | 5 | // sftp, ftp or ftps 6 | "type": "sftp", 7 | 8 | "save_before_upload": true, 9 | "upload_on_save": true, 10 | "sync_down_on_open": true, 11 | "sync_skip_deletes": false, 12 | "sync_same_age": true, 13 | "confirm_downloads": false, 14 | "confirm_sync": true, 15 | "confirm_overwrite_newer": true, 16 | 17 | //"ssh_key_file": "~/.ssh/id_rsa", 18 | //"sftp_flags": ["-F", "/path/to/ssh_config"], 19 | 20 | //"remote_path": "~", 21 | //"host": "localhost", 22 | "user": "root", 23 | "password": "", 24 | "port": "22", 25 | 26 | "ignore_regexes": [ 27 | "\\.sublime-(project|workspace)", "sftp-config(-alt\\d?)?\\.json", 28 | "sftp-settings\\.json", "/venv/", "\\.svn/", "\\.hg/", "\\.git/", 29 | "\\.bzr", "_darcs", "CVS", "\\.DS_Store", "Thumbs\\.db", "desktop\\.ini", 30 | "\\.pyc", "\\.pyo", "\\.swp", "\\.cproject", "\\.project", "build/", 31 | "\\.o", "\\.egg-info/" 32 | ], 33 | //"file_permissions": "664", 34 | //"dir_permissions": "775", 35 | 36 | //"extra_list_connections": 0, 37 | 38 | "connect_timeout": 30, 39 | //"keepalive": 120, 40 | //"ftp_passive_mode": true, 41 | //"ftp_obey_passive_host": false, 42 | 43 | //"preserve_modification_times": false, 44 | //"remote_time_offset_in_hours": 0, 45 | "remote_encoding": "utf-8", 46 | //"remote_locale": "C", 47 | "allow_config_upload": false, 48 | } 49 | -------------------------------------------------------------------------------- /snippet/libs/c-c++/encode.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | // 代码转换操作类 5 | class CodeConverter { 6 | private: 7 | iconv_t cd; 8 | public: 9 | // 构造 10 | CodeConverter(const char *from_charset,const char *to_charset) { 11 | cd = iconv_open(to_charset,from_charset); 12 | } 13 | 14 | // 析构 15 | ~CodeConverter() { 16 | iconv_close(cd); 17 | } 18 | 19 | // 转换输出 20 | int convert(char *inbuf,int inlen,char *outbuf,int outlen) { 21 | char **pin = &inbuf; 22 | char **pout = &outbuf; 23 | 24 | memset(outbuf,0,outlen); 25 | return iconv(cd,pin,(size_t *)&inlen,pout,(size_t *)&outlen); 26 | } 27 | }; 28 | 29 | /* 30 | #include 31 | #define OUTLEN 255 32 | int main(int argc, char **argv) 33 | { 34 | char *in_utf8 = "中国"; 35 | char *in_gb2312 = "正在安装"; 36 | char out[OUTLEN]; 37 | 38 | // utf-8-->gb2312 39 | CodeConverter cc = CodeConverter("utf-8","gb2312"); 40 | cc.convert(in_utf8,strlen(in_utf8),out,OUTLEN); 41 | cout << "utf-8-->gb2312 in=" << in_utf8 << ",out=" << out << endl; 42 | 43 | // gb2312-->utf-8 44 | CodeConverter cc2 = CodeConverter("gb2312","utf-8"); 45 | cc2.convert(in_gb2312,strlen(in_gb2312),out,OUTLEN); 46 | cout << "gb2312-->utf-8 in=" << in_gb2312 << ",out=" << out << endl; 47 | } 48 | */ 49 | -------------------------------------------------------------------------------- /snippet/libs/c-c++/xlib/xtypes.h: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | #ifndef _X_TYPES_H 5 | #define _X_TYPES_H 6 | 7 | /* 8 | * In order to icreasing the portability, define some following types, macros, 9 | * and functions. Its strategy imitates "GLib", changing "g" to "x". 10 | * Why choose "x"? It's in order to avoid the conflict from other programming 11 | * specification. 12 | */ 13 | 14 | /* define the following data types. */ 15 | /* define the integer type.*/ 16 | typedef int xint; // one machine word. 17 | typedef short int xshort; 18 | typedef unsigned short int xushort; 19 | typedef int xint; 20 | typedef unsigned int xuint; 21 | typedef long int xlong; 22 | typedef unsigned long int xulong; 23 | #ifdef SYSTEM_C99 24 | typedef long long int xlonglong; 25 | typedef unsigned long long int xulonglong; 26 | #endif 27 | /* Define the charactor type. */ 28 | typedef char xchar; 29 | typedef unsigned char xuchar; 30 | typedef signed char xschar; 31 | 32 | typedef float xfloat; 33 | typedef double xdouble; 34 | typedef long double xldouble 35 | 36 | typedef xint xbool; 37 | 38 | typedef void * xpointer; 39 | typedef const void * xconstpointer; 40 | 41 | /* define the macro 'True', 'False'. 42 | * 'True' and 'False' is the two value of the boolean type. 43 | * And you will think that the boolean type has only the two value. 44 | */ 45 | #define False 0 46 | #define True (!(Falsee)) 47 | 48 | /* Define two macros, they represent success and fail. */ 49 | #define ERROR 0 50 | #define OK (!(ERROR)) 51 | 52 | 53 | typedef xint (*XCompareFunc) (xconstpointer a, xconstpointer b); 54 | typedef xbool (*XEqualFunc) (xconstpointer a, xconstpointer b); 55 | typedef void (*XFreeFunc) (xpointer data); 56 | 57 | 58 | #endif /* _X_TYPES_H */ 59 | -------------------------------------------------------------------------------- /snippet/libs/css/cssbase.css: -------------------------------------------------------------------------------- 1 | /* base.css, part of YUI's CSS Foundation */ 2 | h1 { 3 | /*18px via YUI Fonts CSS foundation*/ 4 | font-size:138.5%; 5 | } 6 | h2 { 7 | /*16px via YUI Fonts CSS foundation*/ 8 | font-size:123.1%; 9 | } 10 | h3 { 11 | /*14px via YUI Fonts CSS foundation*/ 12 | font-size:108%; 13 | } 14 | h1,h2,h3 { 15 | /* top & bottom margin based on font size */ 16 | margin:1em 0; 17 | } 18 | h1,h2,h3,h4,h5,h6,strong { 19 | /*bringing boldness back to headers and the strong element*/ 20 | font-weight:bold; 21 | } 22 | abbr,acronym { 23 | /*indicating to users that more info is available */ 24 | border-bottom:1px dotted #000; 25 | cursor:help; 26 | } 27 | em { 28 | /*bringing italics back to the em element*/ 29 | font-style:italic; 30 | } 31 | blockquote,ul,ol,dl { 32 | /*giving blockquotes and lists room to breath*/ 33 | margin:1em; 34 | } 35 | ol,ul,dl { 36 | /*bringing lists on to the page with breathing room */ 37 | margin-left:2em; 38 | } 39 | ol { 40 | /*giving OL's LIs generated numbers*/ 41 | list-style: decimal outside; 42 | } 43 | ul { 44 | /*giving UL's LIs generated disc markers*/ 45 | list-style: disc outside; 46 | } 47 | dd { 48 | /*providing spacing for definition terms*/ 49 | margin-left:1em; 50 | } 51 | th,td { 52 | /*borders and padding to make the table readable*/ 53 | border:1px solid #000; 54 | padding:.5em; 55 | } 56 | th { 57 | /*distinguishing table headers from data cells*/ 58 | font-weight:bold; 59 | text-align:center; 60 | } 61 | caption { 62 | /*coordinated margin to match cell's padding*/ 63 | margin-bottom:.5em; 64 | /*centered so it doesn't blend in to other content*/ 65 | text-align:center; 66 | } 67 | p,fieldset,table,pre { 68 | /*so things don't run into each other*/ 69 | margin-bottom:1em; 70 | } 71 | /* setting a consistent width, 160px; 72 | control of type=file still not possible 73 | *width is for ie7 (no ie6 fallback) */ 74 | input[type=text],input[type=password],textarea{width:12.25em;*width:11.9em;} 75 | -------------------------------------------------------------------------------- /snippet/libs/css/cssreset.css: -------------------------------------------------------------------------------- 1 | /* 2 | TODO will need to remove settings on HTML since we can't namespace it. 3 | TODO with the prefix, should I group by selector or property for weight savings? 4 | */ 5 | html{ 6 | color:#000; 7 | background:#FFF; 8 | } 9 | /* 10 | TODO remove settings on BODY since we can't namespace it. 11 | */ 12 | /* 13 | TODO test putting a class on HEAD. 14 | - Fails on FF. 15 | */ 16 | body, 17 | div, 18 | dl, 19 | dt, 20 | dd, 21 | ul, 22 | ol, 23 | li, 24 | h1, 25 | h2, 26 | h3, 27 | h4, 28 | h5, 29 | h6, 30 | pre, 31 | code, 32 | form, 33 | fieldset, 34 | legend, 35 | input, 36 | textarea, 37 | p, 38 | blockquote, 39 | th, 40 | td { 41 | margin:0; 42 | padding:0; 43 | } 44 | table { 45 | border-collapse:collapse; 46 | border-spacing:0; 47 | } 48 | fieldset, 49 | img { 50 | border:0; 51 | } 52 | /* 53 | TODO think about hanlding inheritence differently, maybe letting IE6 fail a bit... 54 | */ 55 | address, 56 | caption, 57 | cite, 58 | code, 59 | dfn, 60 | em, 61 | strong, 62 | th, 63 | var { 64 | font-style:normal; 65 | font-weight:normal; 66 | } 67 | 68 | ol, 69 | ul { 70 | list-style:none; 71 | } 72 | 73 | caption, 74 | th { 75 | text-align:left; 76 | } 77 | h1, 78 | h2, 79 | h3, 80 | h4, 81 | h5, 82 | h6 { 83 | font-size:100%; 84 | font-weight:normal; 85 | } 86 | q:before, 87 | q:after { 88 | content:''; 89 | } 90 | abbr, 91 | acronym { 92 | border:0; 93 | font-variant:normal; 94 | } 95 | /* to preserve line-height and selector appearance */ 96 | sup { 97 | vertical-align:text-top; 98 | } 99 | sub { 100 | vertical-align:text-bottom; 101 | } 102 | input, 103 | textarea, 104 | select { 105 | font-family:inherit; 106 | font-size:inherit; 107 | font-weight:inherit; 108 | *font-size:100%; /*to enable resizing for IE*/ 109 | } 110 | /*because legend doesn't inherit in IE */ 111 | legend { 112 | color:#000; 113 | } 114 | -------------------------------------------------------------------------------- /snippet/libs/js/cookie.js: -------------------------------------------------------------------------------- 1 | 2 | // $.cookie('username'); //获得cookie 3 | // $.cookie('username', '张三'); //设置cookie 4 | // $.cookie('username', '李四', { expires: 3 }); //设置带时间的cookie 3天 5 | // $.cookie('username', '', { expires: -1 }); //删除cookie 6 | // $.cookie('username', null); //删除 cookie 7 | jQuery.cookie = function (name, value, options) { 8 | if (typeof value != 'undefined') { 9 | options = options || {}; 10 | if (value === null) { 11 | value = ''; 12 | options.expires = -1; 13 | } 14 | var expires = ''; 15 | if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) { 16 | var date; 17 | if (typeof options.expires == 'number') { 18 | date = new Date(); 19 | date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000)); 20 | } else { 21 | date = options.expires; 22 | } 23 | expires = ';expires=' + date.toUTCString(); 24 | } 25 | var path = options.path ? ';path=' + options.path : ''; 26 | var domain = options.domain ? ';domain=' + options.domain : ''; 27 | var secure = options.secure ? ';secure' : ''; 28 | document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join(''); 29 | } else { 30 | var cookieValue = null; 31 | if (document.cookie && document.cookie != '') { 32 | var cookies = document.cookie.split(';'); 33 | for (var i = 0; i < cookies.length; i++) { 34 | var cookie = jQuery.trim(cookies[i]); 35 | if (cookie.substring(0, name.length + 1) == (name + '=')) { 36 | cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); 37 | break; 38 | } 39 | } 40 | } 41 | return cookieValue; 42 | } 43 | }; -------------------------------------------------------------------------------- /snippet/libs/js/loadjs.js: -------------------------------------------------------------------------------- 1 | // Load the JS dependencies Asynchronously, then call the callback. 2 | // 3 | // For example, 4 | // 5 | // getScripts(['http://example.com/js1.js', 'http://example.com/js2.js'], function () { 6 | // alert('Finish to load all the dependencies.'); 7 | // }); 8 | function getScripts(dependencies, callback) { 9 | 'use strict'; 10 | 11 | function _getScripts(i, linkArray, fn) { 12 | env || getEnv(); 13 | var script = document.createElement('script'); 14 | script.type = 'text/javascript'; 15 | script.src = linkArray[i]; 16 | var head = document.head || document.getElementsByTagName('head')[0]; 17 | head.appendChild(script); 18 | 19 | if ('onload' in script) { 20 | script.onload = function () { 21 | if (i === linkArray.length - 1) { 22 | if (fn) { 23 | fn(); 24 | } 25 | } else { 26 | _getScripts(++i, linkArray, fn); 27 | } 28 | }; 29 | } else { // For IE. 30 | script.onreadystatechange = function () { 31 | if (/loaded|complete/.test(script.readyState)) { 32 | script.onreadystatechange = null; 33 | if (i === linkArray.length - 1) { 34 | if (fn) { 35 | fn(); 36 | } 37 | } else { 38 | _getScripts(++i, linkArray, fn); 39 | } 40 | } 41 | }; 42 | } 43 | } 44 | 45 | _getScripts(0, dependencies, callback); 46 | } 47 | -------------------------------------------------------------------------------- /snippet/libs/linux/init.d-service-example: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # chkconfig: - 98 02 4 | 5 | . /etc/rc.d/init.d/functions 6 | 7 | PROGRAM=XXX 8 | 9 | suffix=$PROGRAM 10 | prog=$suffix 11 | exec="/usr/bin/$PROGRAM" 12 | pidfile="/var/run/$PROGRAM/$suffix.pid" 13 | logfile="/var/log/$PROGRAM/$suffix.log" 14 | 15 | [ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog 16 | 17 | lockfile=/var/lock/subsys/$prog 18 | 19 | start() { 20 | echo -n $"Starting $prog: " 21 | daemon --user root --pidfile $pidfile "python $exec &>$logfile & echo \$! > $pidfile" 22 | retval=$? 23 | echo 24 | [ $retval -eq 0 ] && touch $lockfile 25 | return $retval 26 | } 27 | 28 | stop() { 29 | echo -n $"Stopping $prog: " 30 | killproc -p $pidfile $prog 31 | retval=$? 32 | echo 33 | [ $retval -eq 0 ] && rm -f $lockfile 34 | return $retval 35 | } 36 | 37 | restart() { 38 | stop 39 | start 40 | } 41 | 42 | reload() { 43 | restart 44 | } 45 | 46 | force_reload() { 47 | restart 48 | } 49 | 50 | rh_status() { 51 | status -p $pidfile $prog 52 | } 53 | 54 | rh_status_q() { 55 | rh_status >/dev/null 2>&1 56 | } 57 | 58 | 59 | case "$1" in 60 | start) 61 | rh_status_q && exit 0 62 | $1 63 | ;; 64 | stop) 65 | rh_status_q || exit 0 66 | $1 67 | ;; 68 | restart) 69 | $1 70 | ;; 71 | reload) 72 | rh_status_q || exit 7 73 | $1 74 | ;; 75 | force-reload) 76 | force_reload 77 | ;; 78 | status) 79 | rh_status 80 | ;; 81 | condrestart|try-restart) 82 | rh_status_q || exit 0 83 | restart 84 | ;; 85 | *) 86 | echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}" 87 | exit 2 88 | esac 89 | exit $? 90 | -------------------------------------------------------------------------------- /snippet/software/symbol-fonts_1.2_all.deb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgfone/snippet/b0b734dd35478b7ef3e6193623981f4f29b6748c/snippet/software/symbol-fonts_1.2_all.deb --------------------------------------------------------------------------------