├── sdn
├── __init__.py
├── myovsdb
│ ├── __init__.py
│ ├── ovs_api.py
│ └── ovsdb_client.py
├── ryu-cuc
│ ├── __init__.py
│ ├── pep8.log
│ ├── book
│ │ └── __init__.py
│ ├── docs
│ │ └── __init__.py
│ ├── tests
│ │ ├── __init__.py
│ │ └── unit
│ │ │ ├── __init__.py
│ │ │ ├── packet
│ │ │ └── __init__.py
│ │ │ ├── sample
│ │ │ ├── __init__.py
│ │ │ ├── test_sample2.py
│ │ │ └── test_sample1.py
│ │ │ └── controller
│ │ │ └── __init__.py
│ └── run_tests.log
├── mininet-cuc
│ ├── __init__.py
│ └── CHANGELOG
├── mininet-tests
│ ├── lib
│ │ └── __init__.py
│ ├── cpuiso
│ │ ├── __init__.py
│ │ └── cpu
│ │ │ ├── Makefile
│ │ │ ├── run.sh
│ │ │ ├── gettimeofday.c
│ │ │ └── test_cpu.py
│ ├── pairs
│ │ ├── __init__.py
│ │ ├── Makefile
│ │ ├── pair_intervals_links_debug.sh
│ │ ├── pair_intervals_switches.sh
│ │ ├── pair_intervals_links.sh
│ │ └── README.md
│ ├── util
│ │ ├── __init__.py
│ │ └── .gitignore
│ ├── parkinglot
│ │ ├── __init__.py
│ │ └── README.md
│ ├── buffersizing
│ │ ├── .gitignore
│ │ ├── __init__.py
│ │ ├── gengraph 2.sh
│ │ ├── build-patched-iperf.sh
│ │ ├── README.md
│ │ ├── iperf-2.0.5-wait-syn.patch
│ │ └── README.iperf
│ ├── buffersizing-red
│ │ ├── .gitignore
│ │ ├── __init__.py
│ │ ├── gen.sh
│ │ ├── build-patched-iperf.sh
│ │ ├── iperf-2.0.5-wait-syn.patch
│ │ └── README.iperf
│ ├── udping
│ │ ├── plot_udpong.sh
│ │ ├── plot_udpong_box.sh
│ │ ├── Makefile
│ │ ├── README.md
│ │ └── run_udpong.sh
│ ├── README.md
│ └── dasdn
│ │ └── README.md
├── akaedu
│ ├── ch10
│ │ ├── ex10.4.segm_fault.c
│ │ ├── ex10.reverse.c
│ │ ├── ex10.5.segm_fault2.c
│ │ ├── ex10.3.watch.c
│ │ ├── Makefile
│ │ └── ex10.2.break.c
│ ├── ch28
│ │ ├── ex28.2.blocking.c
│ │ └── Makefile
│ ├── ch25
│ │ ├── Makefile
│ │ └── ex25.2.strok.c
│ ├── ch08
│ │ ├── Makefile
│ │ └── ex08.5.game.c
│ ├── utils
│ │ └── Makefile
│ ├── README.md
│ └── ch37
│ │ ├── wrap.h
│ │ ├── README.md
│ │ └── ex37.unix.bind.c
├── cs144_bufferbloat
│ ├── iperf.sh
│ ├── show_figure.sh
│ ├── bufferbloat_setup.sh
│ ├── monitor.sh
│ ├── http
│ │ └── webserver.py
│ ├── run-minq.sh
│ ├── run.sh
│ ├── run-diff.sh
│ └── tc_cmd.sh
├── .gitignore
├── tests
│ └── test_ovsdb.py
├── README.md
├── bin
│ └── openvswitch-switch.rc
├── ipc-bench-master
│ └── Makefile
└── linux-header
│ └── int-l64.h
├── .idea
├── .name
├── encodings.xml
└── vcs.xml
├── yun_sdk
└── baidu
│ ├── TTS
│ └── __init__.py
│ ├── config.example.py
│ ├── ASR
│ └── test.wav
│ ├── demo_tts.py
│ └── README.md
├── stdmod
├── unittest
│ ├── test_mylib
│ │ ├── __init__.py
│ │ ├── sub
│ │ │ ├── __init__.py
│ │ │ └── test_string.py
│ │ ├── mainsuit.py
│ │ └── test_rm_nomock.py
│ └── mylib
│ │ ├── __init__.py
│ │ ├── rm_module.py
│ │ ├── req_module.py
│ │ ├── widget.py
│ │ └── primes.py
└── math
│ └── docs_math.py
├── web_framework
├── mydjango
│ ├── dingding
│ │ └── __init__.py
│ ├── learn
│ │ ├── __init__.py
│ │ ├── migrations
│ │ │ ├── __init__.py
│ │ │ ├── 0001_initial.py
│ │ │ ├── 0003_student.py
│ │ │ └── 0002_article.py
│ │ ├── templates
│ │ │ ├── ad.html
│ │ │ ├── nav.html
│ │ │ ├── bottom.html
│ │ │ ├── step06a.html
│ │ │ ├── home.html
│ │ │ ├── step06b.html
│ │ │ ├── step06c.html
│ │ │ ├── base_extend.html
│ │ │ ├── base.html
│ │ │ ├── step09.html
│ │ │ └── step06d.html
│ │ ├── tests.py
│ │ ├── static
│ │ │ └── screen.png
│ │ └── forms.py
│ ├── mydjango
│ │ ├── __init__.py
│ │ └── wsgi.py
│ ├── demoapp
│ │ ├── migrations
│ │ │ ├── __init__.py
│ │ │ ├── 0009_question_checked.py
│ │ │ ├── 0006_auto_20150727_1250.py
│ │ │ ├── 0017_auto_20151209_0529.py
│ │ │ ├── 0007_post_tags.py
│ │ │ ├── 0008_auto_20150727_1253.py
│ │ │ ├── 0011_auto_20150806_1248.py
│ │ │ ├── 0019_auto_20151216_1514.py
│ │ │ ├── 0012_auto_20150806_1331.py
│ │ │ └── 0015_auto_20150819_0238.py
│ │ ├── __init__.py
│ │ └── templates
│ │ │ └── d01_first_steps
│ │ │ ├── base.html
│ │ │ ├── polls_results.html
│ │ │ ├── polls_index.html
│ │ │ ├── year_archive.html
│ │ │ └── polls_detail.html
│ ├── db.sqlite3
│ ├── manage.py
│ ├── templates
│ │ └── admin
│ │ │ └── base_site.orig.html
│ ├── requirements.txt
│ └── cucMsg
│ │ └── user.py
├── web_py_templates
│ └── index.html
└── web_py_examples.py
├── douban_kdd
├── .python-version
├── README.md
└── douban_ipython.py
├── ns2
├── otcl
│ ├── class_info.tcl
│ ├── wiki_string.tcl
│ ├── class_info.sh
│ └── README.md
├── tutorial
│ └── output
│ │ └── README.md
├── tcpsuit
│ ├── analysis
│ │ ├── mixed_protocol
│ │ ├── graph_protocol
│ │ ├── extract_data
│ │ ├── process_protocol
│ │ ├── process_protocol.bkp
│ │ ├── count_flows.sh
│ │ ├── test.tcl
│ │ ├── processdata
│ │ ├── link_graph.gpl
│ │ └── process_ef.pl
│ ├── README.md
│ ├── README
│ ├── topology_generator
│ │ ├── process_graph.sh
│ │ ├── execute.sh
│ │ └── execute2.sh
│ └── experiment_executor
│ │ └── scenarios.sh
├── course-for-beginners
│ ├── toolbox
│ │ ├── avr.awk
│ │ ├── stdv.awk
│ │ └── rv1.tcl
│ ├── ch01-basic-tcl.tcl
│ └── ch02-random.tcl
├── ns-2.35
│ └── README.md
├── ns_by_example
│ ├── jitter.sh
│ ├── post01_trace2jitter.sh
│ ├── ex-linkage.tcl
│ ├── basic01_ex-tcl.tcl
│ ├── dtrr-queue.h
│ └── basic02_ex-otcl.tcl
├── my
│ └── README.md
├── dctcp-sigcomm10
│ ├── Makefile.orig
│ └── index.html
├── dctcp
│ └── dctcp.patch-README
├── cuc-buffer
│ └── verify
│ │ └── run-flows-vs-link.sh
└── caltech-ns2tcplinux
│ ├── tutorial
│ ├── linux.tcl
│ └── sack1.tcl
│ └── script-gnuplot.txt
├── lecture
├── bit_program_design
│ ├── .python-version
│ ├── pil.png
│ ├── 04TextProBarV2.py
│ ├── README.md
│ ├── 12test.txt
│ ├── 01TempConvert.py
│ ├── 04TextProBarV1.py
│ ├── 04TextProBarV3.py
│ ├── 08KochDrawV1.py
│ ├── 08KochDrawV2.py
│ ├── 10CalHamletV1.py
│ ├── 05CalBMI.py
│ ├── 12GovRptWordCloudv1.py
│ ├── 06CalPi.py
│ ├── 10CalThreeKingdomsV1.py
│ ├── 10CalThreeKingdomsV2.py
│ ├── 09CalStatisticsV1.py
│ └── 15HollandRadarDraw2Plotly.py
├── nju_data_intro
│ ├── 5.8.tushare.py
│ └── df_plot.py
└── guess_num.py
├── ns3
├── cplusplus.com
│ ├── example.txt
│ ├── example.bin
│ ├── ch02_program_structure.cpp
│ ├── ch05_default_delete.cpp
│ └── ch04_chars.cpp
├── practical_csocket2
│ ├── Framer.h
│ ├── VoteEncoding.h
│ ├── survey1.txt
│ ├── VoteProtocol.h
│ ├── DieWithMessage.c
│ ├── README.md
│ ├── AdminClient2.cpp
│ ├── TCPEchoServer.c
│ └── TestSizes.c
├── misc
│ ├── test_std_clang.cc
│ └── non-POD-array.cc
└── scratch
│ └── cfi16-plot-fig2-drop-packets.py
├── pygame
├── audio
│ ├── shake.wav
│ └── friendship.mp3
├── pygame_demo_audio.py
└── README.md
├── scikit
└── main
│ └── clf_model.pkl
├── EduLogging
├── lesson1
│ ├── task3
│ │ ├── levels.pyc
│ │ ├── levels_answers1_window.pyc
│ │ └── tests.py
│ ├── task4
│ │ ├── loggers.pyc
│ │ ├── tests.py
│ │ └── task.html
│ ├── task2
│ │ ├── log_output.pyc
│ │ ├── tests.py
│ │ ├── log_output.py
│ │ └── task.html
│ ├── task1
│ │ ├── replacing_print.pyc
│ │ ├── tests.py
│ │ ├── task.html
│ │ └── replacing_print.py
│ ├── task7
│ │ ├── special_levels.pyc
│ │ ├── tests.py
│ │ └── task.html
│ ├── task5
│ │ ├── multiple_loggers.pyc
│ │ └── tests.py
│ ├── task8
│ │ ├── selective_logging.pyc
│ │ ├── selective_logging_answers0_window.pyc
│ │ ├── tests.py
│ │ └── task.html
│ └── task6
│ │ ├── task.html
│ │ └── tests.py
├── lesson2
│ ├── task5
│ │ ├── log_objects.pyc
│ │ ├── task.html
│ │ ├── tests.py
│ │ └── log_objects.py
│ ├── task6
│ │ ├── limit_output.pyc
│ │ ├── tests.py
│ │ ├── limit_output.py
│ │ └── task.html
│ ├── task2
│ │ ├── custom_datetime.pyc
│ │ └── tests.py
│ ├── task3
│ │ ├── log_attributes.pyc
│ │ └── tests.py
│ ├── task4
│ │ ├── log_exception.pyc
│ │ ├── tests.py
│ │ └── task.html
│ ├── task1
│ │ ├── custom_format_string.pyc
│ │ ├── task.html
│ │ └── tests.py
│ └── task7
│ │ ├── string_formatting.py
│ │ ├── tests.py
│ │ └── task.html
├── lesson8
│ ├── task1
│ │ ├── logger_naming.pyc
│ │ ├── tests.py
│ │ └── task.html
│ ├── task7
│ │ ├── context.py
│ │ └── tests.py
│ ├── task3
│ │ ├── conditional_logging.py
│ │ ├── tests.py
│ │ └── task.html
│ ├── task4
│ │ ├── tests.py
│ │ ├── task.html
│ │ └── library_logging.py
│ ├── task6
│ │ ├── task.html
│ │ ├── tests.py
│ │ └── logging_decorator.py
│ ├── task2
│ │ ├── tests.py
│ │ ├── task.html
│ │ └── private_logger.py
│ └── task5
│ │ ├── task.html
│ │ ├── tests.py
│ │ └── right_levels.py
├── lesson6
│ ├── task7
│ │ ├── task.html
│ │ ├── tests.py
│ │ └── dict_config_root.py
│ ├── task3
│ │ ├── task.html
│ │ ├── tests.py
│ │ └── file_config_loggers.py
│ ├── task2
│ │ ├── tests.py
│ │ ├── task.html
│ │ └── file_config_handlers.py
│ ├── task5
│ │ └── tests.py
│ ├── task1
│ │ ├── tests.py
│ │ └── file_config_formatters.py
│ ├── task4
│ │ ├── tests.py
│ │ └── task.html
│ └── task6
│ │ ├── tests.py
│ │ └── task.html
├── README.md
├── lesson5
│ ├── task4
│ │ ├── task.html
│ │ ├── tests.py
│ │ └── null_handler.py
│ ├── task3
│ │ ├── tests.py
│ │ └── propagate1.py
│ ├── task5
│ │ ├── tests.py
│ │ ├── task.html
│ │ └── filtering_handler.py
│ ├── task1
│ │ ├── tests.py
│ │ └── filter.py
│ └── task2
│ │ └── tests.py
├── lesson7
│ ├── task3
│ │ ├── tests.py
│ │ └── task.html
│ ├── task4
│ │ └── tests.py
│ ├── task1
│ │ ├── tests.py
│ │ └── task.html
│ └── task2
│ │ └── tests.py
├── lesson4
│ ├── task3
│ │ ├── tests.py
│ │ └── task.html
│ ├── task5
│ │ ├── tests.py
│ │ └── task.html
│ ├── task4
│ │ └── tests.py
│ ├── task1
│ │ └── tests.py
│ ├── task2
│ │ └── tests.py
│ └── task6
│ │ ├── tests.py
│ │ ├── task.html
│ │ └── remove_handler.py
├── Sandbox
│ ├── basic_file.log
│ ├── separate_levels.log
│ └── file_handler_with_formatter.log
└── lesson3
│ ├── task6
│ ├── tests.py
│ └── task.html
│ ├── task1
│ └── tests.py
│ ├── task2
│ ├── tests.py
│ └── task.html
│ ├── task4
│ ├── tests.py
│ └── task.html
│ ├── task5
│ ├── tests.py
│ └── task.html
│ └── task3
│ ├── tests.py
│ └── task.html
├── turtle
├── drag.py
├── star.py
├── hexagon.py
├── draw-sin.py
├── random-stamps.py
└── interact.py
├── bin
└── collect_my_codes.sh
├── pythonchallenge
├── 01.py
├── README.md
├── mylib.py
└── 05.py
├── ml
└── README.md
└── gurobi
└── examples-python
└── interact-open-pit-mining.py
/sdn/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/sdn/myovsdb/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/sdn/ryu-cuc/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/sdn/ryu-cuc/pep8.log:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | ArsenalPython
--------------------------------------------------------------------------------
/sdn/mininet-cuc/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/sdn/ryu-cuc/book/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/sdn/ryu-cuc/docs/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/sdn/mininet-tests/lib/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/sdn/ryu-cuc/tests/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/yun_sdk/baidu/TTS/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/sdn/mininet-tests/cpuiso/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/sdn/mininet-tests/pairs/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/sdn/mininet-tests/util/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/sdn/ryu-cuc/tests/unit/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/stdmod/unittest/test_mylib/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/sdn/mininet-tests/parkinglot/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/sdn/mininet-tests/util/.gitignore:
--------------------------------------------------------------------------------
1 | *.pyc
2 |
--------------------------------------------------------------------------------
/sdn/ryu-cuc/tests/unit/packet/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/sdn/ryu-cuc/tests/unit/sample/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/stdmod/unittest/test_mylib/sub/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/web_framework/mydjango/dingding/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/web_framework/mydjango/learn/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/web_framework/mydjango/mydjango/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/douban_kdd/.python-version:
--------------------------------------------------------------------------------
1 | anaconda2-4.3.1
2 |
--------------------------------------------------------------------------------
/sdn/ryu-cuc/tests/unit/controller/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/web_framework/mydjango/demoapp/migrations/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/web_framework/mydjango/learn/migrations/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/ns2/otcl/class_info.tcl:
--------------------------------------------------------------------------------
1 | puts [Class info instances]
2 |
--------------------------------------------------------------------------------
/ns2/tutorial/output/README.md:
--------------------------------------------------------------------------------
1 | temp ns traces file here
2 |
--------------------------------------------------------------------------------
/stdmod/unittest/mylib/__init__.py:
--------------------------------------------------------------------------------
1 | __version__ = (1, 2)
2 |
--------------------------------------------------------------------------------
/lecture/bit_program_design/.python-version:
--------------------------------------------------------------------------------
1 | anaconda3-4.3.1
2 |
--------------------------------------------------------------------------------
/ns3/cplusplus.com/example.txt:
--------------------------------------------------------------------------------
1 | Writing this to a file 11.
2 |
--------------------------------------------------------------------------------
/web_framework/mydjango/demoapp/__init__.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
--------------------------------------------------------------------------------
/web_framework/mydjango/learn/templates/ad.html:
--------------------------------------------------------------------------------
1 |
简单的广告页面 ad.html
--------------------------------------------------------------------------------
/web_framework/mydjango/learn/templates/nav.html:
--------------------------------------------------------------------------------
1 | 简单导航条(nav.html)
--------------------------------------------------------------------------------
/ns3/cplusplus.com/example.bin:
--------------------------------------------------------------------------------
1 | Writing this to a file (binary testing).
2 |
--------------------------------------------------------------------------------
/web_framework/mydjango/learn/templates/bottom.html:
--------------------------------------------------------------------------------
1 | 简单的bottom 底栏内容
--------------------------------------------------------------------------------
/web_framework/mydjango/learn/templates/step06a.html:
--------------------------------------------------------------------------------
1 |
2 | 这里显示的是一个字符串变量 {{ myVar }}
--------------------------------------------------------------------------------
/yun_sdk/baidu/config.example.py:
--------------------------------------------------------------------------------
1 | YOUR_APP_KEY='XXXXXXXXXXXX'
2 | YOUR_SECRET_KEY='XXXXXXXXX'
3 |
--------------------------------------------------------------------------------
/sdn/mininet-tests/buffersizing/.gitignore:
--------------------------------------------------------------------------------
1 | #临时 ignore 一些文件
2 | result-buffersizing-*
3 | verify/
4 |
--------------------------------------------------------------------------------
/sdn/myovsdb/ovs_api.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | # --*-- coding:utf-8 --*--
3 |
4 |
5 | import ovs
6 |
--------------------------------------------------------------------------------
/ns2/tcpsuit/analysis/mixed_protocol:
--------------------------------------------------------------------------------
1 | compoundreno
2 | cubicreno
3 | htcpreno
4 | wwarreno
5 | arenoreno
6 |
--------------------------------------------------------------------------------
/pygame/audio/shake.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thevibepei/ArsenalPython/HEAD/pygame/audio/shake.wav
--------------------------------------------------------------------------------
/ns2/course-for-beginners/toolbox/avr.awk:
--------------------------------------------------------------------------------
1 | BEGIN { FS = " "} { nl++ } { s=s+$1} END {print "average:" s/nl}
2 |
--------------------------------------------------------------------------------
/scikit/main/clf_model.pkl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thevibepei/ArsenalPython/HEAD/scikit/main/clf_model.pkl
--------------------------------------------------------------------------------
/sdn/mininet-tests/buffersizing-red/.gitignore:
--------------------------------------------------------------------------------
1 | #临时 ignore 一些文件
2 | result-buffersizing-*
3 | red-*/
4 | red-*.png
--------------------------------------------------------------------------------
/web_framework/mydjango/learn/tests.py:
--------------------------------------------------------------------------------
1 | from django.test import TestCase
2 |
3 | # Create your tests here.
4 |
--------------------------------------------------------------------------------
/yun_sdk/baidu/ASR/test.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thevibepei/ArsenalPython/HEAD/yun_sdk/baidu/ASR/test.wav
--------------------------------------------------------------------------------
/pygame/audio/friendship.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thevibepei/ArsenalPython/HEAD/pygame/audio/friendship.mp3
--------------------------------------------------------------------------------
/ns2/course-for-beginners/toolbox/stdv.awk:
--------------------------------------------------------------------------------
1 | BEGIN {FS=" "}{ln++}{d=$1-t}{s2=s2+d*d} END {print "standev:" sqrt(s2/ln)}
2 |
--------------------------------------------------------------------------------
/lecture/bit_program_design/pil.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thevibepei/ArsenalPython/HEAD/lecture/bit_program_design/pil.png
--------------------------------------------------------------------------------
/web_framework/mydjango/db.sqlite3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thevibepei/ArsenalPython/HEAD/web_framework/mydjango/db.sqlite3
--------------------------------------------------------------------------------
/EduLogging/lesson1/task3/levels.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thevibepei/ArsenalPython/HEAD/EduLogging/lesson1/task3/levels.pyc
--------------------------------------------------------------------------------
/EduLogging/lesson1/task4/loggers.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thevibepei/ArsenalPython/HEAD/EduLogging/lesson1/task4/loggers.pyc
--------------------------------------------------------------------------------
/EduLogging/lesson1/task2/log_output.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thevibepei/ArsenalPython/HEAD/EduLogging/lesson1/task2/log_output.pyc
--------------------------------------------------------------------------------
/EduLogging/lesson2/task5/log_objects.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thevibepei/ArsenalPython/HEAD/EduLogging/lesson2/task5/log_objects.pyc
--------------------------------------------------------------------------------
/EduLogging/lesson2/task6/limit_output.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thevibepei/ArsenalPython/HEAD/EduLogging/lesson2/task6/limit_output.pyc
--------------------------------------------------------------------------------
/sdn/mininet-cuc/CHANGELOG:
--------------------------------------------------------------------------------
1 | 2016-08-31
2 | 支持 ecn 测试计算平均值. 考虑每次测试的时候结果并不稳定, 以平均值计算会更为清楚
3 |
4 | TODO 如何计算 发出的 tcp-ece-flag 包的数量, 以及对带宽\延时的影响
--------------------------------------------------------------------------------
/EduLogging/lesson1/task1/replacing_print.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thevibepei/ArsenalPython/HEAD/EduLogging/lesson1/task1/replacing_print.pyc
--------------------------------------------------------------------------------
/EduLogging/lesson1/task7/special_levels.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thevibepei/ArsenalPython/HEAD/EduLogging/lesson1/task7/special_levels.pyc
--------------------------------------------------------------------------------
/EduLogging/lesson2/task2/custom_datetime.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thevibepei/ArsenalPython/HEAD/EduLogging/lesson2/task2/custom_datetime.pyc
--------------------------------------------------------------------------------
/EduLogging/lesson2/task3/log_attributes.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thevibepei/ArsenalPython/HEAD/EduLogging/lesson2/task3/log_attributes.pyc
--------------------------------------------------------------------------------
/EduLogging/lesson2/task4/log_exception.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thevibepei/ArsenalPython/HEAD/EduLogging/lesson2/task4/log_exception.pyc
--------------------------------------------------------------------------------
/EduLogging/lesson8/task1/logger_naming.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thevibepei/ArsenalPython/HEAD/EduLogging/lesson8/task1/logger_naming.pyc
--------------------------------------------------------------------------------
/EduLogging/lesson1/task5/multiple_loggers.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thevibepei/ArsenalPython/HEAD/EduLogging/lesson1/task5/multiple_loggers.pyc
--------------------------------------------------------------------------------
/EduLogging/lesson1/task8/selective_logging.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thevibepei/ArsenalPython/HEAD/EduLogging/lesson1/task8/selective_logging.pyc
--------------------------------------------------------------------------------
/ns3/practical_csocket2/Framer.h:
--------------------------------------------------------------------------------
1 | int GetNextMsg(FILE *in, uint8_t *buf, size_t bufSize);
2 | int PutMsg(uint8_t buf[], size_t msgSize, FILE *out);
3 |
--------------------------------------------------------------------------------
/sdn/akaedu/ch10/ex10.4.segm_fault.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(void)
4 | {
5 | int man = 0;
6 | scanf("%d", man); //错误地址
7 | return 0;
8 | }
--------------------------------------------------------------------------------
/web_framework/mydjango/learn/static/screen.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thevibepei/ArsenalPython/HEAD/web_framework/mydjango/learn/static/screen.png
--------------------------------------------------------------------------------
/EduLogging/lesson2/task1/custom_format_string.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thevibepei/ArsenalPython/HEAD/EduLogging/lesson2/task1/custom_format_string.pyc
--------------------------------------------------------------------------------
/EduLogging/lesson1/task3/levels_answers1_window.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thevibepei/ArsenalPython/HEAD/EduLogging/lesson1/task3/levels_answers1_window.pyc
--------------------------------------------------------------------------------
/sdn/cs144_bufferbloat/iperf.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #qsize=$1
3 | iperf -c 10.0.0.2 -p 5001 -t 3600 -i 1 -w 16m -Z reno > iperf.txt &
4 | echo started iperf
5 |
6 |
--------------------------------------------------------------------------------
/sdn/cs144_bufferbloat/show_figure.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | echo "Use http://localhost:8888/queue.png to see the figure on your browser"
3 | python -m SimpleHTTPServer 8888
4 |
--------------------------------------------------------------------------------
/web_framework/mydjango/learn/forms.py:
--------------------------------------------------------------------------------
1 | from django import forms
2 |
3 | class AddForm(forms.Form):
4 | a = forms.IntegerField()
5 | b = forms.IntegerField()
6 |
--------------------------------------------------------------------------------
/ns2/ns-2.35/README.md:
--------------------------------------------------------------------------------
1 |
2 | 复制 ns-2.35 的一些代码
3 |
4 | ## 运行例子
5 | ```
6 | cd output
7 | ns ../ex/jobs-cn2002.tcl
8 | ```
9 |
10 | ## 代码说明
11 | * `ex/jobs-cn2002.tcl` 显示链路带宽利用率
--------------------------------------------------------------------------------
/sdn/ryu-cuc/run_tests.log:
--------------------------------------------------------------------------------
1 | Traceback (most recent call last):
2 | File "./tests/run_tests_cuc.py", line 15, in
3 | import cuc
4 | ImportError: No module named cuc
5 |
--------------------------------------------------------------------------------
/EduLogging/lesson1/task8/selective_logging_answers0_window.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thevibepei/ArsenalPython/HEAD/EduLogging/lesson1/task8/selective_logging_answers0_window.pyc
--------------------------------------------------------------------------------
/lecture/nju_data_intro/5.8.tushare.py:
--------------------------------------------------------------------------------
1 | import matplotlib.pyplot as plt
2 | import tushare as ts
3 | df = ts.get_h_data('600848', start='2018-01-01', end='2018-06-30')
4 | plt.show()
5 |
--------------------------------------------------------------------------------
/turtle/drag.py:
--------------------------------------------------------------------------------
1 | # TODO 操作不是很稳定;
2 |
3 | from turtle import *
4 |
5 | ts = Screen(); tu = Turtle()
6 | ts.listen()
7 | # onmouseclick(goto)
8 | ondrag(tu.goto)
9 | mainloop()
10 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/bin/collect_my_codes.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | #ryu codes
4 | cd ~/PycharmProjects/ryu
5 | git branch zhchen #切换至 zhchen 分支
6 | rsync -avv ./cuc/ ~/PycharmProjects/ArsenalPython/sdn/ryu-cuc
7 |
8 |
--------------------------------------------------------------------------------
/EduLogging/lesson6/task7/task.html:
--------------------------------------------------------------------------------
1 |
2 | There is a shortcut for defining the root logger. Instead of having an empty string key ''
3 | under the loggers key, you can create a top-level key called "root".
4 |
--------------------------------------------------------------------------------
/ns2/tcpsuit/analysis/graph_protocol:
--------------------------------------------------------------------------------
1 | renoreno
2 | compoundcompound
3 | compoundreno
4 | cubiccubic
5 | cubicreno
6 | htcphtcp
7 | htcpreno
8 | wwarwwar
9 | wwarreno
10 | arenoareno
11 | arenoreno
12 |
--------------------------------------------------------------------------------
/sdn/mininet-tests/udping/plot_udpong.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # 绘制 bar 图
4 |
5 | NODES='2,5,10,20,40,60,80,100'
6 | HOST=`hostname`
7 |
8 | ./plot_udpong.py -c $NODES results/$HOST/udping-{cfs,none}/
9 |
--------------------------------------------------------------------------------
/sdn/mininet-tests/udping/plot_udpong_box.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # 绘制 bar 图
3 |
4 | NODES='2,5,10,20,40,60,80,100'
5 | HOST=`hostname`
6 |
7 | ./plot_udpong.py -b -c $NODES results/$HOST/udping-{cfs,none}/
8 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/ns2/tcpsuit/analysis/extract_data:
--------------------------------------------------------------------------------
1 | ls *.tar.gz > dir
2 | sed "s/^/tar xzf /" dir > dir2
3 | sh ./dir2
4 | mkdir data
5 | sed "s/\.tar\.gz//" dir | sed "s/^/mv /" | sed "s/$/\/data\/* data/" > dir3
6 | sh ./dir3
7 |
--------------------------------------------------------------------------------
/ns2/tcpsuit/analysis/process_protocol:
--------------------------------------------------------------------------------
1 | renoreno
2 | compoundcompound
3 | compoundreno
4 | cubiccubic
5 | cubicreno
6 | htcphtcp
7 | htcpreno
8 | wwarwwar
9 | wwarreno
10 | arenoareno
11 | arenoreno
12 |
--------------------------------------------------------------------------------
/sdn/mininet-tests/buffersizing/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | Buffersizing experiment.
3 | Please refer to http://reproducingnetworkresearch.wordpress.com/2012/06/01/sizing-router-buffers/
4 | for more details.
5 | """
6 |
--------------------------------------------------------------------------------
/ns2/tcpsuit/analysis/process_protocol.bkp:
--------------------------------------------------------------------------------
1 | renoreno
2 | compoundcompound
3 | compoundreno
4 | cubiccubic
5 | cubicreno
6 | htcphtcp
7 | htcpreno
8 | wwarwwar
9 | wwarreno
10 | arenoareno
11 | arenoreno
12 |
--------------------------------------------------------------------------------
/sdn/cs144_bufferbloat/bufferbloat_setup.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | cd ~
4 | git clone https://bitbucket.org/huangty/cs144_bufferbloat.git
5 | sudo apt-get -y install screen
6 | sudo apt-get -y install python-matplotlib
7 |
--------------------------------------------------------------------------------
/sdn/mininet-tests/buffersizing-red/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | Buffersizing experiment.
3 | Please refer to http://reproducingnetworkresearch.wordpress.com/2012/06/01/sizing-router-buffers/
4 | for more details.
5 | """
6 |
--------------------------------------------------------------------------------
/sdn/cs144_bufferbloat/monitor.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | if [ $# -ne 1 ]
4 | then
5 | echo "Usage: `basename $0` {experiment_name}"
6 | exit
7 | fi
8 |
9 | exp=$1
10 | sudo python exp_monitor.py -e ${exp}
11 |
--------------------------------------------------------------------------------
/lecture/bit_program_design/04TextProBarV2.py:
--------------------------------------------------------------------------------
1 | #coding:utf-8
2 | #TextProBarV2.py
3 | print("\n=== 版本V2 ===")
4 | import time
5 | for i in range(101):
6 | print("\r{:3}%".format(i), end="") #TODO \r 的作用?
7 | time.sleep(0.1)
8 |
--------------------------------------------------------------------------------
/lecture/nju_data_intro/df_plot.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 | import pandas as pd
3 | import matplotlib.pyplot as plt
4 |
5 | df = pd.DataFrame(np.random.randn(4,4),index = list('ABCD'),columns=list('OPKL'))
6 | df.plot()
7 | plt.show()
--------------------------------------------------------------------------------
/pythonchallenge/01.py:
--------------------------------------------------------------------------------
1 | # -*- coding:utf-8 -*-
2 | """
3 | filename:
4 | author:
5 | version:
6 | """
7 | import math
8 |
9 | """
10 | In [9]: math.pow(2,38)
11 | Out[9]: 274877906944.0
12 | """
13 | print math.pow(2,38)
14 |
--------------------------------------------------------------------------------
/sdn/mininet-tests/udping/Makefile:
--------------------------------------------------------------------------------
1 |
2 | FILES=udping
3 |
4 | all: $(FILES)
5 | @echo done
6 |
7 | udping: udping.c
8 |
9 | %.c:
10 | $(CC) $(CFLAGS) $< -o $@
11 |
12 | .PHONY: clean
13 | clean:
14 | rm $(FILES)
15 |
16 |
--------------------------------------------------------------------------------
/web_framework/mydjango/learn/templates/home.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 传媒众筹
6 |
7 |
8 | 欢迎光临传媒众筹网
9 |
10 |
--------------------------------------------------------------------------------
/ns3/practical_csocket2/VoteEncoding.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | bool Decode(uint8_t *inBuf, size_t mSize, VoteInfo *v);
6 | size_t Encode(VoteInfo *v, uint8_t *outBuf, size_t bufSize);
7 |
--------------------------------------------------------------------------------
/sdn/mininet-tests/pairs/Makefile:
--------------------------------------------------------------------------------
1 |
2 | FILES=packetcount
3 |
4 | all: $(FILES)
5 | @echo done
6 |
7 | udping: udping.c
8 |
9 | %.c:
10 | $(CC) $(CFLAGS) $< -o $@
11 |
12 | .PHONY: clean
13 | clean:
14 | rm $(FILES)
15 |
16 |
--------------------------------------------------------------------------------
/web_framework/mydjango/learn/templates/step06b.html:
--------------------------------------------------------------------------------
1 | 教程列表:
2 |
3 |
4 | {% for i in TutorialList %}
5 | {{ i }}
6 | {% endfor %}
7 |
8 |
9 |
10 | 小结
11 | 一般的变量之类的用 { { } }(变量),功能类的,比如循环,条件判断是用 { % % }(标签)
--------------------------------------------------------------------------------
/lecture/bit_program_design/README.md:
--------------------------------------------------------------------------------
1 | # 北理工 MOOC 国家精品课程 Python语言程序设计 源代码示例
2 |
3 | Source: https://www.icourse163.org/learn/BIT-268001
4 |
5 | ## 运行环境
6 | ```
7 | $ python -V
8 | Python 3.6.0 :: Anaconda 4.3.1 (x86_64)
9 | ```
10 |
11 |
--------------------------------------------------------------------------------
/ml/README.md:
--------------------------------------------------------------------------------
1 |
2 | 增加关联规则算法
3 |
4 | * https://github.com/apachecn/AiLearning/blob/master/docs/ml/11.使用Apriori算法进行关联分析.md , python 2.0 代码
5 |
6 | * https://github.com/apachecn/AiLearning/blob/master/docs/ml/12.使用FP-growth算法来高效发现频繁项集.md, python 3.0 代码
--------------------------------------------------------------------------------
/sdn/mininet-tests/README.md:
--------------------------------------------------------------------------------
1 |
2 | mininet-tests 相关测试; 结果在 evernotes: 搜索 mininet-tests 中
3 | * dasdn 测试 deadline aware sdn
4 | * parkinglot
5 | * pairs
6 | * udping
7 |
8 | 其他目录
9 | * cpuiso
10 | * lib 库目录
11 | * util 工具目录
12 |
--------------------------------------------------------------------------------
/stdmod/math/docs_math.py:
--------------------------------------------------------------------------------
1 | # -*- coding:utf-8 -*-
2 |
3 | """
4 | https://docs.python.org/2/library/math.html
5 | """
6 |
7 | import math
8 | """
9 | In [9]: math.pow(2,38)
10 | Out[9]: 274877906944.0
11 | """
12 | print math.pow(2,38)
13 |
--------------------------------------------------------------------------------
/ns2/ns_by_example/jitter.sh:
--------------------------------------------------------------------------------
1 | #! /bin/bash
2 |
3 | cat out.tr | grep " 2 3 cbr " | grep ^r | ../column.sh 1 10 | awk '{dif = $2 - old2; if(dif==0) dif = 1; if(dif > 0) {printf("%d\t%f\n", $2, ($1 - old1) / dif); old1 = $1; old2 = $2}}' > jitter.txt
4 |
5 |
--------------------------------------------------------------------------------
/ns2/otcl/wiki_string.tcl:
--------------------------------------------------------------------------------
1 |
2 |
3 | string replace "this is a bad example" 10 12 good
4 | #this is a good example
5 |
6 | string map {bad good} "this is a bad example"
7 | #this is a good example
8 |
9 | set rate [string map {Mb ""} "1000Mb"]
10 |
11 |
--------------------------------------------------------------------------------
/pygame/pygame_demo_audio.py:
--------------------------------------------------------------------------------
1 | import pygame
2 | pygame.mixer.init()
3 | #pygame.mixer.music.load("audio/friendship.mp3")
4 | pygame.mixer.music.load("audio/shake.wav")
5 | pygame.mixer.music.play()
6 | while pygame.mixer.music.get_busy() == True:
7 | continue
8 |
--------------------------------------------------------------------------------
/sdn/mininet-tests/buffersizing-red/gen.sh:
--------------------------------------------------------------------------------
1 |
2 | rootdir=red-p0.02-Jul17-23-13/
3 | python plot-results.py --dir $rootdir --out red-p0.02.png
4 |
5 | # 使用内嵌4项数据生成图表 for flows_per_host in 10 25 50 100;
6 | python plot-results.py --dir $rootdir --out red-embed.png -e
7 |
--------------------------------------------------------------------------------
/ns3/practical_csocket2/survey1.txt:
--------------------------------------------------------------------------------
1 | 2
2 | What is your favorite flavor of ice cream?
3 | 3
4 | Vanilla
5 | Chocolate
6 | Strawberry
7 | Socket programming is:
8 | 4
9 | Surprisingly easy
10 | Empowering
11 | Not for the faint of heart
12 | Fun for the whole family
13 |
--------------------------------------------------------------------------------
/sdn/mininet-tests/pairs/pair_intervals_links_debug.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | sudo ./pair_intervals.py --counts 2,2,2 --time 10 -o results/links2.out
3 | sudo ./pair_intervals.py --counts 3,3,3 --time 10 -o results/links3.out
4 |
5 | ./plot_pair_intervals.py -lr results/links*.out
6 |
--------------------------------------------------------------------------------
/lecture/bit_program_design/12test.txt:
--------------------------------------------------------------------------------
1 | 袁帅
2 | 孙雨辰
3 | 刘思琪
4 | 李雅琪
5 | 栾云琦
6 | 杨聪灵
7 | 陈百科
8 | 钭诗薇
9 | 童丽芳
10 | 刘静宜
11 | 吴倩
12 | 卿姮瑜
13 | 邓高旭
14 | 廖梦思
15 | 季永懿
16 | 周杨頔
17 | 邓沛
18 | 李宏娟
19 | 卜一凡
20 | 余锦坤
21 | 唐子晨
22 | 刘嘉欣
23 | 米亚沙尔·阿布都拉
24 | 古丽孜巴·喀迪尔
25 | 麦迪那木·于苏普
26 | 魏于坤
27 | 王梓潇
--------------------------------------------------------------------------------
/stdmod/unittest/test_mylib/mainsuit.py:
--------------------------------------------------------------------------------
1 | import unittest
2 |
3 | from test.sub.test_string import TestStringMethods
4 |
5 | if __name__ == '__main__':
6 | suite = unittest.TestLoader().loadTestsFromTestCase(TestStringMethods)
7 | unittest.TextTestRunner(verbosity=2).run(suite)
8 |
--------------------------------------------------------------------------------
/lecture/guess_num.py:
--------------------------------------------------------------------------------
1 | #conding:utf-8
2 | # filename: guess_num.py
3 |
4 | import random
5 |
6 | print ("游戏结束,您要猜的数字是 {}".format(random.randrange(1,10)))
7 |
8 |
9 | level = 3
10 |
11 | def chooselevel():
12 | # global level2
13 | print("选择难度为:", level)
14 |
15 | chooselevel()
16 |
--------------------------------------------------------------------------------
/stdmod/unittest/mylib/rm_module.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 | import os
4 |
5 | def rm(filename):
6 | if os.path.isfile(filename):
7 | os.remove(filename)
8 |
9 |
10 | class ProductionClass():
11 | def method(self):
12 | return 100
13 |
--------------------------------------------------------------------------------
/turtle/star.py:
--------------------------------------------------------------------------------
1 |
2 | #REF: https://docs.python.org/3.3/library/turtle.html?highlight=turtle
3 |
4 | from turtle import *
5 | color('red', 'yellow')
6 | begin_fill()
7 | while True:
8 | forward(200)
9 | left(170)
10 | if abs(pos()) < 1:
11 | break
12 | end_fill()
13 | done()
--------------------------------------------------------------------------------
/ns2/ns_by_example/post01_trace2jitter.sh:
--------------------------------------------------------------------------------
1 | OUT_FILE=$1
2 | cat out.tr | grep " 2 3 cbr " | grep ^r | ../column.sh 1 10 | awk '{dif = $2 - old2; if(dif==0) dif = 1; if(dif > 0) {printf("%d\t%f\n", $2, ($1 - old1) / dif); old1 = $1; old2 = $2}}' > $OUT_FILE
3 |
4 | echo "generated $OUT_FILE from out.tr"
5 |
--------------------------------------------------------------------------------
/stdmod/unittest/mylib/req_module.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 |
4 | import requests
5 |
6 |
7 | def send_request(url):
8 | r = requests.get(url)
9 | return r.status_code
10 |
11 |
12 | def visit_ustack():
13 | return send_request('http://www.ustack.com')
--------------------------------------------------------------------------------
/EduLogging/README.md:
--------------------------------------------------------------------------------
1 | python stdlib logging 弹药库
2 | ---------------------------
3 |
4 | 以 Pycharm Edu -- Logging 项目为主
5 | 已完成
6 | ```
7 | Basics
8 | Formating
9 | Basic Handlers
10 | ```
11 |
12 |
13 | 除了以下目录以外, 大部分目录为从 pycharm Edu 项目获取
14 | ***
15 | www.python.org
16 | www.othersite.com
17 | ***
18 |
--------------------------------------------------------------------------------
/ns2/tcpsuit/analysis/count_flows.sh:
--------------------------------------------------------------------------------
1 | name=`cat file`
2 | echo $name
3 | gawk '{if ($1%2==0) print}' $name > top_even
4 | gawk '{if ($1%2!=0) print}' $name > top_odd
5 | paste top_odd top_even > top
6 | awk '{print $2$6}' top | sort -n | uniq -c
7 | echo "===="
8 | head -n 40 top | awk '{print $2$6}' | sort -n | uniq -c
9 |
--------------------------------------------------------------------------------
/sdn/akaedu/ch28/ex28.2.blocking.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | int main(void)
5 | {
6 | char buf[10];
7 | int n;
8 | n = read(STDIN_FILENO, buf, 10);
9 | if (n < 0) {
10 | perror("read STDIN_FILENO");
11 | exit(1);
12 | }
13 | write(STDOUT_FILENO, buf, n);
14 | return 0;
15 | }
--------------------------------------------------------------------------------
/web_framework/mydjango/learn/templates/step06c.html:
--------------------------------------------------------------------------------
1 | 教程列表:
2 |
3 |
4 |
5 | key: value
6 | {% for key, value in info_dict.items %}
7 | {{ key }}: {{ value }}
8 | {% endfor %}
9 |
10 |
11 |
12 |
13 | 小结
14 | 一般的变量之类的用 { { } }(变量),功能类的,比如循环,条件判断是用 { % % }(标签)
--------------------------------------------------------------------------------
/sdn/akaedu/ch28/Makefile:
--------------------------------------------------------------------------------
1 |
2 | #%.o: %.c
3 | # $(CC) -c $<
4 |
5 | BIN1=ex28.2.blocking
6 |
7 | all: $(BIN1) $(BIN1).o
8 |
9 | # 编译可执行文件到上一级./bin/目录 $@ 表示规则中的目标
10 | $(BIN1):
11 | $(CC) $@.c -o ../out/$@
12 |
13 | # 编译.o 文件, 下面这句为默认策略, 可省略
14 | $(BIN1).o:
15 |
16 | clean:
17 | rm -f *.o
18 | rm -f ../out/$(BIN1)
--------------------------------------------------------------------------------
/web_framework/mydjango/demoapp/templates/d01_first_steps/base.html:
--------------------------------------------------------------------------------
1 | {% load staticfiles %}
2 |
3 |
4 | {% block title %}{% endblock %}
5 |
6 |
7 |
8 | {% block content %}{% endblock %}
9 |
10 |
--------------------------------------------------------------------------------
/web_framework/mydjango/manage.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | import os
3 | import sys
4 |
5 | if __name__ == "__main__":
6 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mydjango.settings")
7 |
8 | from django.core.management import execute_from_command_line
9 |
10 | execute_from_command_line(sys.argv)
11 |
--------------------------------------------------------------------------------
/yun_sdk/baidu/demo_tts.py:
--------------------------------------------------------------------------------
1 | #-*- coding:utf-8 -*-
2 |
3 | from TTS.tts_lib import MyTTS
4 |
5 | from config import * #YOUR_APP_KEY / YOUR_SECRET_KEY 秘钥
6 |
7 |
8 | # #使用复制出的 ttslib文件进行替换
9 | tts = MyTTS(app_key=YOUR_APP_KEY, secret_key=YOUR_SECRET_KEY)
10 | tts.say("你好")
11 | tts.save("这是一个百度语音例子", "tmp.mp3")
12 |
--------------------------------------------------------------------------------
/sdn/akaedu/ch25/Makefile:
--------------------------------------------------------------------------------
1 |
2 | #%.o: %.c
3 | # $(CC) -c $<
4 |
5 | all: ex25.2.strok \
6 | ex25.1.strfun
7 |
8 | # 编译可执行文件到上一级./bin/目录 $@ 表示规则中的目标
9 | # ex25.2.strok:
10 | # $(CC) $@.c -o ../out/$@
11 |
12 | # 编译.o 文件, 下面这句为默认策略, 可省略
13 | # ex25.2.strok.o:
14 |
15 | clean:
16 | rm -f *.o
17 | rm -f ex25.2.strok
18 | rm -f ex25.1.strfun
--------------------------------------------------------------------------------
/web_framework/web_py_templates/index.html:
--------------------------------------------------------------------------------
1 | $def with (name)
2 |
3 | $if name:
4 |
5 |
6 |
7 |
8 |
9 |
10 | I just wanted to say hello to $name.
11 |
12 |
13 |
14 | $else:
15 | Hello , world! (name is $name)
16 |
17 |
18 |
--------------------------------------------------------------------------------
/sdn/akaedu/ch25/ex25.2.strok.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | int main(void)
5 | {
6 | char str[] = "root:x::0:root:/root:/bin/bash:";
7 | char *token;
8 |
9 | token = strtok(str, ":");
10 | printf("%s\n", token);
11 | while ( (token = strtok(NULL, ":")) != NULL)
12 | printf("%s\n", token);
13 |
14 | return 0;
15 | }
16 |
--------------------------------------------------------------------------------
/stdmod/unittest/mylib/widget.py:
--------------------------------------------------------------------------------
1 | class Widget:
2 | def __init__(self, name):
3 | self.x = 50
4 | self.y = 50
5 | pass
6 |
7 | def resize(self, x, y):
8 | self.x = x
9 | self.y = y
10 |
11 | def size(self):
12 | return self.x, self.y
13 |
14 | def dispose(self):
15 | pass
16 |
--------------------------------------------------------------------------------
/ns3/misc/test_std_clang.cc:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | struct Foo {
4 | int n;
5 | Foo() {
6 | std::clog << "static constructor\n";
7 | }
8 | ~Foo() {
9 | std::clog << "static destructor\n";
10 | }
11 | };
12 |
13 | Foo f; // static object
14 |
15 | int main()
16 | {
17 | std::clog << "main function\n";
18 | }
19 |
--------------------------------------------------------------------------------
/web_framework/mydjango/templates/admin/base_site.orig.html:
--------------------------------------------------------------------------------
1 | {% extends "admin/base.html" %}
2 |
3 | {% block title %}{{ title }} | {{ 欢迎访问 {% endblock %}
4 |
5 | {% block branding %}
6 |
7 | {% endblock %}
8 |
9 |
10 |
11 | {% block nav-global %}
12 | {% endblock %}
13 |
--------------------------------------------------------------------------------
/ns3/practical_csocket2/VoteProtocol.h:
--------------------------------------------------------------------------------
1 | struct VoteInfo {
2 | uint64_t count; // invariant: !isResponse => count==0
3 | int candidate; // invariant: 0 <= candidate <= MAX_CANDIDATE
4 | bool isInquiry;
5 | bool isResponse;
6 | };
7 |
8 | typedef struct VoteInfo VoteInfo;
9 |
10 | enum {
11 | MAX_CANDIDATE = 1000,
12 | MAX_WIRE_SIZE = 500
13 | };
14 |
--------------------------------------------------------------------------------
/turtle/hexagon.py:
--------------------------------------------------------------------------------
1 | #hexagon.py
2 |
3 | # REF: https://github.com/asweigart/simple-turtle-tutorial-for-python/blob/master/simple_turtle_tutorial.md
4 |
5 |
6 | from turtle import *
7 | colors = ['red', 'purple', 'blue', 'green', 'yellow', 'orange']
8 | for x in range(360):
9 | pencolor(colors[x % 6])
10 | width(x / 100 + 1)
11 | forward(x)
12 | left(59)
--------------------------------------------------------------------------------
/web_framework/mydjango/demoapp/templates/d01_first_steps/polls_results.html:
--------------------------------------------------------------------------------
1 | {{ question.question_text }}
2 |
3 |
4 | {% for choice in question.choice_set.all %}
5 | {{ choice.choice_text }} -- {{ choice.votes }} vote{{ choice.votes|pluralize }}
6 | {% endfor %}
7 |
8 |
9 | 再投一次?
10 |
--------------------------------------------------------------------------------
/web_framework/mydjango/demoapp/templates/d01_first_steps/polls_index.html:
--------------------------------------------------------------------------------
1 | {% if latest_question_list %}
2 |
7 | {% else %}
8 | No polls are available.
9 | {% endif %}
10 |
--------------------------------------------------------------------------------
/ns2/otcl/class_info.sh:
--------------------------------------------------------------------------------
1 | # linux sort 在面对特殊字符 # 表现不稳定, 修改为 sorted();
2 | # 用 objs.sort() 会报TypeError: 'NoneType' object is not iterable
3 | #ns class_info.tcl | pawk -p 'objs=r[0].split(); print "# total otcl objects", len(objs); for x in objs: print x' | sort
4 |
5 | ns class_info.tcl | pawk -p 'objs=r[0].split(); print "# total otcl objects", len(objs); for x in sorted(objs): print x'
--------------------------------------------------------------------------------
/sdn/mininet-tests/udping/README.md:
--------------------------------------------------------------------------------
1 | # udping
2 | 在不同节点的数量(CPU 利用率)下,绘制udping 的 box 与 bar 图
3 |
4 | ## required
5 | ../cpuiso make
6 |
7 | ../lib
8 |
9 | ## run
10 | ```
11 | make
12 | ./run_udpong.sh
13 | export DISPLAY=127.0.0.1:10.0
14 |
15 | ./plot_udpong.sh # 绘制 bar 图
16 | ./plot_udpong_box.sh # 绘制 box 图
17 |
18 | # 绘图样例可参考搜索 evernotes "mininet-tests"
19 | ```
20 |
--------------------------------------------------------------------------------
/sdn/ryu-cuc/tests/unit/sample/test_sample2.py:
--------------------------------------------------------------------------------
1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4
2 |
3 | import unittest
4 | from nose.tools import ok_, eq_
5 | # from ryu.app.simple_switch import SimpleSwitch
6 |
7 |
8 | class TestSample2(unittest.TestCase):
9 |
10 | def testS2Func1(self):
11 | ok_(True)
12 |
13 | def testS2Func2(self):
14 | ok_(True)
15 |
--------------------------------------------------------------------------------
/ns3/practical_csocket2/DieWithMessage.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | void DieWithUserMessage(const char *msg, const char *detail) {
5 | fputs(msg, stderr);
6 | fputs(": ", stderr);
7 | fputs(detail, stderr);
8 | fputc('\n', stderr);
9 | exit(1);
10 | }
11 |
12 | void DieWithSystemMessage(const char *msg) {
13 | perror(msg);
14 | exit(1);
15 | }
16 |
--------------------------------------------------------------------------------
/sdn/mininet-tests/cpuiso/cpu/Makefile:
--------------------------------------------------------------------------------
1 |
2 | FILES=cpu-stress
3 | FILES+=gettimeofday
4 | FILES+=timer
5 | FILES+=steal_cpu
6 | FILES+=cpumonitor
7 |
8 | all: $(FILES)
9 | @echo done
10 |
11 | cpu-stress: cpu-stress.c
12 | gettimeofday: gettimeofday.c
13 | timer: timer.c
14 |
15 | %.c:
16 | $(CC) $(CFLAGS) $< -o $@
17 |
18 | .PHONY: clean
19 | clean:
20 | rm $(FILES)
21 |
22 |
--------------------------------------------------------------------------------
/turtle/draw-sin.py:
--------------------------------------------------------------------------------
1 | # REF: https://zhuanlan.zhihu.com/p/31202953
2 | # 绘制正弦曲线
3 |
4 | import turtle
5 | import math
6 |
7 | window=turtle.Screen() #creat a screen
8 | pen=turtle.Turtle()
9 |
10 | pen.pu()
11 | pen.setx(-300)
12 | pen.sety(100*math.sin(-300/40))
13 | pen.pd()
14 |
15 | for i in range(-300,300):
16 | pen.setx(i)
17 | pen.sety(100*math.sin(i/40))
18 |
--------------------------------------------------------------------------------
/EduLogging/lesson8/task7/context.py:
--------------------------------------------------------------------------------
1 | import logging
2 |
3 | def do_service_lookup(service_address):
4 | try:
5 | raise Exception('Connection refused.')
6 |
7 | except:
8 | logging.exception(enter a message with relevent context)
9 |
10 | if __name__ == '__main__':
11 | logging.basicConfig(level=logging.INFO)
12 |
13 | do_service_lookup('10.0.0.15')
14 |
--------------------------------------------------------------------------------
/lecture/bit_program_design/01TempConvert.py:
--------------------------------------------------------------------------------
1 | #coding:utf-8
2 | #TempConvert.py
3 | TempStr = input("请输入带有符号的温度值: ")
4 | if TempStr[-1] in ['F', 'f']:
5 | C = (eval(TempStr[0:-1]) - 32) / 1.8
6 | print("转换后的温度是{:.2f}C".format(C))
7 | elif TempStr[-1] in ['C', 'c']:
8 | F = 1.8 * eval(TempStr[0:-1]) + 32
9 | print("转换后的温度是{:.2f}F".format(F))
10 | else:
11 | print("输入格式错误")
12 |
--------------------------------------------------------------------------------
/sdn/mininet-tests/cpuiso/cpu/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | container=`date +%s`
4 | quota=100000
5 | period=500000
6 |
7 | # -s lxc.cgroup.cpuset.cpus=$1 \
8 | lxc-execute -n "$container" \
9 | -s lxc.cgroup.cpu.cfs_quota_us=$quota \
10 | -s lxc.cgroup.cpu.cfs_period_us=$period \
11 | ./cpu-stress 36000 0
12 | #python timer_latency.py $quota-$period
13 | #./steal_cpu 500000
14 |
15 |
--------------------------------------------------------------------------------
/lecture/bit_program_design/04TextProBarV1.py:
--------------------------------------------------------------------------------
1 | #coding:utf-8
2 | #TextProBarV1.py
3 | print("\n=== 版本V1 ===")
4 |
5 | import time
6 | scale = 10
7 | print("------执行开始------")
8 | for i in range(scale+1):
9 | a = '*' * i
10 | b = '.' * (scale - i)
11 | c = (i/scale)*100
12 | print("\r{:^3.0f}%[{}->{}]".format(c,a,b), end="")
13 | time.sleep(0.1)
14 | print("\n------执行结束------")
15 |
--------------------------------------------------------------------------------
/EduLogging/lesson5/task4/task.html:
--------------------------------------------------------------------------------
1 |
2 | In the previous task, disabling propagation on a handler in the hierarchy gave us a warning message, under Python 2.7.
3 | We can explicitly silence this warning by adding a NullHandler handler object to the logger. This
4 | handler does not output any log records. This will work with both Python 2.7 and Python 3. NullHandler is not available
5 | in Python 2.6 or earlier.
6 |
--------------------------------------------------------------------------------
/sdn/mininet-tests/parkinglot/README.md:
--------------------------------------------------------------------------------
1 |
2 | ##required
3 | * termcolor
4 | # 输出命令时可显示队列颜色
5 |
6 | pip install termcolor
7 | * ../util
8 | git clone https://github.com/mininet/mininet-util.git ../util
9 | * bwm-ng # 带宽监测
10 | git clone https://github.com/vgropp/bwm-ng.git
11 | cd bwm-ng/
12 | ./autogen.sh && make && sudo make install
13 |
14 |
15 | ## Running
16 |
17 | sudo ./parkinglot-sweep.sh
18 |
--------------------------------------------------------------------------------
/ns2/ns_by_example/ex-linkage.tcl:
--------------------------------------------------------------------------------
1 | # Jae Chung 7-13-99
2 |
3 | # Create MyAgent (This will give two warning messages that
4 | # no default vaules exist for my_var1_otcl and my_var2_otcl)
5 | set myagent [new Agent/MyAgentOtcl]
6 |
7 | # Set configurable parameters of MyAgent
8 | $myagent set my_var1_otcl 3
9 | $myagent set my_var2_otcl 3.14
10 |
11 | # Give a command to MyAgent
12 | $myagent call-my-priv-func
13 |
--------------------------------------------------------------------------------
/EduLogging/lesson2/task7/string_formatting.py:
--------------------------------------------------------------------------------
1 | from __future__ import print_function
2 | import logging
3 |
4 | logger = logging.getLogger(__name__)
5 |
6 | if __name__ == '__main__':
7 | logging.basicConfig(level=logging.DEBUG)
8 |
9 | logging.debug('this message is not formatted; value=%s %s', 'value', 'value')
10 |
11 | logging.debug('this message is not formatted; value=%s' , 'value' )
12 |
13 |
14 |
--------------------------------------------------------------------------------
/sdn/mininet-tests/buffersizing/gengraph 2.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # Plot inter-dequeue time distribution...
4 |
5 | # Exit on any failure...
6 | set -e
7 |
8 | python link_dequeues.py --files linkdata-10 linkdata-100 linkdata-400 \
9 | --expected 193.8 193.8 193.8 \
10 | --labels "20 flows" "200 flows" "800 flows" \
11 | --title "" --ccdf --log --out inter-dequeue-deviation-ccdf-latest.pdf --percent
12 |
13 |
--------------------------------------------------------------------------------
/web_framework/mydjango/learn/templates/base_extend.html:
--------------------------------------------------------------------------------
1 |
2 | {% extends 'base.html' %}
3 |
4 | {% block title %}欢迎光临 众筹页面 {% endblock %}
5 |
6 | {% block content %}
7 |
8 |
9 | {% include 'ad.html' %}
10 |
11 | 这里是首页,欢迎光临
12 |
13 | 来给你一个列表
14 |
15 | a
16 | b
17 | c
18 |
19 |
20 | {% endblock %}
--------------------------------------------------------------------------------
/ns2/tcpsuit/analysis/test.tcl:
--------------------------------------------------------------------------------
1 | ####### Set of simulation senarios
2 | set idxs "1 2 3 4 5 6 7 8 9 10 11 12"
3 | #set idxs "1 2 7 8"
4 |
5 | ####### Set of ptorocols
6 | set prots "bbhreno bbhbbh"
7 |
8 | ####### Model parameters
9 | set maxlink [lindex $argv 0]
10 | set maxflow [lindex $argv 1]
11 | set maxlflow [lindex $argv 2]
12 | puts "maxlink $maxlink"
13 | puts "maxflow $maxflow"
14 | puts "maxlflow $maxlflow"
15 |
16 |
--------------------------------------------------------------------------------
/pythonchallenge/README.md:
--------------------------------------------------------------------------------
1 |
2 | pythonchanllenge 备忘
3 |
4 |
5 | ```
6 | ipython 页面
7 | pythonchanllenge.ipynb: 将挑战汇聚到 ipynb 中, 一览所有的解决方法
8 |
9 |
10 | python 代码(旧)
11 | 01.py: math.power()
12 | 02.py: string.maketrans() translate() 翻译加密字符a-z
13 | 03.py: 查找罕见的字符; 定义uniq_count() 函数,便于观察字符中的罕见字符
14 | 04.py: 查找; 定义了mylib.uniq_count() 字符串的分割统计函数 ,便于以后使用
15 | 05.py: linkedlist 循环抓取页面 requests/response 页面处理(据说requests速度慢不要用)
16 | ```
17 |
--------------------------------------------------------------------------------
/EduLogging/lesson8/task3/conditional_logging.py:
--------------------------------------------------------------------------------
1 | import logging
2 | import time
3 |
4 | logger = logging.getLogger(__name__)
5 |
6 | def calculate_expensive_result(timeout):
7 | time.sleep(timeout)
8 | return 1
9 |
10 |
11 | if __name__ == '__main__':
12 | logging.basicConfig(level=logging.WARNING)
13 |
14 | if logger.isEnabledFor(logging.DEBUG):
15 | logger.debug('expensive_result=%d', calculate_expensive_result(5))
16 |
--------------------------------------------------------------------------------
/ns2/tcpsuit/README.md:
--------------------------------------------------------------------------------
1 | #TCP Evaluation Suite
2 |
3 | Authors: Hideyuki Shimonishi (NEC-Japan)
4 | Cesar Marcondes (UCLA)
5 | M.Y. Sanadidi (UCLA)
6 | Mario Gerla (UCLA)
7 | Padmanabhan Vasu (UCLA)
8 |
9 | Please, follow instruction described in website.
10 |
11 | Source: http://netlab.cs.ucla.edu/tcpsuite/
12 |
13 | 按 ns-2.35 部分修复代码
14 |
15 | 执行代码前, 需运行
16 | `export NSDIR=/opt/coding/ns-allinone-2.35/ns-2.35`
--------------------------------------------------------------------------------
/sdn/mininet-tests/pairs/pair_intervals_switches.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | sudo ./pair_intervals.py --switches --counts 10,10,10 --time 60 -o switches10.out
3 | sudo ./pair_intervals.py --switches --counts 20,20,20 --time 60 -o switches10.out
4 | sudo ./pair_intervals.py --switches --counts 40,40,40 --time 60 -o switches40.out
5 | sudo ./pair_intervals.py --switches --counts 80,80,80 --time 60 -o switches80.out
6 |
7 | ./plot_pair_intervals.py --all switches*.out
8 |
--------------------------------------------------------------------------------
/sdn/mininet-tests/buffersizing/build-patched-iperf.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | PA2_DIR=`pwd`
3 | IPERF_VER='iperf-2.0.5'
4 |
5 |
6 | cd $HOME
7 | wget http://downloads.sourceforge.net/project/iperf/iperf-2.0.5.tar.gz
8 | tar -zxf ${IPERF_VER}.tar.gz
9 | cd ${IPERF_VER}/src
10 | patch -p1 < $PA2_DIR/${IPERF_VER}-wait-syn.patch
11 | cd ..
12 | ./configure
13 | make
14 | cd $HOME
15 | rm ${IPERF_VER}.tar.gz
16 | mv ${IPERF_VER} iperf-patched
17 | cd $PA2_DIR
18 |
--------------------------------------------------------------------------------
/EduLogging/lesson6/task7/tests.py:
--------------------------------------------------------------------------------
1 | from test_helper import run_common_tests, failed, passed, get_answer_placeholders
2 |
3 |
4 | def test_answer_placeholders():
5 | placeholders = get_answer_placeholders()
6 | placeholder = placeholders[0]
7 | if placeholder == "root":
8 | passed()
9 | else:
10 | failed()
11 |
12 |
13 | if __name__ == '__main__':
14 | run_common_tests()
15 | test_answer_placeholders()
16 |
17 |
18 |
--------------------------------------------------------------------------------
/EduLogging/lesson7/task3/tests.py:
--------------------------------------------------------------------------------
1 | from test_helper import run_common_tests, failed, passed, get_answer_placeholders
2 |
3 |
4 | def test_answer_placeholders():
5 | placeholders = get_answer_placeholders()
6 | placeholder = placeholders[0]
7 | if placeholder == "emit":
8 | passed()
9 | else:
10 | failed()
11 |
12 |
13 | if __name__ == '__main__':
14 | run_common_tests()
15 | test_answer_placeholders()
16 |
17 |
18 |
--------------------------------------------------------------------------------
/sdn/mininet-tests/buffersizing-red/build-patched-iperf.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | PA2_DIR=`pwd`
3 | IPERF_VER='iperf-2.0.5'
4 |
5 |
6 | cd $HOME
7 | wget http://downloads.sourceforge.net/project/iperf/iperf-2.0.5.tar.gz
8 | tar -zxf ${IPERF_VER}.tar.gz
9 | cd ${IPERF_VER}/src
10 | patch -p1 < $PA2_DIR/${IPERF_VER}-wait-syn.patch
11 | cd ..
12 | ./configure
13 | make
14 | cd $HOME
15 | rm ${IPERF_VER}.tar.gz
16 | mv ${IPERF_VER} iperf-patched
17 | cd $PA2_DIR
18 |
--------------------------------------------------------------------------------
/EduLogging/lesson8/task1/tests.py:
--------------------------------------------------------------------------------
1 | from test_helper import run_common_tests, failed, passed, get_answer_placeholders
2 |
3 |
4 | def test_answer_placeholders():
5 | placeholders = get_answer_placeholders()
6 | placeholder = placeholders[0]
7 | if placeholder == "__name__":
8 | passed()
9 | else:
10 | failed()
11 |
12 |
13 | if __name__ == '__main__':
14 | run_common_tests()
15 | test_answer_placeholders()
16 |
17 |
18 |
--------------------------------------------------------------------------------
/sdn/akaedu/ch08/Makefile:
--------------------------------------------------------------------------------
1 | # -g 运行调试
2 | # CFLAGS = -g -Wall -O3
3 | # CFLAGS = -g -O3 -w # disable warning
4 | CFLAGS = -g # 如果用-O3编译, gdb将不支持 set val 操作
5 |
6 | #%.o: %.c
7 | # $(CC) -c $<
8 |
9 | all: ex08.str ex08.5.game
10 |
11 |
12 | # 编译可执行文件到上一级./bin/目录 $@ 表示规则中的目标
13 | # ex25.2.strok:
14 | # $(CC) $@.c -o ../out/$@
15 |
16 | # 编译.o 文件, 下面这句为默认策略, 可省略
17 | # ex25.2.strok.o:
18 |
19 | clean:
20 | rm -f *.o
21 | rm -f ex08.str
22 | rm -f ex08.5.game
--------------------------------------------------------------------------------
/EduLogging/lesson1/task7/tests.py:
--------------------------------------------------------------------------------
1 | from test_helper import run_common_tests, failed, passed, get_answer_placeholders
2 |
3 |
4 | def test_answer_placeholders():
5 | placeholders = get_answer_placeholders()
6 | placeholder = placeholders[0]
7 | if placeholder == "logging.NOTSET":
8 | passed()
9 | else:
10 | failed()
11 |
12 |
13 | if __name__ == '__main__':
14 | run_common_tests()
15 | test_answer_placeholders()
16 |
17 |
18 |
--------------------------------------------------------------------------------
/EduLogging/lesson4/task3/tests.py:
--------------------------------------------------------------------------------
1 | from test_helper import run_common_tests, failed, passed, get_answer_placeholders
2 |
3 |
4 | def test_answer_placeholders():
5 | placeholders = get_answer_placeholders()
6 | placeholder = placeholders[0]
7 | if placeholder == "file_handler":
8 | passed()
9 | else:
10 | failed()
11 |
12 |
13 | if __name__ == '__main__':
14 | run_common_tests()
15 | test_answer_placeholders()
16 |
17 |
18 |
--------------------------------------------------------------------------------
/EduLogging/lesson6/task3/task.html:
--------------------------------------------------------------------------------
1 |
2 | In this task we will configure our root Logger instance. This is done using the instance name "root".
3 |
4 |
5 | Under the "[logger_root]" section we need to configure additional key/values to complete the instance configuration:
6 |
7 |
8 | "handlers" is a list of key names for each instance of a handler we want to add to this Logger instance.
9 |
10 |
11 | "level" is the log severity level
12 |
--------------------------------------------------------------------------------
/EduLogging/lesson1/task2/tests.py:
--------------------------------------------------------------------------------
1 | from test_helper import run_common_tests, failed, passed, get_answer_placeholders
2 |
3 |
4 | def test_answer_placeholders():
5 | placeholders = get_answer_placeholders()
6 | placeholder = placeholders[0]
7 | if placeholder == "level=logging.DEBUG":
8 | passed()
9 | else:
10 | failed()
11 |
12 |
13 | if __name__ == '__main__':
14 | run_common_tests()
15 | test_answer_placeholders()
16 |
17 |
18 |
--------------------------------------------------------------------------------
/EduLogging/lesson4/task5/tests.py:
--------------------------------------------------------------------------------
1 | from test_helper import run_common_tests, failed, passed, get_answer_placeholders
2 |
3 |
4 | def test_answer_placeholders():
5 | placeholders = get_answer_placeholders()
6 | placeholder = placeholders[0]
7 | if placeholder == "logging.shutdown()":
8 | passed()
9 | else:
10 | failed()
11 |
12 |
13 | if __name__ == '__main__':
14 | run_common_tests()
15 | test_answer_placeholders()
16 |
17 |
18 |
--------------------------------------------------------------------------------
/EduLogging/lesson6/task2/tests.py:
--------------------------------------------------------------------------------
1 | from test_helper import run_common_tests, failed, passed, get_answer_placeholders, check_answers
2 |
3 |
4 | def test_answer_placeholders():
5 | placeholders = get_answer_placeholders()
6 | answers = [
7 | ["handler1"],
8 | ["handler1"],
9 | ]
10 | check_answers(placeholders, answers)
11 |
12 |
13 | if __name__ == '__main__':
14 | run_common_tests()
15 | test_answer_placeholders()
16 |
17 |
18 |
--------------------------------------------------------------------------------
/EduLogging/lesson6/task5/tests.py:
--------------------------------------------------------------------------------
1 | from test_helper import run_common_tests, failed, passed, get_answer_placeholders, check_answers
2 |
3 |
4 | def test_answer_placeholders():
5 | placeholders = get_answer_placeholders()
6 | answers = [
7 | ['console'],
8 | ['log_config']
9 | ]
10 | check_answers(placeholders, answers)
11 |
12 |
13 | if __name__ == '__main__':
14 | run_common_tests()
15 | test_answer_placeholders()
16 |
17 |
18 |
--------------------------------------------------------------------------------
/EduLogging/lesson7/task4/tests.py:
--------------------------------------------------------------------------------
1 | from test_helper import run_common_tests, failed, passed, get_answer_placeholders, check_answers
2 |
3 |
4 | def test_answer_placeholders():
5 | placeholders = get_answer_placeholders()
6 | answers = [
7 | ["filter"],
8 | ["True", "1"]
9 | ]
10 | check_answers(placeholders, answers)
11 |
12 |
13 | if __name__ == '__main__':
14 | run_common_tests()
15 | test_answer_placeholders()
16 |
17 |
18 |
--------------------------------------------------------------------------------
/lecture/bit_program_design/04TextProBarV3.py:
--------------------------------------------------------------------------------
1 | #coding:utf-8
2 | print("\n=== 版本V3 ===")
3 | import time
4 | scale = 50
5 | print("执行开始".center(scale//2, "-"))
6 | start = time.perf_counter()
7 | for i in range(scale+1):
8 | a = '*' * i
9 | b = '.' * (scale - i)
10 | c = (i/scale)*100
11 | dur = time.perf_counter() - start
12 | print("\r{:^3.0f}% [{}->{}]{:.2f}s".format(c,a,b,dur),end='')
13 | time.sleep(0.1)
14 | print("\n"+"执行结束".center(scale//2,'-'))
--------------------------------------------------------------------------------
/ns2/ns_by_example/basic01_ex-tcl.tcl:
--------------------------------------------------------------------------------
1 | # 基本运算
2 | # Writing a procedure called "test"
3 | proc test {} {
4 | set a 43
5 | set b 27
6 | set c [expr $a + $b]
7 | set d [expr [expr $a - $b] * $c]
8 | for {set k 0} {$k < 10} {incr k} {
9 | if {$k < 5} {
10 | puts "k < 5, pow = [expr pow($d, $k)]"
11 | } else {
12 | puts "k >= 5, mod = [expr $d % $k]"
13 | }
14 | }
15 | }
16 |
17 | # Calling the "test" procedure created above
18 | test
19 |
--------------------------------------------------------------------------------
/sdn/akaedu/utils/Makefile:
--------------------------------------------------------------------------------
1 | # -g 运行调试
2 | # CFLAGS = -g -Wall -O3
3 | # CFLAGS = -g -O3 -w # disable warning
4 | CFLAGS = -g # 如果用-O3编译, gdb将不支持 set val 操作
5 |
6 | #%.o: %.c
7 | # $(CC) -c $<
8 |
9 | all: parse-string-into-argv-argc
10 |
11 |
12 | # 编译可执行文件到上一级./bin/目录 $@ 表示规则中的目标
13 | # ex25.2.strok:
14 | # $(CC) $@.c -o ../out/$@
15 |
16 | # 编译.o 文件, 下面这句为默认策略, 可省略
17 | # ex25.2.strok.o:
18 |
19 | clean:
20 | rm -f *.o
21 | rm -f parse-string-into-argv-argc
22 |
--------------------------------------------------------------------------------
/EduLogging/lesson6/task1/tests.py:
--------------------------------------------------------------------------------
1 | from test_helper import run_common_tests, failed, passed, get_answer_placeholders, check_answers
2 |
3 |
4 | def test_answer_placeholders():
5 | placeholders = get_answer_placeholders()
6 | answers = [
7 | ["formatter1"],
8 | ["formatter1"],
9 | ]
10 | check_answers(placeholders, answers)
11 |
12 |
13 | if __name__ == '__main__':
14 | run_common_tests()
15 | test_answer_placeholders()
16 |
17 |
18 |
--------------------------------------------------------------------------------
/sdn/cs144_bufferbloat/http/webserver.py:
--------------------------------------------------------------------------------
1 | import SimpleHTTPServer
2 | import SocketServer
3 |
4 | class CS144Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
5 |
6 | # Disable logging DNS lookups
7 | def address_string(self):
8 | return str(self.client_address[0])
9 |
10 |
11 | PORT = 80
12 |
13 | Handler = CS144Handler
14 | httpd = SocketServer.TCPServer(("", PORT), Handler)
15 | print "Server1: httpd serving at port", PORT
16 | httpd.serve_forever()
17 |
--------------------------------------------------------------------------------
/EduLogging/lesson1/task1/tests.py:
--------------------------------------------------------------------------------
1 | from test_helper import run_common_tests, failed, passed, get_answer_placeholders
2 |
3 |
4 | def test_answer_placeholders():
5 | placeholders = get_answer_placeholders()
6 | for placeholder in placeholders:
7 | if placeholder != "logging.debug":
8 | failed()
9 | return
10 |
11 | passed()
12 |
13 | if __name__ == '__main__':
14 | run_common_tests()
15 | test_answer_placeholders()
16 |
17 |
18 |
--------------------------------------------------------------------------------
/EduLogging/lesson2/task5/task.html:
--------------------------------------------------------------------------------
1 |
2 | When you include an object in your log message, the object's __str__ method is called to return a string value for that object.
3 |
4 |
5 | If you run this task, you will notice the log message contains the __str__ generated string.
6 |
7 |
8 | If you want to use the __repr__ generated string, you will have to explicitly call repr() on your object.
9 |
10 |
11 | In this task, log the __repr__ generated string.
12 |
--------------------------------------------------------------------------------
/EduLogging/lesson2/task6/tests.py:
--------------------------------------------------------------------------------
1 | from test_helper import run_common_tests, failed, passed, get_answer_placeholders
2 |
3 |
4 | def test_answer_placeholders():
5 | placeholders = get_answer_placeholders()
6 | placeholder = placeholders[0]
7 | if placeholder.startswith("truncate(big_list,"):
8 | passed()
9 | else:
10 | failed()
11 |
12 |
13 | if __name__ == '__main__':
14 | run_common_tests()
15 | test_answer_placeholders()
16 |
17 |
18 |
--------------------------------------------------------------------------------
/EduLogging/lesson2/task7/tests.py:
--------------------------------------------------------------------------------
1 | from test_helper import run_common_tests, failed, passed, get_answer_placeholders, check_answers
2 |
3 |
4 | def test_answer_placeholders():
5 | placeholders = get_answer_placeholders()
6 | answers = [
7 | [', "value"', ',"value"', ",'value'", ", 'value'"]
8 | ]
9 | check_answers(placeholders, answers)
10 |
11 |
12 | if __name__ == '__main__':
13 | run_common_tests()
14 | test_answer_placeholders()
15 |
16 |
17 |
--------------------------------------------------------------------------------
/EduLogging/lesson5/task3/tests.py:
--------------------------------------------------------------------------------
1 | from test_helper import run_common_tests, failed, passed, get_answer_placeholders
2 |
3 |
4 | def test_answer_placeholders():
5 | placeholders = get_answer_placeholders()
6 | placeholder = placeholders[0]
7 | if placeholder == "False" or placeholder == '0':
8 | passed()
9 | else:
10 | failed()
11 |
12 |
13 | if __name__ == '__main__':
14 | run_common_tests()
15 | test_answer_placeholders()
16 |
17 |
18 |
--------------------------------------------------------------------------------
/EduLogging/Sandbox/basic_file.log:
--------------------------------------------------------------------------------
1 | 2015-12-05 21:58:26,498 INFO Calling mortgage calculator
2 | 2015-12-05 21:58:26,498 WARNING Term greater than 50 years
3 | 2015-12-05 21:58:26,498 DEBUG Fetching current interest rate for 80 years
4 | 2015-12-05 21:58:26,498 DEBUG Service returned interest rate 5.300000
5 | 2015-12-05 21:58:26,498 DEBUG Number of monthly payments 960
6 | 2015-12-05 21:58:26,499 DEBUG Calculated result is 448.184492
7 | 2015-12-05 21:58:26,499 DEBUG Leaving mortgage calculator
8 |
--------------------------------------------------------------------------------
/EduLogging/lesson1/task8/tests.py:
--------------------------------------------------------------------------------
1 | from test_helper import run_common_tests, failed, passed, get_answer_placeholders
2 |
3 |
4 | def test_answer_placeholders():
5 | placeholders = get_answer_placeholders()
6 | placeholder = placeholders[0].replace('"', "'")
7 | if placeholder == "'mortgage.rate'":
8 | passed()
9 | else:
10 | failed()
11 |
12 |
13 | if __name__ == '__main__':
14 | run_common_tests()
15 | test_answer_placeholders()
16 |
17 |
18 |
--------------------------------------------------------------------------------
/EduLogging/lesson3/task6/tests.py:
--------------------------------------------------------------------------------
1 | from test_helper import run_common_tests, failed, passed, get_answer_placeholders, check_answers
2 |
3 |
4 | def test_answer_placeholders():
5 | placeholders = get_answer_placeholders()
6 | answers = [
7 | ['setLevel(logging.WARNING)', 'setLevel(logging.WARN)']
8 | ]
9 | check_answers(placeholders, answers)
10 |
11 |
12 | if __name__ == '__main__':
13 | run_common_tests()
14 | test_answer_placeholders()
15 |
16 |
17 |
--------------------------------------------------------------------------------
/EduLogging/lesson6/task4/tests.py:
--------------------------------------------------------------------------------
1 | from test_helper import run_common_tests, failed, passed, get_answer_placeholders, check_answers
2 |
3 |
4 | def test_answer_placeholders():
5 | placeholders = get_answer_placeholders()
6 | answers = [
7 | ["file"],
8 | ["file"],
9 | ["file"]
10 | ]
11 | check_answers(placeholders, answers)
12 |
13 |
14 | if __name__ == '__main__':
15 | run_common_tests()
16 | test_answer_placeholders()
17 |
18 |
19 |
--------------------------------------------------------------------------------
/EduLogging/lesson6/task6/tests.py:
--------------------------------------------------------------------------------
1 | from test_helper import run_common_tests, failed, passed, get_answer_placeholders, check_answers
2 |
3 |
4 | def test_answer_placeholders():
5 | placeholders = get_answer_placeholders()
6 | answers = [
7 | ['disable_existing_loggers'],
8 | ['False', 0]
9 | ]
10 | check_answers(placeholders, answers)
11 |
12 |
13 | if __name__ == '__main__':
14 | run_common_tests()
15 | test_answer_placeholders()
16 |
17 |
18 |
--------------------------------------------------------------------------------
/EduLogging/lesson7/task1/tests.py:
--------------------------------------------------------------------------------
1 | from test_helper import run_common_tests, failed, passed, get_answer_placeholders, check_answers
2 |
3 |
4 | def test_answer_placeholders():
5 | placeholders = get_answer_placeholders()
6 | answers = [
7 | ['handler.setFormatter(fmt)', 'handler.setFormatter(fmt=fmt)']
8 | ]
9 | check_answers(placeholders, answers)
10 |
11 | if __name__ == '__main__':
12 | run_common_tests()
13 | test_answer_placeholders()
14 |
15 |
16 |
--------------------------------------------------------------------------------
/sdn/akaedu/ch10/ex10.reverse.c:
--------------------------------------------------------------------------------
1 | /*
2 | 先用字符串"hello"初始化一个字符数组str(算上'\0'共6个字符)。然后用空字符串""初始化一个同样长的字符数组reverse_str,相当于所有元素用'\0'初始化。然后打印str,把str倒序存入reverse_str,再打印reverse_str。然而结果并不正确:
3 | */
4 | #include
5 |
6 | int main(void)
7 | {
8 | int i;
9 | char str[6] = "hello";
10 | char reverse_str[6] = "";
11 |
12 | printf("%s\n", str);
13 | for (i = 0; i < 5; i++)
14 | reverse_str[5-i] = str[i]; // reverse_str[5-i-1] 正确代码
15 | printf("%s\n", reverse_str);
16 | return 0;
17 | }
--------------------------------------------------------------------------------
/sdn/cs144_bufferbloat/run-minq.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | echo "start cs144 buffer bloat experiment"
3 | sudo sysctl -w net.ipv4.tcp_congestion_control=reno
4 | python bufferbloat.py --bw-host 1000 \
5 | --bw-net 1.5 \
6 | --delay 10 \
7 | --dir ./ \
8 | --nflows 1 \
9 | --maxq 20 \
10 | -n 2 \
11 |
12 | echo "cleaning up..."
13 | killall -9 iperf ping
14 | mn -c > /dev/null 2>&1
15 | echo "end"
16 |
--------------------------------------------------------------------------------
/EduLogging/Sandbox/separate_levels.log:
--------------------------------------------------------------------------------
1 | 2015-12-05 22:07:29,490 INFO Calling mortgage calculator
2 | 2015-12-05 22:07:29,491 WARNING Term greater than 50 years
3 | 2015-12-05 22:07:29,491 DEBUG Fetching current interest rate for 80 years
4 | 2015-12-05 22:07:29,492 DEBUG Service returned interest rate 5.300000
5 | 2015-12-05 22:07:29,492 DEBUG Number of monthly payments 960
6 | 2015-12-05 22:07:29,492 DEBUG Calculated result is 448.184492
7 | 2015-12-05 22:07:29,493 DEBUG Leaving mortgage calculator
8 |
--------------------------------------------------------------------------------
/EduLogging/lesson3/task1/tests.py:
--------------------------------------------------------------------------------
1 | from test_helper import run_common_tests, failed, passed, get_answer_placeholders
2 |
3 |
4 | def test_answer_placeholders():
5 | placeholders = get_answer_placeholders()
6 | placeholder = placeholders[0].replace('"', "'")
7 | if placeholder == "filename=log_filename":
8 | passed()
9 | else:
10 | failed()
11 |
12 |
13 | if __name__ == '__main__':
14 | run_common_tests()
15 | test_answer_placeholders()
16 |
17 |
18 |
--------------------------------------------------------------------------------
/EduLogging/lesson3/task2/tests.py:
--------------------------------------------------------------------------------
1 | from test_helper import run_common_tests, failed, passed, get_answer_placeholders
2 |
3 |
4 | def test_answer_placeholders():
5 | placeholders = get_answer_placeholders()
6 | placeholder = placeholders[0]
7 | if placeholder == "w":
8 | passed()
9 | else:
10 | failed()
11 |
12 |
13 | if __name__ == '__main__':
14 | run_common_tests()
15 | test_answer_placeholders() # TODO: uncomment test call
16 |
17 |
18 |
--------------------------------------------------------------------------------
/EduLogging/lesson6/task3/tests.py:
--------------------------------------------------------------------------------
1 | from test_helper import run_common_tests, failed, passed, get_answer_placeholders, check_answers
2 |
3 |
4 | def test_answer_placeholders():
5 | placeholders = get_answer_placeholders()
6 | answers = [
7 | ["root"],
8 | ["root"],
9 | ["handler1"]
10 | ]
11 | check_answers(placeholders, answers)
12 |
13 |
14 | if __name__ == '__main__':
15 | run_common_tests()
16 | test_answer_placeholders()
17 |
18 |
19 |
--------------------------------------------------------------------------------
/EduLogging/lesson7/task1/task.html:
--------------------------------------------------------------------------------
1 |
2 | Writing your log messages out as structured JSON objects allows you to write programs to easily process your logs.
3 |
4 |
5 | In this task, we have created a new object called JSONFormatter that inherits from Formatter. The most important
6 | method to implement is the "format()" method which returns a string to be passed to a Handler.
7 |
8 |
9 | In this task, add the call to set this new formatter on the StreamHandler instance.
10 |
--------------------------------------------------------------------------------
/EduLogging/lesson7/task2/tests.py:
--------------------------------------------------------------------------------
1 | from test_helper import run_common_tests, failed, passed, get_answer_placeholders
2 |
3 |
4 | def test_answer_placeholders():
5 | placeholders = get_answer_placeholders()
6 | placeholder = placeholders[0]
7 | if placeholder == "SmartMemoryHandler(capacity=2, target=file_handler)":
8 | passed()
9 | else:
10 | failed()
11 |
12 |
13 | if __name__ == '__main__':
14 | run_common_tests()
15 | test_answer_placeholders()
16 |
--------------------------------------------------------------------------------
/EduLogging/lesson8/task3/tests.py:
--------------------------------------------------------------------------------
1 | from test_helper import run_common_tests, failed, passed, get_answer_placeholders
2 |
3 |
4 | def test_answer_placeholders():
5 | placeholders = get_answer_placeholders()
6 | placeholder = placeholders[0]
7 | if placeholder == "if logger.isEnabledFor(logging.DEBUG):":
8 | passed()
9 | else:
10 | failed()
11 |
12 |
13 | if __name__ == '__main__':
14 | run_common_tests()
15 | test_answer_placeholders()
16 |
17 |
18 |
--------------------------------------------------------------------------------
/EduLogging/lesson2/task5/tests.py:
--------------------------------------------------------------------------------
1 | from test_helper import run_common_tests, failed, passed, get_answer_placeholders
2 |
3 |
4 | def test_answer_placeholders():
5 | placeholders = get_answer_placeholders()
6 | placeholder = placeholders[0]
7 | if placeholder == "repr(obj)" or placeholder == "obj.__repr__()":
8 | passed()
9 | else:
10 | failed()
11 |
12 |
13 | if __name__ == '__main__':
14 | run_common_tests()
15 | test_answer_placeholders()
16 |
17 |
18 |
--------------------------------------------------------------------------------
/EduLogging/lesson4/task4/tests.py:
--------------------------------------------------------------------------------
1 | from test_helper import run_common_tests, failed, passed, get_answer_placeholders, check_answers
2 |
3 |
4 | def test_answer_placeholders():
5 | placeholders = get_answer_placeholders()
6 | answers = [
7 | ['HTTPHandler'],
8 | ['127.0.0.1:8080'],
9 | ['/']
10 | ]
11 | check_answers(placeholders, answers)
12 |
13 | if __name__ == '__main__':
14 | run_common_tests()
15 | test_answer_placeholders()
16 |
17 |
18 |
--------------------------------------------------------------------------------
/EduLogging/lesson5/task4/tests.py:
--------------------------------------------------------------------------------
1 | from test_helper import run_common_tests, failed, passed, get_answer_placeholders
2 |
3 |
4 | def test_answer_placeholders():
5 | placeholders = get_answer_placeholders()
6 | placeholder = placeholders[0]
7 | if placeholder == "logger3.addHandler(logging.NullHandler())":
8 | passed()
9 | else:
10 | failed()
11 |
12 |
13 | if __name__ == '__main__':
14 | run_common_tests()
15 | test_answer_placeholders()
16 |
17 |
18 |
--------------------------------------------------------------------------------
/EduLogging/lesson8/task4/tests.py:
--------------------------------------------------------------------------------
1 | from test_helper import run_common_tests, failed, passed, get_answer_placeholders
2 |
3 |
4 | def test_answer_placeholders():
5 | placeholders = get_answer_placeholders()
6 | placeholder = placeholders[0]
7 | if placeholder == "logger.addHandler(logging.NullHandler())":
8 | passed()
9 | else:
10 | failed()
11 |
12 |
13 | if __name__ == '__main__':
14 | run_common_tests()
15 | test_answer_placeholders()
16 |
17 |
18 |
--------------------------------------------------------------------------------
/EduLogging/lesson3/task4/tests.py:
--------------------------------------------------------------------------------
1 | from test_helper import run_common_tests, failed, passed, get_answer_placeholders, check_answers
2 |
3 |
4 | def test_answer_placeholders():
5 | placeholders = get_answer_placeholders()
6 | answers = [
7 | ['%(asctime)s %(levelname)s %(message)s'],
8 | ['setFormatter(fmt)']
9 | ]
10 | check_answers(placeholders, answers)
11 |
12 | if __name__ == '__main__':
13 | run_common_tests()
14 | test_answer_placeholders()
15 |
16 |
17 |
--------------------------------------------------------------------------------
/web_framework/mydjango/requirements.txt:
--------------------------------------------------------------------------------
1 | diff-match-patch==20121119
2 | Django==1.9
3 | django-admin-bootstrapped==2.5.7
4 | django-dbbackup==2.3.2
5 | django-filter==0.10.0
6 | django-import-export==0.4.1
7 | django-model-utils==2.4
8 | djangorestframework==3.3.2
9 | ecdsa==0.13
10 | Markdown==2.6.2
11 | MySQL-python==1.2.5
12 | paramiko==1.16.0
13 | pycrypto==2.6.1
14 | Pygments==2.0.2
15 | pytz==2015.7
16 | requests==2.9.0
17 | six==1.10.0
18 | tablib==0.10.0
19 | wechat==0.4.16
20 | wheel==0.24.0
21 |
--------------------------------------------------------------------------------
/EduLogging/Sandbox/file_handler_with_formatter.log:
--------------------------------------------------------------------------------
1 | 2015-12-05 22:02:17,342 INFO Calling mortgage calculator
2 | 2015-12-05 22:02:17,342 WARNING Term greater than 50 years
3 | 2015-12-05 22:02:17,342 DEBUG Fetching current interest rate for 80 years
4 | 2015-12-05 22:02:17,342 DEBUG Service returned interest rate 5.300000
5 | 2015-12-05 22:02:17,342 DEBUG Number of monthly payments 960
6 | 2015-12-05 22:02:17,343 DEBUG Calculated result is 448.184492
7 | 2015-12-05 22:02:17,343 DEBUG Leaving mortgage calculator
8 |
--------------------------------------------------------------------------------
/EduLogging/lesson2/task1/task.html:
--------------------------------------------------------------------------------
1 |
2 | You can customize how each log message is output by specifying a format string.
3 |
4 |
5 | This can be done by passing a "format" keyword argument to the "basicConfig" function.
6 |
7 |
8 | The following format string will output the human readable datetime, the severity level and the log message.
9 |
10 | '%(asctime)s %(levelname)s %(message)s'
11 |
12 |
13 | In this task, pass this format string to the "basicConfig" function.
14 |
--------------------------------------------------------------------------------
/EduLogging/lesson8/task1/task.html:
--------------------------------------------------------------------------------
1 |
2 | Logger instances are typically named by using the __name__ builtin. When you organize your modules into packages,
3 | the logger name hierarchy will reflect the package structure. You can take advantage of this by being selective
4 | about logging levels.
5 |
6 |
7 | When you run a python script directly, the __name__ will take on the value "__main__".
8 |
9 |
10 | In this task, replace the module scoped logger instance using __name__ builtin.
11 |
--------------------------------------------------------------------------------
/ns3/cplusplus.com/ch02_program_structure.cpp:
--------------------------------------------------------------------------------
1 | // my second program in C++
2 | // Source: http://www.cplusplus.com/doc/tutorial/program_structure/
3 |
4 | #include
5 |
6 | int main ()
7 | {
8 | std::cout << "Hello World! ";
9 | std::cout << "I'm a C++ program";
10 | }
11 |
12 | /*
13 | // my second program in C++
14 | #include
15 | using namespace std; // using namspace
16 |
17 | int main ()
18 | {
19 | cout << "Hello World! ";
20 | cout << "I'm a C++ program";
21 | }
22 | */
--------------------------------------------------------------------------------
/web_framework/mydjango/demoapp/templates/d01_first_steps/year_archive.html:
--------------------------------------------------------------------------------
1 | {% extends "doclearn/base.html" %}
2 |
3 | {% block title %}Articles for {{ year }}{% endblock %}
4 |
5 | {% block content %}
6 | Articles for {{ year }}
7 |
8 | {% for article in article_list %}
9 | {{ article.headline }}
10 | {{ article.content }}
11 | By {{ article.reporter.full_name }}
12 | 发表时间 {{ article.pub_date|date:"F j, Y" }}
13 | {% endfor %}
14 | {% endblock %}
--------------------------------------------------------------------------------
/web_framework/mydjango/mydjango/wsgi.py:
--------------------------------------------------------------------------------
1 | """
2 | WSGI config for cuczhongchou project.
3 |
4 | It exposes the WSGI callable as a module-level variable named ``application``.
5 |
6 | For more information on this file, see
7 | https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/
8 | """
9 |
10 | import os
11 |
12 | from django.core.wsgi import get_wsgi_application
13 |
14 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "cuczhongchou.settings")
15 |
16 | application = get_wsgi_application()
17 |
--------------------------------------------------------------------------------
/EduLogging/lesson2/task1/tests.py:
--------------------------------------------------------------------------------
1 | from test_helper import run_common_tests, failed, passed, get_answer_placeholders
2 |
3 |
4 | def test_answer_placeholders():
5 | placeholders = get_answer_placeholders()
6 | placeholder = placeholders[0].replace('"', "'")
7 | if placeholder == "'%(asctime)s %(levelname)s %(message)s'":
8 | passed()
9 | else:
10 | failed()
11 |
12 |
13 | if __name__ == '__main__':
14 | run_common_tests()
15 | test_answer_placeholders()
16 |
17 |
18 |
--------------------------------------------------------------------------------
/EduLogging/lesson4/task1/tests.py:
--------------------------------------------------------------------------------
1 | from test_helper import run_common_tests, failed, passed, get_answer_placeholders, check_answers
2 |
3 |
4 | def test_answer_placeholders():
5 | placeholders = get_answer_placeholders()
6 | answers = [
7 | ['logging.handlers'],
8 | ['logging.handlers.RotatingFileHandler']
9 |
10 | ]
11 | check_answers(placeholders, answers)
12 |
13 |
14 | if __name__ == '__main__':
15 | run_common_tests()
16 | test_answer_placeholders()
17 |
18 |
19 |
--------------------------------------------------------------------------------
/sdn/mininet-tests/pairs/pair_intervals_links.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | sudo ./pair_intervals.py --counts 10,10,10 --time 60 -o results/links10.out
3 | sudo ./pair_intervals.py --counts 20,20,20 --time 60 -o results/links20.out
4 | sudo ./pair_intervals.py --counts 40,40,40 --time 60 -o results/links40.out
5 | sudo ./pair_intervals.py --counts 80,80,80 --time 60 -o results/links80.out
6 |
7 | # orignal
8 | # ./plot_pair_intervals.py --all results/links*.out
9 |
10 | ./plot_pair_intervals.py -lr results/links*.out
11 |
--------------------------------------------------------------------------------
/sdn/ryu-cuc/tests/unit/sample/test_sample1.py:
--------------------------------------------------------------------------------
1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4
2 |
3 | import unittest
4 | from nose.tools import ok_, eq_
5 | # from ryu.app.simple_switch import SimpleSwitch
6 |
7 | import logging
8 |
9 |
10 | LOG = logging.getLogger('ryu.tests.test_sample1')
11 |
12 |
13 | class TestSample1(unittest.TestCase):
14 |
15 | def testS1Func1(self):
16 | LOG.debug('testS1Func1 - START')
17 | ok_(True)
18 |
19 | def testS1Func2(self):
20 | ok_(True)
21 |
--------------------------------------------------------------------------------
/EduLogging/lesson5/task5/tests.py:
--------------------------------------------------------------------------------
1 | from test_helper import run_common_tests, failed, passed, get_answer_placeholders, check_answers
2 |
3 |
4 | def test_answer_placeholders():
5 | placeholders = get_answer_placeholders()
6 | answers = [
7 | ["logging.getLogger()", "logging.root"],
8 | ["handler.addFilter(log_filter)"]
9 | ]
10 | check_answers(placeholders, answers)
11 |
12 |
13 | if __name__ == '__main__':
14 | run_common_tests()
15 | test_answer_placeholders()
16 |
17 |
18 |
--------------------------------------------------------------------------------
/lecture/bit_program_design/08KochDrawV1.py:
--------------------------------------------------------------------------------
1 | #coding:utf-8
2 | #KochDrawV1.py
3 | import turtle
4 | def koch(size, n):
5 | if n == 0:
6 | turtle.fd(size)
7 | else:
8 | for angle in [0, 60, -120, 60]:
9 | turtle.left(angle)
10 | koch(size/3, n-1)
11 | def main():
12 | turtle.setup(800,400)
13 | turtle.penup()
14 | turtle.goto(-300, -50)
15 | turtle.pendown()
16 | turtle.pensize(2)
17 | koch(600,3) # 0阶科赫曲线长度,阶数
18 | # turtle.hideturtle()
19 | main()
--------------------------------------------------------------------------------
/sdn/akaedu/ch10/ex10.5.segm_fault2.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(void)
4 | {
5 | int sum = 0, i = 0;
6 | char input[5];
7 |
8 | scanf("%s", input);
9 | for (i = 0; input[i] != '\0'; i++) {
10 | if (input[i] < '0' || input[i] > '9') {
11 | printf("Invalid input!\n");
12 | sum = -1;
13 | break;
14 | }
15 | sum = sum*10 + input[i] - '0';
16 | }
17 | printf("input=%d\n", sum);
18 | return 0;
19 | } // scanf 输入超长时, 错误发生地址
20 |
21 | /**
22 | ,如果某个函数的局部变量发生访问越界,有可能并不立即产生段错误,而是在函数返回时产生段错误。
23 | */
--------------------------------------------------------------------------------
/web_framework/mydjango/learn/templates/base.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {% block title %}默认标题{% endblock %} - 传媒大学
6 |
7 |
8 |
9 | {% include 'nav.html' %}
10 |
11 |
12 | {% block head_text %}
13 | 此页面模板base_extend.html 从 base.html 继承下来
14 | {% endblock %}
15 |
16 |
17 | {% block content %}
18 | 这里是默认内容,所有继承自这个模板的,如果不覆盖就显示这里的默认内容。
19 | {% endblock %}
20 |
21 | {% include 'bottom.html' %}
22 |
23 |
--------------------------------------------------------------------------------
/EduLogging/lesson5/task5/task.html:
--------------------------------------------------------------------------------
1 |
2 | In a previous task, we showed adding a filter to a Logger object. Since, filters are only applied when the log
3 | method is called on a Logger, the filter has to be added to every logger that needs to have the filter applied. You
4 | can also add a filter to a Handler, and since the log records propagate up the hierarchy, the filter will be applied
5 | by the handler for all log records that reach it.
6 |
7 |
8 | In this task, add the filter to all the handlers on the root logger.
9 |
--------------------------------------------------------------------------------
/EduLogging/lesson8/task6/task.html:
--------------------------------------------------------------------------------
1 |
2 | Writing custom logging decorators can help you cut down on some boilerplate logging code.
3 |
4 |
5 | In this example, we want to have our function "do_work" log when the function starts and finishes and also
6 | include how long it took to execute.
7 |
8 |
9 | We have written an example decorator for you.
10 |
11 |
12 | 1) Add the decorator to the "do_work" function
13 |
14 | 2) Set the appropriate log level to allow us to see the decorator results.
15 |
--------------------------------------------------------------------------------
/sdn/cs144_bufferbloat/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | echo "start cs144 buffer bloat experiment"
3 | sudo sysctl -w net.ipv4.tcp_congestion_control=reno
4 | sudo sysctl -w net.ipv4.tcp_min_tso_segs=1
5 | python bufferbloat.py --bw-host 1000 \
6 | --bw-net 1.5 \
7 | --delay 10 \
8 | --dir ./ \
9 | --nflows 1 \
10 | --maxq 100 \
11 | -n 2 \
12 |
13 | echo "cleaning up..."
14 | killall -9 iperf ping
15 | mn -c > /dev/null 2>&1
16 | echo "end"
17 |
--------------------------------------------------------------------------------
/EduLogging/lesson5/task1/tests.py:
--------------------------------------------------------------------------------
1 | from test_helper import run_common_tests, failed, passed, get_answer_placeholders, check_answers
2 |
3 |
4 | def test_answer_placeholders():
5 | placeholders = get_answer_placeholders()
6 | answers = [
7 | ['addFilter(log_filter)'],
8 | ['addFilter(log_filter)'],
9 | ['addFilter(log_filter)']
10 | ]
11 | check_answers(placeholders, answers)
12 |
13 |
14 | if __name__ == '__main__':
15 | run_common_tests()
16 | test_answer_placeholders()
17 |
18 |
19 |
--------------------------------------------------------------------------------
/EduLogging/lesson8/task7/tests.py:
--------------------------------------------------------------------------------
1 | from test_helper import run_common_tests, failed, passed, get_answer_placeholders
2 |
3 |
4 | def test_answer_placeholders():
5 | placeholders = get_answer_placeholders()
6 | placeholder = placeholders[0]
7 | if placeholder.find('service_address') != -1:
8 | passed()
9 | else:
10 | failed('Sorry that is not correct. Check the Hint for more help.')
11 |
12 |
13 | if __name__ == '__main__':
14 | run_common_tests()
15 | test_answer_placeholders()
16 |
17 |
18 |
--------------------------------------------------------------------------------
/sdn/mininet-tests/pairs/README.md:
--------------------------------------------------------------------------------
1 | ## Running
2 |
3 | TODO:将试验结果参考 dasdn 存放至按日期存放的目录中
4 |
5 | ### 运行试验
6 | ```
7 | ./pair_intervals_links_debug.sh # 测试脚本速度快
8 | ./pair_intervals_links.sh # 普通脚本
9 |
10 | ```
11 |
12 | ### 绘图
13 | ```
14 | 绘制其他图表
15 | ./plot_pair_intervals.py -lrsebc results/links*.out
16 |
17 | 绘制 cpu bar 图 # 速度会慢一些
18 | ./plot_pair_intervals.py -p results/links*.out
19 |
20 |
21 | 不要绘制 iperf 图表, 会出现数据错误
22 | '-i', '--iperf'
23 | ```
24 | # 通过 packetcount.c 读取网络统计信息
25 | cat /proc/stat
26 | cat /proc/net/dev
27 |
--------------------------------------------------------------------------------
/EduLogging/lesson3/task5/tests.py:
--------------------------------------------------------------------------------
1 | from test_helper import run_common_tests, failed, passed, get_answer_placeholders, check_answers
2 |
3 |
4 | def test_answer_placeholders():
5 | placeholders = get_answer_placeholders()
6 | answers = [
7 | ['logging.StreamHandler'],
8 | ['stdout_handler.setFormatter(fmt)'],
9 | ['stdout_handler']
10 | ]
11 | check_answers(placeholders, answers)
12 |
13 |
14 | if __name__ == '__main__':
15 | run_common_tests()
16 | test_answer_placeholders()
17 |
18 |
19 |
--------------------------------------------------------------------------------
/sdn/akaedu/README.md:
--------------------------------------------------------------------------------
1 | # C语言代码预备
2 |
3 | 参考:[Linux C编程一站式学习](http://akaedu.github.io/book/) 完成的Linux代码
4 |
5 | ## 目录
6 |
7 | - chxx: Linux C编程一站式学习 章节目录. 示例代码以 `ex`(example) 开头.
8 | - ch08: 数组与字符串
9 | - ch10: gdb 调试
10 | - ch25: 字符串函数
11 | - ch28: 文件io
12 | - ch37: socket编程:
13 | * tcp服务/客户端: ex.37.tcp_server.c ex.37tcp_client.c
14 | * udp服务/客户端: udp_server.c udp_client.c
15 | * unix_socket服务/客户端(支持echo * 3回写) : unix_server.c unix_client.c
16 | - out: 编译输出的二进制可执行文件
17 | - utils: 工具代码: parse-string-into-argv-argc.c 解析命令行;
18 |
--------------------------------------------------------------------------------
/EduLogging/lesson2/task2/tests.py:
--------------------------------------------------------------------------------
1 | from test_helper import run_common_tests, failed, passed, get_answer_placeholders
2 |
3 |
4 | def test_answer_placeholders():
5 | placeholders = get_answer_placeholders()
6 | placeholder = placeholders[0]
7 | if placeholder == "%a %b %d %Y %I:%M:%S%p":
8 | passed()
9 | else:
10 | failed('Sorry, that is not correct. Check the Hint for the correct answer.')
11 |
12 |
13 | if __name__ == '__main__':
14 | run_common_tests()
15 | test_answer_placeholders()
16 |
17 |
18 |
--------------------------------------------------------------------------------
/EduLogging/lesson3/task3/tests.py:
--------------------------------------------------------------------------------
1 | from test_helper import run_common_tests, failed, passed, get_answer_placeholders, check_answers
2 |
3 |
4 | def test_answer_placeholders():
5 | placeholders = get_answer_placeholders()
6 | answers = [
7 | ['logging.FileHandler(log_filename)', 'logging.FileHandler(filename=log_filename)'],
8 | ['addHandler']
9 | ]
10 | check_answers(placeholders, answers)
11 |
12 |
13 | if __name__ == '__main__':
14 | run_common_tests()
15 | test_answer_placeholders()
16 |
17 |
18 |
--------------------------------------------------------------------------------
/EduLogging/lesson1/task6/task.html:
--------------------------------------------------------------------------------
1 |
2 | In our previous examples, we logged messages with different severity levels using helper functions such as logger.debug()
3 | or logger.warning(). This is the easiest way to log messages.
4 |
5 |
6 | If you need to dynamically change the log level (for example, escalate a warning to an error), then you can use
7 | the Logger "log()" method which takes the level as the first argument.
8 |
9 |
10 | In this task, replace the helper logging functions with the equivalent calls using Logger "log()".
11 |
--------------------------------------------------------------------------------
/EduLogging/lesson8/task6/tests.py:
--------------------------------------------------------------------------------
1 | from test_helper import run_common_tests, failed, passed, get_answer_placeholders
2 |
3 |
4 | def test_answer_placeholders():
5 | placeholders = get_answer_placeholders()
6 | if placeholders[0] == "@logging_decorator":
7 | passed()
8 | else:
9 | failed()
10 |
11 | if placeholders[1] == "level=logging.DEBUG":
12 | passed()
13 | else:
14 | failed()
15 |
16 |
17 | if __name__ == '__main__':
18 | run_common_tests()
19 | test_answer_placeholders()
20 |
21 |
22 |
--------------------------------------------------------------------------------
/ns2/my/README.md:
--------------------------------------------------------------------------------
1 |
2 | 我的 ns-2 代码
3 |
4 | ## 基础环境
5 |
6 | Linux & MacOSX
7 | * `xgraph.py` 链接指向-> `ns3/scratch/my_plot_helper.py` 我们的绘图工具, 用于取代 xgraph 以及 gnuplot
8 | - `ln -sf /opt/PycharmProjects/ArsenalPython/ns3/scratch/my_plot_helper.py /usr/local/bin/xgraph.py `
9 | * MacOSX: 设置 display `sudo ln -sf /usr/bin/open /usr/bin/display` 快速打开图片方法
10 |
11 | ## 运行例子
12 | ```
13 | cd output
14 | ns ../xxxx.tcl
15 | ```
16 |
17 | ## 代码说明
18 | * `monitor-link-usage.tcl` 监测并修改链路带宽利用率
19 | - `xgraph.py -d ratefile0` 查看链路带宽变化
20 | * `monitor-queue.tcl` 监测队列利用率
--------------------------------------------------------------------------------
/EduLogging/lesson1/task4/tests.py:
--------------------------------------------------------------------------------
1 | from test_helper import run_common_tests, failed, passed, get_answer_placeholders
2 |
3 |
4 | def test_answer_placeholders():
5 | placeholders = get_answer_placeholders()
6 | for placeholder in placeholders:
7 | if placeholder != 'logger':
8 | failed('Sorry, that is not correct. Please replace all instances of "logging" with "logger"')
9 | return
10 | passed()
11 |
12 |
13 | if __name__ == '__main__':
14 | run_common_tests()
15 | test_answer_placeholders()
16 |
17 |
18 |
--------------------------------------------------------------------------------
/yun_sdk/baidu/README.md:
--------------------------------------------------------------------------------
1 |
2 | # 自定义TTS库函数
3 |
4 | TTS/tts_lib.py
5 |
6 | ```
7 | class MyTTS(pby.TTS):
8 | """
9 | 重载 TTS类, 依赖于 PyBaiduYuyin, 需要提前安装
10 | 安装方法 source: https://pypi.python.org/pypi/PyBaiduYuyin
11 | pip install PyBaiduYuyin
12 | """
13 | say(): 朗读语音, 原始类支持
14 | save(): 保存tts为文件, 扩展支持
15 | ```
16 |
17 | # 准备
18 |
19 | 预备app key
20 |
21 | ```
22 | ##重命名并 修改 config.py 为你的 app key
23 | mv config.example.py config.py
24 |
25 | ```
26 |
27 | # 运行 tts 例子
28 |
29 | 朗读语音,保存文件
30 | ```
31 | python demo_tts.py
32 | ```
33 |
--------------------------------------------------------------------------------
/sdn/cs144_bufferbloat/run-diff.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | echo "start cs144 buffer bloat experiment"
3 | sudo sysctl -w net.ipv4.tcp_congestion_control=reno
4 | sudo sysctl -w net.ipv4.tcp_min_tso_segs=1
5 | python bufferbloat.py --bw-host 1000 \
6 | --bw-net 1.5 \
7 | --delay 10 \
8 | --dir ./ \
9 | --nflows 1 \
10 | --maxq 100 \
11 | -n 2 \
12 | --diff \
13 |
14 | echo "cleaning up..."
15 | killall -9 iperf ping
16 | mn -c > /dev/null 2>&1
17 | echo "end"
18 |
--------------------------------------------------------------------------------
/EduLogging/lesson3/task2/task.html:
--------------------------------------------------------------------------------
1 |
2 | If you ran the previous task a few times, you will have noticed each time all the log messages were appended to the file.
3 | Sometimes, it is useful to truncate the log file each time you start the program to avoid having to sort through
4 | a large number of old log messages.
5 |
6 |
7 | You can do this by passing a "filemode" keyword argument to "basicConfig()" with a string value of "w".
8 |
9 |
10 | In this task, please change the default log file mode to start a new file each time the program is run.
11 |
--------------------------------------------------------------------------------
/EduLogging/lesson1/task5/tests.py:
--------------------------------------------------------------------------------
1 | from test_helper import run_common_tests, failed, passed, get_answer_placeholders
2 |
3 |
4 | def test_answer_placeholders():
5 | placeholders = get_answer_placeholders()
6 | placeholder = placeholders[0].replace('"', "'")
7 | if placeholder == "logger = logging.getLogger('mortgage.rate')":
8 | passed()
9 | else:
10 | failed('Sorry, that is not correct. Check the Hint for more help.')
11 |
12 |
13 | if __name__ == '__main__':
14 | run_common_tests()
15 | test_answer_placeholders()
16 |
17 |
18 |
--------------------------------------------------------------------------------
/ns2/tcpsuit/analysis/processdata:
--------------------------------------------------------------------------------
1 | mkdir data2
2 | mkdir data3
3 | maxlink=6
4 | maxflow=140
5 | maxlflow=40
6 | echo "processthr.tcl"
7 | $NSDIR/ns processthr.tcl $maxlink $maxflow $maxlflow > processthr.txt
8 | echo "hsflow.tcl"
9 | $NSDIR/ns hsflows.tcl $maxlink $maxflow $maxlflow > hsflows.txt
10 | echo "link.tcl"
11 | $NSDIR/ns link.tcl > links.txt
12 | echo "comp-sep.tcl"
13 | $NSDIR/ns comp-sep.tcl $maxlink $maxflow $maxlflow > comp-sep.txt
14 | echo "comp-mix.tcl"
15 | $NSDIR/ns comp-mix.tcl $maxlink $maxflow $maxlflow > comp-mix.txt
16 | echo "ef.sh"
17 | sh ./ef.sh
18 |
--------------------------------------------------------------------------------
/sdn/.gitignore:
--------------------------------------------------------------------------------
1 | */out/*
2 |
3 |
4 |
5 | cs144_bufferbloat/http/nohup.out
6 | cs144_bufferbloat/index.html
7 | cs144_bufferbloat/iperf-recv.txt
8 | cs144_bufferbloat/iperf.txt
9 |
10 | # defaut ignore mininet-tests results
11 | mininet-tests/*/results
12 |
13 | mininet-tests/cpuiso/cpu/cpumonitor
14 | mininet-tests/cpuiso/cpu/steal_cpu
15 | mininet-tests/cpuiso/cpu/timer
16 | mininet-tests/cpuiso/cpu/cpu-stress
17 | mininet-tests/cpuiso/cpu/gettimeofday
18 |
19 | mininet-tests/udping/results/
20 | mininet-tests/udping/udping
21 |
22 | mininet-tests/pairs/packetcount
23 |
--------------------------------------------------------------------------------
/EduLogging/lesson2/task3/tests.py:
--------------------------------------------------------------------------------
1 | from test_helper import run_common_tests, failed, passed, get_answer_placeholders
2 |
3 |
4 | def test_answer_placeholders():
5 | placeholders = get_answer_placeholders()
6 | placeholder = placeholders[0]
7 | if placeholder == "%(asctime)s %(levelname)s %(module)s %(funcName)s %(message)s":
8 | passed()
9 | else:
10 | failed('Sorry, that is not correct. Check the Hint for the correct answer.')
11 |
12 |
13 | if __name__ == '__main__':
14 | run_common_tests()
15 | test_answer_placeholders()
16 |
17 |
18 |
--------------------------------------------------------------------------------
/web_framework/mydjango/demoapp/migrations/0009_question_checked.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | from __future__ import unicode_literals
3 |
4 | from django.db import models, migrations
5 |
6 |
7 | class Migration(migrations.Migration):
8 |
9 | dependencies = [
10 | ('demoapp', '0008_auto_20150727_1253'),
11 | ]
12 |
13 | operations = [
14 | migrations.AddField(
15 | model_name='question',
16 | name='checked',
17 | field=models.BooleanField(default=False, verbose_name='\u5ba1\u6838'),
18 | ),
19 | ]
20 |
--------------------------------------------------------------------------------
/ns3/misc/non-POD-array.cc:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | // http://ysonggit.github.io/coding/2015/01/01/variable-length-array-for-non-pod-element-type.html
4 | // pod_array.cc:10:8: error: variable length array of non-POD element type 'Foo'
5 |
6 | struct Foo{
7 | std::string val;
8 | };
9 |
10 |
11 | int main(){
12 | int n = 5;
13 |
14 | // not working in MacOSX clang
15 | // Foo a[n];
16 | // const size_t m =10;
17 | // Foo b[m];
18 |
19 | Foo *a = new Foo[n];
20 | delete [] a;
21 | a = NULL; // clear to prevent using invalid memory reference (dangling pointer)
22 | }
--------------------------------------------------------------------------------
/sdn/akaedu/ch10/ex10.3.watch.c:
--------------------------------------------------------------------------------
1 | /**
2 |
3 | 平台相关, 在linux没出现文档的效果.
4 | Source: http://akaedu.github.io/book/ch10s03.html
5 |
6 | 表 10.3. gdb基本命令3
7 |
8 | 命令 描述
9 | watch 设置观察点
10 | info(或i) watchpoints 查看当前设置了哪些观察点
11 | x 从某个位置开始打印存储单元的内容,全部当成字节来看,而不区分哪个字节属于哪个变量
12 | */
13 |
14 | #include
15 |
16 | int main(void)
17 | {
18 | int sum = 0, i = 0;
19 | char input[5];
20 |
21 | while (1) {
22 | sum = 0;
23 | scanf("%s", input);
24 | for (i = 0; input[i] != '\0'; i++)
25 | sum = sum*10 + input[i] - '0';
26 | printf("input=%d\n", sum);
27 | }
28 | return 0;
29 | }
--------------------------------------------------------------------------------
/sdn/cs144_bufferbloat/tc_cmd.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | qlen=$1
4 | rate=1.5Mbit
5 | rate2=1.5Mbit
6 |
7 | function add_qdisc {
8 | dev=$1
9 | tc qdisc del dev $dev root
10 | echo qdisc removed
11 |
12 | tc qdisc add dev $dev root handle 1:0 htb default 1
13 | echo qdisc added
14 |
15 | tc class add dev $dev parent 1:0 classid 1:1 htb rate $rate ceil $rate
16 | echo classes created
17 |
18 | tc qdisc add dev $dev parent 1:1 handle 10: netem delay 10ms limit $qlen
19 |
20 | echo delay added
21 | }
22 |
23 | add_qdisc s0-eth1
24 | add_qdisc s0-eth2
25 |
--------------------------------------------------------------------------------
/ns3/practical_csocket2/README.md:
--------------------------------------------------------------------------------
1 | ## Practical TCP/IP Sockets in C, Second Edition
2 |
3 | Book: http://cs.baylor.edu/~donahoo/practical/CSockets2/
4 |
5 | ```
6 |
7 | 在 Mac 上编译
8 |
9 |
10 | 原始 build
11 | Generally, compilation is as follows:
12 | Linux: gcc -o TCPEchoClient -std=gnu99 TCPEchoClient.c DieWithMessage.c TCPClientUtility.c
13 | Solaris: gcc -o TCPEchoClient TCPEchoClient.c DieWithMessage.c TCPClientUtility.c -lsocket -lnsl
14 | Both: Add -lpthread to both Linux and Solaris for the threads example
15 | ```
16 |
17 | All practical serial: http://cs.baylor.edu/~donahoo/practical/
18 |
--------------------------------------------------------------------------------
/web_framework/mydjango/demoapp/migrations/0006_auto_20150727_1250.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | from __future__ import unicode_literals
3 |
4 | from django.db import models, migrations
5 |
6 |
7 | class Migration(migrations.Migration):
8 |
9 | dependencies = [
10 | ('demoapp', '0005_auto_20150727_1242'),
11 | ]
12 |
13 | operations = [
14 | migrations.AlterField(
15 | model_name='category',
16 | name='sort',
17 | field=models.SmallIntegerField(default=100, verbose_name=b'\xe6\x8e\x92\xe5\xba\x8f'),
18 | ),
19 | ]
20 |
--------------------------------------------------------------------------------
/web_framework/mydjango/demoapp/migrations/0017_auto_20151209_0529.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | from __future__ import unicode_literals
3 |
4 | from django.db import models, migrations
5 |
6 |
7 | class Migration(migrations.Migration):
8 |
9 | dependencies = [
10 | ('demoapp', '0016_auto_20151125_0104'),
11 | ]
12 |
13 | operations = [
14 | migrations.AlterModelOptions(
15 | name='question',
16 | options={'verbose_name': '\u6295\u7968\u95ee\u9898', 'verbose_name_plural': '\u6295\u7968\u95ee\u9898 (Question)'},
17 | ),
18 | ]
19 |
--------------------------------------------------------------------------------
/EduLogging/lesson2/task4/tests.py:
--------------------------------------------------------------------------------
1 | from test_helper import run_common_tests, failed, passed, get_answer_placeholders
2 |
3 |
4 | def test_answer_placeholders():
5 | placeholders = get_answer_placeholders()
6 | placeholder = placeholders[0].replace('"', "'")
7 | if placeholder.startswith("logger.exception(") and placeholder.find("'") != -1:
8 | passed()
9 | else:
10 | failed("That is not correct. Be sure to call exception() with a string argument.")
11 |
12 |
13 | if __name__ == '__main__':
14 | run_common_tests()
15 | test_answer_placeholders()
16 |
17 |
18 |
--------------------------------------------------------------------------------
/web_framework/mydjango/learn/templates/step09.html:
--------------------------------------------------------------------------------
1 |
8 |
9 |
10 |
11 |
19 |
--------------------------------------------------------------------------------
/EduLogging/lesson6/task4/task.html:
--------------------------------------------------------------------------------
1 |
2 | In this task, we are going to add a File Handler object to our root logger instance, in addition to our Stream
3 | Handler.
4 |
5 |
6 | Use the instance name "file" in this task. It could be something else, but all the instances to this object
7 | must be the same.
8 |
9 |
10 | You will notice, under the [handler_file] section, we are specifying a tuple value with the "args" key. The first
11 | value in this tuple is the filename for this instance of the FileHandler. We are also referencing the same instance
12 | of the Formatter used by the StreamHandler.
13 |
--------------------------------------------------------------------------------
/web_framework/mydjango/demoapp/migrations/0007_post_tags.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | from __future__ import unicode_literals
3 |
4 | from django.db import models, migrations
5 |
6 |
7 | class Migration(migrations.Migration):
8 |
9 | dependencies = [
10 | ('demoapp', '0006_auto_20150727_1250'),
11 | ]
12 |
13 | operations = [
14 | migrations.AddField(
15 | model_name='post',
16 | name='tags',
17 | field=models.ManyToManyField(related_name='posts', verbose_name=b'\xe6\xa0\x87\xe7\xad\xbe', to='demoapp.Tag', blank=True),
18 | ),
19 | ]
20 |
--------------------------------------------------------------------------------
/ns2/tcpsuit/README:
--------------------------------------------------------------------------------
1 | TCP Evaluation Suite
2 | Authors: Hideyuki Shimonishi (NEC-Japan)
3 | Cesar Marcondes (UCLA)
4 | M.Y. Sanadidi (UCLA)
5 | Mario Gerla (UCLA)
6 | Padmanabhan Vasu (UCLA)
7 |
8 | Please, follow instruction described in website.
9 | http://netlab.cs.ucla.edu/tcpsuite/
10 |
11 | Enjoy and please contribute,
12 | Cesar Marcondes, UCLA
13 |
14 | DISCLAIMER:
15 |
16 | The original codes were developed by HIDEyuki Shimonishi,
17 | NEC Corp, and were donated by the company to the community.
18 | The codes are now being developed and maintained by both
19 | UCLA and NEC.
20 |
--------------------------------------------------------------------------------
/sdn/mininet-tests/cpuiso/cpu/gettimeofday.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | typedef struct timeval mytime_t;
5 |
6 | mytime_t start, end, temp;
7 |
8 | int main(int c, char *v[]) {
9 | int runs = 100000, i = 0;
10 | if(c > 1) {
11 | runs = atoi(v[1]);
12 | }
13 |
14 | gettimeofday(&start, NULL);
15 | while(i++ < runs) {
16 | gettimeofday(&temp, NULL);
17 | }
18 | gettimeofday(&end, NULL);
19 |
20 | int diff = (end.tv_sec - start.tv_sec) * 1000000;
21 | diff += (end.tv_usec - start.tv_usec);
22 |
23 | printf("%f\n", diff*1.0/runs);
24 | return 0;
25 | }
26 |
27 |
--------------------------------------------------------------------------------
/sdn/tests/test_ovsdb.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | # --*-- coding:utf-8 --*--
3 |
4 | try:
5 | import mock # Python 2
6 | except ImportError:
7 | from unittest import mock # Python 3
8 |
9 | import json
10 | import os
11 | import sys
12 | import warnings
13 | import unittest
14 | import logging
15 | import random
16 |
17 | from sdn.myovsdb import ovsdb_client
18 |
19 | LOG = logging.getLogger('test_ovsdb')
20 |
21 |
22 | class test_ovsdb_client(unittest.TestCase):
23 | def test_get_reposne(self):
24 | self.assertEqual(ovsdb_client.get_resposne() ,'{"id":0,"result":["Open_vSwitch"],"error":null}')
25 |
--------------------------------------------------------------------------------
/web_framework/mydjango/demoapp/migrations/0008_auto_20150727_1253.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | from __future__ import unicode_literals
3 |
4 | from django.db import models, migrations
5 |
6 |
7 | class Migration(migrations.Migration):
8 |
9 | dependencies = [
10 | ('demoapp', '0007_post_tags'),
11 | ]
12 |
13 | operations = [
14 | migrations.AlterField(
15 | model_name='post',
16 | name='tags',
17 | field=models.ManyToManyField(related_name='posts2', verbose_name=b'\xe6\xa0\x87\xe7\xad\xbe', to='demoapp.Tag', blank=True),
18 | ),
19 | ]
20 |
--------------------------------------------------------------------------------
/EduLogging/lesson4/task2/tests.py:
--------------------------------------------------------------------------------
1 | from test_helper import run_common_tests, failed, passed, get_answer_placeholders
2 |
3 |
4 | def test_answer_placeholders():
5 | placeholders = get_answer_placeholders()
6 | placeholder = placeholders[0].replace('"', "'")
7 | if placeholder == "'S'" or placeholder == "'s'":
8 | passed()
9 | else:
10 | failed()
11 |
12 | placeholder = placeholders[1]
13 | if placeholder == "2":
14 | passed()
15 | else:
16 | failed()
17 |
18 | if __name__ == '__main__':
19 | run_common_tests()
20 | test_answer_placeholders()
21 |
22 |
23 |
--------------------------------------------------------------------------------
/EduLogging/lesson5/task3/propagate1.py:
--------------------------------------------------------------------------------
1 | import logging
2 |
3 | if __name__ == '__main__':
4 | logging.basicConfig(level=logging.DEBUG)
5 |
6 | log_filter = logging.Filter('A')
7 |
8 | logger1 = logging.getLogger('A')
9 | logger1.debug('This is written to log output')
10 |
11 | logger2 = logging.getLogger('A.B')
12 | logger2.debug('This is written to log output')
13 |
14 | logger3 = logging.getLogger('B')
15 | logger3.propagate = disable log propagation to parent handlers
16 | logger3.debug('This is NOT written to log output, because only names start with "B" are allowed by filter')
17 |
18 |
--------------------------------------------------------------------------------
/EduLogging/lesson5/task4/null_handler.py:
--------------------------------------------------------------------------------
1 | import logging
2 |
3 | if __name__ == '__main__':
4 | logging.basicConfig(level=logging.DEBUG)
5 |
6 | log_filter = logging.Filter('A')
7 |
8 | logger1 = logging.getLogger('A')
9 | logger1.debug('This is written to log output')
10 |
11 | logger2 = logging.getLogger('A.B')
12 | logger2.debug('This is written to log output')
13 |
14 | logger3 = logging.getLogger('B')
15 | add a null handler to logger3
16 | logger3.propagate = False
17 | logger3.debug('This is NOT written to log output, because only names start with "B" are allowed by filter')
18 |
--------------------------------------------------------------------------------
/EduLogging/lesson8/task2/tests.py:
--------------------------------------------------------------------------------
1 | from test_helper import run_common_tests, failed, passed, get_answer_placeholders
2 |
3 |
4 | def test_answer_placeholders():
5 | placeholders = get_answer_placeholders()
6 | placeholder = placeholders[0]
7 | if placeholder == ".first_class":
8 | passed()
9 | else:
10 | failed()
11 |
12 | placeholder = placeholders[1]
13 | if placeholder == "first_logger.setLevel(logging.DEBUG)":
14 | passed()
15 | else:
16 | failed()
17 |
18 | if __name__ == '__main__':
19 | run_common_tests()
20 | test_answer_placeholders()
21 |
22 |
23 |
--------------------------------------------------------------------------------
/EduLogging/lesson8/task5/task.html:
--------------------------------------------------------------------------------
1 |
2 | Using the right logging severity levels can be very subjective. This is one of the reasons why it's better to
3 | have fewer logging levels. It is important that you try to use the right level, so that
4 | you can set the most appropriate logging level in your application and not have too much information.
5 |
6 |
7 | In this task, there are some example log messages, and based on the message and context, try to pick the right
8 | severity level for each message.
9 |
10 |
11 | Remember, this could be very subjective, so click the Hint button to see what is expected.
12 |
--------------------------------------------------------------------------------
/ns2/dctcp-sigcomm10/Makefile.orig:
--------------------------------------------------------------------------------
1 |
2 | install_deps:
3 | sudo apt-get update
4 | sudo apt-get -y install vlan libssl-dev libncurses5-dev python-matplotlib python-numpy
5 | sudo apt-get -y install build-essential autoconf automake libxmu-dev xorg-dev g++ xgraph
6 | cd ns-2 && tar -xvf ns-allinone-2.34.tar.gz
7 | cd ns-2/ns-allinone-2.34/ && patch -p1 < ../qjump-ns2/ns-allinone-2.34.ubuntu.patch
8 | cd ns-2/ns-allinone-2.34/ && ./install
9 | cd ns-2/ns-allinone-2.34/ns-2.34/ && patch -p1 < ../../qjump-ns2/pfabric.patch && make clean && make
10 | ./bin/make_settings.py
11 |
12 | clean:
13 | rm ${TCL_DIR}/out/*
14 |
15 |
--------------------------------------------------------------------------------
/EduLogging/lesson3/task6/task.html:
--------------------------------------------------------------------------------
1 |
2 | In some use cases you may want to log different severity levels to different handlers.
3 |
4 |
5 | You can do this by calling the "setLevel()" function on the Handler object. Only log messages with this
6 | level or greater will be written to the output stream.
7 |
8 |
9 | In this task, change the StreamHandler logging level to only output WARNING messages or higher.
10 |
11 |
12 | After running this task, you should notice if you load the "separate_levels.log" file, it contains all the
13 | log messages, and the console only showed the one WARN level message.
14 |
--------------------------------------------------------------------------------
/EduLogging/lesson4/task6/tests.py:
--------------------------------------------------------------------------------
1 | from test_helper import run_common_tests, failed, passed, get_answer_placeholders
2 |
3 |
4 | def test_answer_placeholders():
5 | placeholders = get_answer_placeholders()
6 | placeholder = placeholders[0].replace('"', "'")
7 | if placeholder == "'A.B'":
8 | passed()
9 | else:
10 | failed()
11 | placeholder = placeholders[1]
12 | if placeholder == "b_log.removeHandler(handler)":
13 | passed()
14 | else:
15 | failed()
16 |
17 |
18 | if __name__ == '__main__':
19 | run_common_tests()
20 | test_answer_placeholders()
21 |
22 |
23 |
--------------------------------------------------------------------------------
/pythonchallenge/mylib.py:
--------------------------------------------------------------------------------
1 | # -*- coding:utf-8 -*-
2 | """
3 | 常用的library函数定义在这里
4 | filename: mylib.py
5 | author:
6 | version:
7 | """
8 |
9 | def uniq_count(input_str, chunk_size):
10 | """
11 | 分割统计函数,将input_str字符串按check_size分割统计
12 | 便于观察字符串的出现频率
13 | """
14 | chunks, chunk_length = len(input_str), len(input_str)/chunk_size
15 | dict_count={}
16 | for i in range(0, chunks, chunk_size):
17 | tmp_str=input_str[i:i+chunk_size]
18 | if dict_count.has_key(tmp_str):
19 | dict_count[tmp_str]+=1
20 | else:
21 | dict_count[tmp_str]=1
22 | return dict_count
23 |
--------------------------------------------------------------------------------
/sdn/mininet-tests/udping/run_udpong.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | loaded=
3 | up='sudo python udpong.py'
4 |
5 | PLATFORM=`hostname` # was: nf-build2
6 |
7 | #NODES='2 5 10 20 30 40 50 60 80 100 150 200 250 300 350 400 450 500'
8 | #NODES='2 5 10 20'
9 | NODES='2 5 10 20 40 60 80 100'
10 |
11 |
12 | function run {
13 | echo $*
14 | time bash -c "$*"
15 | }
16 |
17 | for N in $NODES; do
18 |
19 | for bw in cfs none; do
20 |
21 | RESULTS_DIR=results/$PLATFORM/udping-$bw$loaded
22 | mkdir -p ${RESULTS_DIR}
23 | run $up $loaded --b $bw -c $N -o $RESULTS_DIR
24 | sleep 3
25 | sudo mn -c
26 | done
27 |
28 | done
29 |
--------------------------------------------------------------------------------
/web_framework/mydjango/demoapp/migrations/0011_auto_20150806_1248.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | from __future__ import unicode_literals
3 |
4 | from django.db import models, migrations
5 |
6 |
7 | class Migration(migrations.Migration):
8 |
9 | dependencies = [
10 | ('demoapp', '0010_auto_20150806_1245'),
11 | ]
12 |
13 | operations = [
14 | migrations.RenameModel(
15 | old_name='Article',
16 | new_name='D01Article',
17 | ),
18 | migrations.RenameModel(
19 | old_name='Reporter',
20 | new_name='D01Reporter',
21 | ),
22 | ]
23 |
--------------------------------------------------------------------------------
/EduLogging/lesson1/task8/task.html:
--------------------------------------------------------------------------------
1 |
2 | When you can organize logging into a hierarchy, you can easily change the logging level at
3 | any point in this structure. This is a powerful way as narrowing your output to certain modules or subsystems.
4 |
5 |
6 | You can change the level in this structure by obtaining the logger instance at that level and calling the
7 | "setLevel" method with the desired log level.
8 |
9 |
10 | In this task, obtain a reference to the "mortgage.rate" logger instance and set its level to DEBUG. When
11 | we run this program, we will see all messages DEBUG level or higher for this logger.
12 |
--------------------------------------------------------------------------------
/lecture/bit_program_design/08KochDrawV2.py:
--------------------------------------------------------------------------------
1 | #coding:utf-8
2 | #KochDrawV2.py
3 | import turtle
4 | def koch(size, n):
5 | if n == 0:
6 | turtle.fd(size)
7 | else:
8 | for angle in [0, 60, -120, 60]:
9 | turtle.left(angle)
10 | koch(size/3, n-1)
11 | def main():
12 | turtle.setup(600,600)
13 | turtle.penup()
14 | turtle.goto(-200, 100)
15 | turtle.pendown()
16 | turtle.pensize(2)
17 | level = 3 # 3阶科赫雪花,阶数
18 | koch(400,level)
19 | turtle.right(120)
20 | koch(400,level)
21 | turtle.right(120)
22 | koch(400,level)
23 | turtle.hideturtle()
24 | main()
--------------------------------------------------------------------------------
/ns2/dctcp/dctcp.patch-README:
--------------------------------------------------------------------------------
1 | This patch applies to ns-2.35 which can be obtained from: http://www.isi.edu/nsnam/ns/ . The patch modifies the following files:
2 | 1) queue/red.cc
3 | 2) tcl/lib/ns-default.tcl
4 | 3) tcp/tcp.cc
5 | 4) tcp/tcp-full.cc
6 | 5) tcp/tcp-full.h
7 | 6) tcp/tcp.h
8 |
9 | To apply the patch, copy "dctcp.patch" to the top ns-2.35 folder and enter:
10 |
11 | patch -p1 --ignore-whitespace -i dctcp.patch
12 |
13 | ---------------------------------------------
14 |
15 | DCTCP is enabled using: Agent/TCP set dctcp_ true
16 |
17 | An example that shows the basic parameter settings is provided at example/simpleDumbbell.tcl .
18 |
19 |
--------------------------------------------------------------------------------
/web_framework/mydjango/demoapp/migrations/0019_auto_20151216_1514.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # Generated by Django 1.9 on 2015-12-16 15:14
3 | from __future__ import unicode_literals
4 |
5 | from django.db import migrations
6 |
7 |
8 | class Migration(migrations.Migration):
9 |
10 | dependencies = [
11 | ('demoapp', '0018_auto_20151216_1503'),
12 | ]
13 |
14 | operations = [
15 | migrations.AlterModelOptions(
16 | name='postadmincheck',
17 | options={'verbose_name_plural': 'Proxy \u6587\u7ae0 \u5bfc\u5165\u5bfc\u51fa ( admin.py \u4e2d\u5feb\u6377\u52a0\u5165)'},
18 | ),
19 | ]
20 |
--------------------------------------------------------------------------------
/lecture/bit_program_design/10CalHamletV1.py:
--------------------------------------------------------------------------------
1 | #coding:utf-8
2 | #CalHamletV1.py
3 | def getText():
4 | txt = open("hamlet.txt", "r").read()
5 | txt = txt.lower()
6 | for ch in '!"#$%&()*+,-./:;<=>?@[\\]^_‘{|}~':
7 | txt = txt.replace(ch, " ") #将文本中特殊字符替换为空格
8 | return txt
9 |
10 | hamletTxt = getText()
11 | words = hamletTxt.split()
12 | counts = {}
13 | for word in words:
14 | counts[word] = counts.get(word,0) + 1
15 | items = list(counts.items())
16 | items.sort(key=lambda x:x[1], reverse=True)
17 | for i in range(10):
18 | word, count = items[i]
19 | print ("{0:<10}{1:>5}".format(word, count))
20 |
--------------------------------------------------------------------------------
/sdn/mininet-tests/buffersizing/README.md:
--------------------------------------------------------------------------------
1 | # buffersizing
2 |
3 | ## 文件说明
4 |
5 | * `.gitignore` 忽略 result 目录; 忽略 verify 目录 (TODO 下一步添加)
6 | * `plot-results.py ` 绘图程序完成3组数值
7 | - 数值1: 公式计算
8 | - 数值2: `nedata2.txt` 绘图中用到的硬件 `Hardware` 数值
9 | - 数值3: `result-buffersizing-xxx` 目录下的 result.txt
10 | - 平均计算方法: 如运行多轮 -r1 -r2 -r3 , 则将数据放入 list [r1, r2, r3] 中, 然后取平均值
11 |
12 | ## 运行方法
13 |
14 | 1. `build-patched-iperf.sh` 在 $HOME 路径下安装 patched iperf.
15 | 1. `sudo service openvswitch-switch start` 启动 ovs 交换机
16 | 1. `sudo ./buffersizing-sweep.sh` 运行脚本; 在对应的 `result-buffersizing-xxx` trace 目录下生成了 `result.png`
17 | 1. 如果绘图执行失败. 可以 `$rootdir` 重新执行绘图程序
18 |
19 |
--------------------------------------------------------------------------------
/sdn/akaedu/ch10/Makefile:
--------------------------------------------------------------------------------
1 | # -g 运行调试
2 | # CFLAGS = -g -Wall -O3
3 | # CFLAGS = -g -O3 -w # disable warning
4 | CFLAGS = -g # 如果用-O3编译, gdb将不支持 set val 操作
5 |
6 | #%.o: %.c
7 | # $(CC) -c $<
8 |
9 | all: ex10.1.add ex10.2.break ex10.reverse \
10 | ex10.3.watch \
11 | ex10.4.segm_fault ex10.5.segm_fault2
12 |
13 |
14 | # 编译可执行文件到上一级./bin/目录 $@ 表示规则中的目标
15 | # ex25.2.strok:
16 | # $(CC) $@.c -o ../out/$@
17 |
18 | # 编译.o 文件, 下面这句为默认策略, 可省略
19 | # ex25.2.strok.o:
20 |
21 | clean:
22 | rm -f *.o
23 | rm -f ex10.1.add
24 | rm -f ex10.2.break
25 | rm -f ex10.reverse
26 | rm -f ex10.3.watch
27 | rm -f ex10.4.segm_fault
28 | rm -f ex10.5.segm_fault2
--------------------------------------------------------------------------------
/EduLogging/lesson6/task6/task.html:
--------------------------------------------------------------------------------
1 |
2 | In the previous task, only the root logger message was included in the output.
3 |
4 |
5 | This is because we created our "logger" instance at module scope, before we called dictConfig().
6 | When dictConfig() was called it disabled any existing loggers. This is the default setting, but you
7 | can override this with the "disable_existing_loggers" key set to the value of "False", within the
8 | configuration dictionary.
9 |
10 |
11 | Update the configuration to prevent existing loggers from being disabled.
12 |
13 |
14 | After you execute this task, you should see all the log output.
15 |
16 |
--------------------------------------------------------------------------------
/lecture/bit_program_design/05CalBMI.py:
--------------------------------------------------------------------------------
1 | #coding:utf-8
2 | #CalBMIv3.py
3 | for x in range(3): # 多测试几次
4 | height, weight = eval(input("请输入身高(厘米)和体重(公斤)[逗号隔开]: "))
5 | bmi = weight / pow(height / 100.0 , 2)
6 | print("BMI 数值为:{:.2f}".format(bmi))
7 | who, nat = "", ""
8 | if bmi < 18.5:
9 | who, nat = "偏瘦", "偏瘦"
10 | elif 18.5 <= bmi < 24:
11 | who, nat = "正常", "正常"
12 | elif 24 <= bmi < 25:
13 | who, nat = "正常", "偏胖"
14 | elif 25 <= bmi < 28:
15 | who, nat = "偏胖", "偏胖"
16 | elif 28 <= bmi < 30:
17 | who, nat = "偏胖", "肥胖" # 测试用例 180, 95
18 | else:
19 | who, nat = "肥胖", "肥胖"
20 | print("BMI 指标为:国际'{0}', 国内'{1}'".format(who, nat))
--------------------------------------------------------------------------------
/EduLogging/lesson1/task1/task.html:
--------------------------------------------------------------------------------
1 |
2 | The following code is typical of how many people start debugging their programs using the "print" function.
3 |
4 |
5 | The problem with using "print" to output debugging information, is it does not work well in
6 | larger programs. The debug output interferes with application output and you typically end up commenting out or
7 | removing all this extra code when you are not debugging.
8 |
9 |
10 | The standard logging module provides an easy way to separate application output from debug output.
11 |
12 |
13 | In this task, replace the highlighted "print" function calls with calls to "logging.debug".
14 |
--------------------------------------------------------------------------------
/stdmod/unittest/mylib/primes.py:
--------------------------------------------------------------------------------
1 | # REF: https://www.jeffknupp.com/blog/2013/12/09/improve-your-python-understanding-unit-testing/
2 |
3 |
4 | def is_prime(number):
5 | """Return True if *number* is prime."""
6 |
7 | if number < 1:
8 | return False
9 |
10 | for element in range(2, number):
11 | if number % element == 0:
12 | return False
13 |
14 | return True
15 |
16 |
17 | def print_next_prime(number):
18 | """Print the closest prime number larger than *number*."""
19 | index = number
20 | while True:
21 | index += 1
22 | if is_prime(index):
23 | print(index)
24 | break
25 |
--------------------------------------------------------------------------------
/web_framework/mydjango/learn/migrations/0001_initial.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | from __future__ import unicode_literals
3 |
4 | from django.db import models, migrations
5 |
6 |
7 | class Migration(migrations.Migration):
8 |
9 | dependencies = [
10 | ]
11 |
12 | operations = [
13 | migrations.CreateModel(
14 | name='Person',
15 | fields=[
16 | ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
17 | ('name', models.CharField(max_length=30)),
18 | ('age', models.IntegerField()),
19 | ],
20 | ),
21 | ]
22 |
--------------------------------------------------------------------------------
/web_framework/web_py_examples.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 |
4 | import web
5 |
6 | class index:
7 | def GET(self):
8 | #STEP1 simple hello
9 | #return "Hello, world!"
10 |
11 | #STEP2 using template
12 | #name = "Zheng Chen"
13 | #name = ""
14 | #return render.index(name)
15 |
16 | #STEP3
17 | i = web.input(name1=None)
18 | return render.index(i.name1) #为什么该成name1了,在页面中仍然还能识别呢?
19 |
20 |
21 |
22 | urls = ('/', 'index')
23 | app = web.application(urls, globals())
24 | render = web.template.render('web_py_templates/')
25 |
26 |
27 | if __name__ == "__main__":
28 | app.run()
29 |
--------------------------------------------------------------------------------
/EduLogging/lesson8/task5/tests.py:
--------------------------------------------------------------------------------
1 | from test_helper import run_common_tests, failed, passed, get_answer_placeholders, check_answers
2 |
3 |
4 | def test_answer_placeholders():
5 | placeholders = get_answer_placeholders()
6 |
7 | answers = [
8 | ['INFO', 'DEBUG', 'WARN', 'WARNING'],
9 | ['ERROR', 'CRITICAL', 'FATAL'],
10 | ['INFO', 'DEBUG'],
11 | ['WARN', 'WARNING'],
12 | ['CRITICAL', 'FATAL'],
13 | ['DEBUG']
14 | ]
15 | check_answers(placeholders, answers)
16 |
17 |
18 | if __name__ == '__main__':
19 | run_common_tests()
20 | test_answer_placeholders() # TODO: uncomment test call
21 |
22 |
23 |
--------------------------------------------------------------------------------
/ns2/tcpsuit/analysis/link_graph.gpl:
--------------------------------------------------------------------------------
1 | set terminal png
2 | set output 'links.png'
3 | set yrange [0:900]
4 | set xrange [0:7]
5 |
6 | set data style boxes
7 | set border 6
8 | set boxwidth 0.4
9 | set xtics ("HS+RENO" 2.2, "HS+HS" 5.4)
10 | set ylabel "Average Throughput All Core Links"
11 | set grid
12 | plot 'links.dat' using ($1-0.8):($2) fs solid 1 title "RenoReno",\
13 | 'links.dat' using ($1-0.4):($3) fs solid 2 title "Compound",\
14 | 'links.dat' using ($1):($4) fs solid 3 title "Cubic",\
15 | 'links.dat' using ($1+0.4):($5) fs solid 4 title "Htcp",\
16 | 'links.dat' using ($1+0.8):($6) fs solid 5 title "WWar",\
17 | 'links.dat' using ($1+1.2):($7) fs solid 6 title "Areno"
18 |
--------------------------------------------------------------------------------
/EduLogging/lesson1/task3/tests.py:
--------------------------------------------------------------------------------
1 | from test_helper import run_common_tests, failed, passed, get_answer_placeholders
2 |
3 |
4 | def test_answer_placeholders():
5 | placeholders = get_answer_placeholders()
6 | placeholder = placeholders[0]
7 | if placeholder == "info":
8 | passed()
9 | else:
10 | failed('Sorry, that is not correct. Please use the info() method.')
11 |
12 | if placeholders[1].startswith('logging.warn'):
13 | passed()
14 | else:
15 | failed('Sorry, that is not correct. Place use the warn() method.')
16 |
17 | if __name__ == '__main__':
18 | run_common_tests()
19 | test_answer_placeholders()
20 |
21 |
22 |
--------------------------------------------------------------------------------
/EduLogging/lesson5/task5/filtering_handler.py:
--------------------------------------------------------------------------------
1 | import logging
2 |
3 | if __name__ == '__main__':
4 | logging.basicConfig(level=logging.DEBUG)
5 |
6 | log_filter = logging.Filter('A')
7 |
8 | root = get the root logger
9 | for handler in root.handlers:
10 | add the filter to each handler
11 |
12 | logger1 = logging.getLogger('A')
13 | logger1.debug('This is written to log output')
14 |
15 | logger2 = logging.getLogger('A.B')
16 | logger2.debug('This is written to log output')
17 |
18 | logger3 = logging.getLogger('B')
19 | logger3.debug('This is NOT written to log output, because only names start with "B" are allowed by filter')
20 |
21 |
--------------------------------------------------------------------------------
/ns2/tcpsuit/topology_generator/process_graph.sh:
--------------------------------------------------------------------------------
1 | #process_dir="long_lived30"
2 | process_dir=$1
3 | vector="1 2 3 4 5 6 7 8 9 10 11 12"
4 | echo "cd $process_dir"
5 | for i in $vector
6 | do
7 | echo "cp ../parsing_flowf.pl ."
8 | echo "cp ../parsing_flowr.pl ."
9 | echo "cp ../parsing_overf.pl ."
10 | echo "perl parsing_flowf.pl $i > seed"$i"_clusterf.dot"
11 | echo "perl parsing_flowr.pl $i > seed"$i"_clusterr.dot"
12 | echo "perl parsing_overf.pl $i > seed"$i"_overallf.dot"
13 | echo "dot -Tpng -o s"$i"cf.png seed"$i"_clusterf.dot"
14 | echo "dot -Tpng -o s"$i"cr.png seed"$i"_clusterr.dot"
15 | echo "dot -Tpng -o s"$i"of.png seed"$i"_overallf.dot"
16 | done
17 | echo "cd .."
18 |
--------------------------------------------------------------------------------
/EduLogging/lesson4/task3/task.html:
--------------------------------------------------------------------------------
1 |
2 | The MemoryHandler is a special handler that provides buffering of log messages until it the specified capacity
3 | or a specified severity level. At that time, the buffered log messages are sent to another Handler.
4 |
5 |
6 | If you wanted to limit disk activity from the logger to less frequent intervals, the MemoryHandler is useful.
7 |
8 |
9 | MemoryHandler is defined in the "logging.handlers" module. It takes a "capacity" argument which is the
10 | number of log records, and a target which is an instance of another file handle.
11 |
12 |
13 | In this task, configure the MemoryHandler to use the FileHandler object.
14 |
--------------------------------------------------------------------------------
/douban_kdd/README.md:
--------------------------------------------------------------------------------
1 | #豆瓣数据挖掘
2 |
3 | ## 安装
4 | MongoDB 使用 Robo 3T 客户端 ( 待更换, 因为暂时不支持 Query 功能 )
5 |
6 | ## 运行环境
7 | ```
8 | Python 2.7.13 :: Anaconda 4.3.1 (x86_64)
9 | MongoDB: 4.0.1 客户端: NoSQLBooster
10 | ```
11 |
12 | ## 运行方法
13 | 启动 mongodb, 参考 http://www.runoob.com/mongodb/mongodb-query.html 使用命令行查询
14 | 执行 `python douban_main.py` 循环抓取 douban 即将上映数据, 存放至 test 库当中
15 |
16 | ## 依赖类
17 | * `douban_client.py` 豆瓣爬虫的 api 类 ,获取 json 数据(201808:douban API 错误由 403 修改为 400)
18 | * `douban_mongo.py` 豆瓣爬虫的 model 类, 存储数据至 mongo 中
19 |
20 |
21 | ## 基础程序
22 | ```
23 | mongo_demo.py mongodb 的参考持久化代码参考测试, 参考官网: https://docs.mongodb.org/getting-started/python/ 在 test 库中插入 restaurants 数据
24 | ```
25 |
26 |
--------------------------------------------------------------------------------
/sdn/myovsdb/ovsdb_client.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | # --*-- coding:utf-8 --*--
3 |
4 | # Source https://fredhsu.wordpress.com/2013/10/15/ovsdb-client-in-python/
5 |
6 | import socket
7 |
8 | OVSDB_IP = '127.0.0.1'
9 | OVSDB_PORT = 6632
10 |
11 | def get_socket():
12 | s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
13 | s.connect((OVSDB_IP, OVSDB_PORT))
14 | return s
15 |
16 | import json
17 |
18 | def get_resposne():
19 | s=get_socket()
20 | list_dbs_query = {"method":"list_dbs", "params":[], "id": 0}
21 | s.send(json.dumps(list_dbs_query))
22 | response = s.recv(4096)
23 | return response
24 |
25 | if __name__ == '__main__':
26 | print get_resposne()
--------------------------------------------------------------------------------
/stdmod/unittest/test_mylib/sub/test_string.py:
--------------------------------------------------------------------------------
1 | #REF: https://docs.python.org/2/library/unittest.html
2 |
3 | import unittest
4 |
5 | class TestStringMethods(unittest.TestCase):
6 |
7 | def test_upper(self):
8 | self.assertEqual('foo'.upper(), 'FOO')
9 |
10 | def test_isupper(self):
11 | self.assertTrue('FOO'.isupper())
12 | self.assertFalse('Foo'.isupper())
13 |
14 | def test_split(self):
15 | s = 'hello world'
16 | self.assertEqual(s.split(), ['hello', 'world'])
17 | # check that s.split fails when the separator is not a string
18 | with self.assertRaises(TypeError):
19 | s.split(2)
20 |
21 | if __name__ == '__main__':
22 | unittest.main()
--------------------------------------------------------------------------------
/web_framework/mydjango/cucMsg/user.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | from dingding.enterprise import DingDingApi
4 | from config import DingTalkConfig
5 |
6 | def getDepts(ddApi):
7 | """
8 | :type ddApi: DingDingApi
9 | :rtype:
10 | """
11 | depts, apiErr = ddApi.departments()
12 | print type(depts), depts
13 | #for key, value in depts.iteritems():
14 | # print key, value
15 | if len(depts)>0: depts = depts["department"]
16 | for dept in depts:
17 | print dept
18 |
19 | ##初始化
20 | ddApi = DingDingApi(DingTalkConfig.CorpID, DingTalkConfig.CorpSecret)
21 |
22 | ##获取token
23 | print ddApi.get_access_token()
24 |
25 | #获取部门
26 | getDepts(ddApi)
27 |
--------------------------------------------------------------------------------
/EduLogging/lesson2/task4/task.html:
--------------------------------------------------------------------------------
1 |
2 | When an exception occurs, it's useful to include the entire traceback in your log file for diagnosing problems.
3 |
4 |
5 | You can use the "exception()" function on the Logger instance to gather the traceback information and do the
6 | formatting for you. It's similar to the "debug()" function, except you should only call "exception()" from an
7 | exception handler.
8 |
9 |
10 | The following code generates an exception. Replace the call to "pass" with a call to log the exception instead. This
11 | will also allow the exception to propagate up to the caller. This is usually better in this case, instead of silently
12 | catching any exception.
13 |
--------------------------------------------------------------------------------
/sdn/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | ## 相关实验
4 |
5 | * `cs144_bufferbloat/` mininet bufferbloat实验参考 https://github.com/mininet/mininet/wiki/Bufferbloat
6 | * `ipc-bench-master/` ipc 性能测试代码
7 | * `mininet-cuc/` mininet ecn 实验代码
8 | * `mininet-tests/` mininet 测试与plot实验参考 https://github.com/mininet/mininet-tests
9 | * `myovsdb/` ovsdb 连接代码 [Simple Socket Client](https://fredhsu.wordpress.com/2013/10/15/ovsdb-client-in-python/)
10 |
11 |
12 | ## 相关教程
13 | * `akaedu/` c++ 入门
14 |
15 | ## 收集 ryu 代码
16 |
17 | 收集命令
18 | ```
19 | cd ~/PycharmProjects/ryu
20 | git branch zhchen #切换至 zhchen 分支
21 | cd PycharmProjects/
22 | mkdir -p ArsenalPython/sdn/ryu-cuc
23 | rsync -avv ryu/cuc/ ArsenalPython/sdn/ryu-cuc
24 | ```
25 |
26 |
--------------------------------------------------------------------------------
/EduLogging/lesson1/task6/tests.py:
--------------------------------------------------------------------------------
1 | from test_helper import run_common_tests, failed, passed, get_answer_placeholders, check_answers
2 |
3 |
4 | def test_answer_placeholders():
5 | answers = [
6 | ['logger.log(logging.DEBUG,'],
7 | ['logger.log(logging.DEBUG,'],
8 | ['logger.log(logging.INFO,'],
9 | ['logger.log(logging.WARN,', 'logger.log(logging.WARNING,'],
10 | ['logger.log(logging.DEBUG,'],
11 | ['logger.log(logging.DEBUG,'],
12 | ['logger.log(logging.DEBUG,']
13 | ]
14 |
15 | check_answers(get_answer_placeholders(), answers)
16 |
17 |
18 | if __name__ == '__main__':
19 | run_common_tests()
20 | test_answer_placeholders()
21 |
22 |
--------------------------------------------------------------------------------
/ns2/ns_by_example/dtrr-queue.h:
--------------------------------------------------------------------------------
1 | //
2 | // Author: Jae Chung
3 | // File: dtrr-queue.h
4 | // Written: 07/19/99 (for ns-2.1b4a)
5 | // Modifed: 10/14/01 (for ns-2.1b8a)
6 | //
7 |
8 | #include
9 | #include "queue.h"
10 | #include "address.h"
11 |
12 |
13 | class DtRrQueue : public Queue {
14 | public:
15 | DtRrQueue() {
16 | q1_ = new PacketQueue;
17 | q2_ = new PacketQueue;
18 | pq_ = q1_;
19 | deq_turn_ = 1;
20 | }
21 |
22 | protected:
23 | void enque(Packet*);
24 | Packet* deque();
25 |
26 | PacketQueue *q1_; // First FIFO queue
27 | PacketQueue *q2_; // Second FIFO queue
28 | int deq_turn_; // 1 for First queue 2 for Second
29 | };
30 |
--------------------------------------------------------------------------------
/EduLogging/lesson5/task1/filter.py:
--------------------------------------------------------------------------------
1 | import logging
2 |
3 | if __name__ == '__main__':
4 | logging.basicConfig(level=logging.DEBUG)
5 |
6 | log_filter = logging.Filter('A')
7 |
8 | logger1 = logging.getLogger('A')
9 | logger1.add the filter object to this logger
10 | logger1.debug('This is written to log output')
11 |
12 | logger2 = logging.getLogger('A.B')
13 | logger2.add the filter object to this logger
14 | logger2.debug('This is written to log output')
15 |
16 | logger3 = logging.getLogger('B')
17 | logger3.add the filter object to this logger
18 | logger3.debug('This is NOT written to log output, because only names start with "B" are allowed by filter')
19 |
20 |
--------------------------------------------------------------------------------
/EduLogging/lesson2/task7/task.html:
--------------------------------------------------------------------------------
1 |
2 | As a Python developer, you are probably familiar with string formatting (or interpolation) using the "%" operator. For example:
3 |
4 |
5 | "Hello, %s" % ("John", )
6 |
7 |
8 | will return the string result:
9 |
10 |
11 | "Hello, John"
12 |
13 |
14 | You may have noticed in some of our logging statements, we pass the string values separately, instead of using this style.
15 |
16 |
17 | This has the advantage that no time is spent formatting a string if the log message is going to be filtered out
18 | by the current severity level.
19 |
20 |
21 | Update this second logging call to pass the string value as an argument.
22 |
23 |
--------------------------------------------------------------------------------
/douban_kdd/douban_ipython.py:
--------------------------------------------------------------------------------
1 | # coding: utf-8
2 |
3 | """
4 | 使用 hist magic 保存 ipython 命令, 便于命令行调试
5 | %hist
6 | """
7 |
8 | import time
9 | from datetime import datetime
10 | from douban_client import DoubanClient
11 | from douban_mongo import StorageClient
12 | import logging
13 |
14 | log = logging.getLogger(__name__)
15 |
16 | level = logging.WARNING
17 | level = logging.DEBUG
18 | logging.basicConfig(format='%(name)s \t\t%(levelname)-8s %(filename)8s %(funcName)8s() [%(message)-60s] %(module)s',
19 | level=level)
20 | douban_client = DoubanClient()
21 | mongo_client = StorageClient()
22 | content, error = douban_client.movie_in_theaters()
23 |
24 | type(content)
25 | print("将这些代码复制到 ipython 中,便于调试 ..")
--------------------------------------------------------------------------------
/ns2/tcpsuit/topology_generator/execute.sh:
--------------------------------------------------------------------------------
1 | # NSDIR="/home/cesar/ns-allinone-2.31/ns-2.31"
2 | TOPO="parking"
3 | NW_SIZE="5"
4 | CAPACITY="1000"
5 | DELAY="15"
6 | SHORT_LIVED="0"
7 | LONG_LIVED="40"
8 | SEEDS="1 2 3 4 5 6 7 8 9 10 11 12"
9 |
10 | for l in $LONG_LIVED
11 | do
12 | mkdir model
13 | for c in $SEEDS
14 | do
15 | echo "nlong_lived=$l seed=$c"
16 | $NSDIR/ns topogen.tcl $TOPO $NW_SIZE 0 $CAPACITY $DELAY $l $SHORT_LIVED p2p
17 | size=$((NW_SIZE-1))
18 | perl ./generate_link.pl $size
19 | mv model-flow model/flow-$c
20 | mv model-link model/link-$c
21 | mv model-rtt model/rtt-$c
22 | mv model-topology model/topology-$c
23 | done
24 | mv model slived_$SHORT_LIVED\_llived$l
25 | sleep 2
26 | done
27 |
--------------------------------------------------------------------------------
/lecture/bit_program_design/12GovRptWordCloudv1.py:
--------------------------------------------------------------------------------
1 | #GovRptWordCloudv1.py
2 | import jieba
3 | import wordcloud
4 | import os
5 |
6 | src_file="threekingdoms.txt"
7 | src_file="12test.txt"
8 |
9 | f = open(src_file, "r", encoding="utf-8")
10 |
11 | t = f.read()
12 | f.close()
13 | ls = jieba.lcut(t)
14 |
15 | txt = " ".join(ls)
16 | w = wordcloud.WordCloud( \
17 | width = 1000, height = 700,\
18 | background_color = "white",
19 | # 设置正确的字体目录,避免 “OSError: cannot open resource” 错误
20 | # Windows
21 | # font_path = "msyh.ttc"
22 | # Mac
23 | font_path = "/Library/Fonts/Songti.ttc"
24 | )
25 | w.generate(txt)
26 | w.to_file("12grwordcloud.png")
27 | os.system("open 12grwordcloud.png")
28 |
--------------------------------------------------------------------------------
/ns2/tcpsuit/topology_generator/execute2.sh:
--------------------------------------------------------------------------------
1 | TOPO="random"
2 | NW_SIZE="3"
3 | CAPACITY="1000"
4 | DELAY="3"
5 | SHORT_LIVED="100"
6 | LONG_LIVED="40"
7 | SEEDS="1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30"
8 |
9 | for l in $LONG_LIVED
10 | do
11 | mkdir model
12 | for c in $SEEDS
13 | do
14 | echo "nlong_lived=$l seed=$c"
15 | $NSDIR/ns topogen.tcl $TOPO $NW_SIZE 2 $CAPACITY $DELAY $l $SHORT_LIVED p2p
16 | size=$((NW_SIZE-1))
17 | perl ./generate_link.pl $size
18 | mv model-flow model/flow-$c
19 | mv model-link model/link-$c
20 | mv model-rtt model/rtt-$c
21 | mv model-topology model/topology-$c
22 | done
23 | mv model slived_$SHORT_LIVED\_llived$l
24 | sleep 2
25 | done
26 |
--------------------------------------------------------------------------------
/lecture/bit_program_design/06CalPi.py:
--------------------------------------------------------------------------------
1 | #coding:utf-8
2 | #CalPiV1.py
3 | pi = 0
4 | N = 100
5 | for k in range(N):
6 | pi += 1/pow(16,k)*( \
7 | 4/(8*k+1) - 2/(8*k+4) - \
8 | 1/(8*k+5) - 1/(8*k+6) )
9 | print("公式法:\n 圆周率值是: {}".format(pi))
10 |
11 |
12 |
13 | #CalPiV2.py
14 | from random import random
15 | from time import perf_counter
16 | DARTS = 1000*1000
17 | hits = 0.0
18 | start = perf_counter()
19 | for i in range(1, DARTS+1):
20 | x, y = random(), random()
21 | dist = pow(x ** 2 + y ** 2, 0.5)
22 | if dist <= 1.0:
23 | hits = hits + 1
24 | pi = 4 * (hits/DARTS)
25 | print("蒙特卡罗方法:\n 圆周率值是: {}".format(pi), end="")
26 | print(" 此方法运行时间是: {:.5f}s".format(perf_counter() - start))
--------------------------------------------------------------------------------
/ns2/tcpsuit/experiment_executor/scenarios.sh:
--------------------------------------------------------------------------------
1 | prot=$1
2 | version="1 2 3 4 5 6 7"
3 |
4 | for i in $version
5 | do
6 | mkdir data
7 | mkdir data4
8 | exp=$prot$i
9 | sh ./submit_batch$i.sh
10 | counter=0
11 | name=`date`
12 |
13 | while [ 1 ]
14 | do
15 | test=`ps -ef | grep ns | wc -l`
16 |
17 | if [ "$test" -ge 3 ]; then
18 | let counter=counter+1
19 | echo "minutes = $counter"
20 | sleep 60
21 | else
22 | echo "experiment $exp done in $counter minutes" | mail -s "experiment $name" youremailhere@youdomain.edu
23 | break;
24 | fi
25 | done
26 |
27 | mkdir data5
28 | mkdir $exp
29 | gzip *.output
30 | mv *.output.gz data5
31 | mv data $exp
32 | mv data4 $exp
33 | mv data5 $exp
34 | done
35 |
--------------------------------------------------------------------------------
/sdn/mininet-tests/dasdn/README.md:
--------------------------------------------------------------------------------
1 |
2 | ##Required
3 | * termcolor # 输出命令时可显示队列颜色
4 | ```
5 | pip install termcolor
6 | ```
7 | * ../util
8 | ```
9 | git clone https://github.com/mininet/mininet-util.git ../util
10 | ```
11 | * bwm-ng # 带宽监测
12 | ```
13 | git clone https://github.com/vgropp/bwm-ng.git
14 | cd bwm-ng/
15 | ./autogen.sh && make && sudo make install
16 | ```
17 |
18 | ## Running
19 |
20 | ```
21 |
22 | sudo ./run.sh # 运行5个节点完整实验(时间较长),收集数据,绘图
23 | sudo ./run-debug.sh # 运行2个节点部分实验(时间短),进入 CLI,自定义收集数据,绘图
24 |
25 | 线程 monitor_thread_switch_bw() 在 [10, 20] 将调整带宽从 50m 到 100m , 然后恢复
26 |
27 | sudo ./run-no-switch-bw.sh # 不切换带宽的测试
28 |
29 | # 绘图结果
30 | ./results/dasdn-Mar16-23\:10/rate.png
31 |
32 |
33 |
34 | ```
35 |
--------------------------------------------------------------------------------
/stdmod/unittest/test_mylib/test_rm_nomock.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 |
4 | """
5 | 普通的 unit 测试
6 | """
7 |
8 | from mylib.rm_module import rm
9 |
10 | import os.path
11 | import tempfile
12 | import unittest
13 |
14 | class RmTestCase(unittest.TestCase):
15 |
16 | tmpfilepath = os.path.join(tempfile.gettempdir(), "tmp-testfile")
17 |
18 | def setUp(self):
19 | with open(self.tmpfilepath, "wb") as f:
20 | f.write("Delete me!")
21 |
22 | def test_rm(self):
23 | # remove the file
24 | rm(self.tmpfilepath)
25 | # test_mylib that it was actually removed
26 | self.assertFalse(os.path.isfile(self.tmpfilepath), "Failed to remove the file.")
27 |
28 |
--------------------------------------------------------------------------------
/ns2/course-for-beginners/ch01-basic-tcl.tcl:
--------------------------------------------------------------------------------
1 |
2 | ## pp. 8-9
3 | set b 0.5
4 |
5 | set x $b
6 |
7 | puts "[expr 1/60]"
8 |
9 | ## pp. 9
10 | puts "浮点运算: [expr 1.0/60.0]"
11 |
12 | # 打开一个文件以写模式
13 | set file1 [open test.write w]
14 |
15 | # 写入数据
16 | puts $file1 "1 1"
17 | puts $file1 "2 $b"
18 |
19 | # exec xgraph test.write &
20 |
21 | # 循环
22 | for { set i 0 } { $i < 5 } { incr i } {
23 | puts "循环 $i "
24 | }
25 |
26 | proc test {} {
27 | set a 43
28 | set b 27
29 | set c [expr $a + $b]
30 |
31 | puts "调用函数 c = $c"
32 | }
33 |
34 | # 调用函数
35 | test
36 |
37 | proc blue { a } {
38 | global b ;#使用 b 为全局变量 b=0.5
39 | set c [expr $a + $b]
40 | puts "调用函数(含参数) c = $c"
41 | return $c
42 | }
43 |
44 | # 调用函数
45 | blue 43
46 |
--------------------------------------------------------------------------------
/ns2/ns_by_example/basic02_ex-otcl.tcl:
--------------------------------------------------------------------------------
1 | # 面向对象
2 | # Create a class call "mom" and
3 | # add a member function call "greet"
4 | Class mom
5 | mom instproc greet {} {
6 | $self instvar age_
7 | puts "$age_ years old mom say:
8 | How are you doing?"
9 | }
10 |
11 | # Create a child class of "mom" called "kid"
12 | # and overide the member function "greet"
13 | Class kid -superclass mom
14 | kid instproc greet {} {
15 | $self instvar age_
16 | puts "$age_ years old kid say:
17 | What's up, dude?"
18 | }
19 |
20 | # Create a mom and a kid object set each age
21 | set a [new mom]
22 | $a set age_ 45
23 | set b [new kid]
24 | $b set age_ 15
25 |
26 | # Calling member function "greet" of each object
27 | $a greet
28 | $b greet
29 |
--------------------------------------------------------------------------------
/sdn/bin/openvswitch-switch.rc:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | function usage(){
3 | echo "$0 (start | stop | restart)"
4 | }
5 | if [ $# -eq 0 ] ; then
6 | usage
7 | else
8 | case $1 in
9 | start)
10 | modprobe openvswitch
11 |
12 | #ovsdb 增加pidfile监听,
13 | # 便于后续控制 sudo ovs-appctl -t ovsdb-server ovsdb-server/add-remote ptcp:6632
14 | /usr/local/sbin/ovsdb-server --pidfile --remote=ptcp:6632 --remote=punix:/usr/local/var/run/openvswitch/db.sock & #启动服务器
15 | /usr/local/sbin/ovs-vswitchd & #启动交换机
16 | /usr/local/bin/ovs-vsctl show #查看交换机状态
17 | ;;
18 | stop)
19 | pkill ovs-vswitchd
20 | pkill ovsdb-server
21 | ;;
22 | restart)
23 | $0 stop
24 | $0 start
25 | ;;
26 | *)
27 | usage
28 | ;;
29 | esac
30 | fi
31 |
--------------------------------------------------------------------------------
/EduLogging/lesson8/task6/logging_decorator.py:
--------------------------------------------------------------------------------
1 | import logging
2 | import time
3 | import functools
4 |
5 | def logging_decorator(f):
6 | @functools.wraps(f)
7 | def wrapper(*args, **kwargs):
8 | logging.debug('Entering %s', f.__name__)
9 | start = time.time()
10 | f(*args, **kwargs)
11 | end = time.time()
12 | logging.debug('Exiting %s in %-5.2f secs', f.__name__, end-start)
13 |
14 | return wrapper
15 |
16 | add our logging decorator do this function
17 | def do_work(timeout):
18 | # Doing something expensive
19 | time.sleep(timeout)
20 |
21 |
22 | if __name__ == '__main__':
23 | logging.basicConfig(configure the log level to ensure we see the decorator output)
24 | do_work(5)
25 |
26 |
--------------------------------------------------------------------------------
/ns2/course-for-beginners/toolbox/rv1.tcl:
--------------------------------------------------------------------------------
1 | ## simple example demonstrating use of the RandomVariable class from tcl
2 |
3 | set count 3
4 | for {set i 0} {$i<3} {incr i} {
5 |
6 | puts "===== i = $i "
7 |
8 | set MyRng1 [new RNG]
9 | $MyRng1 seed $i
10 |
11 | set MyRng2 [new RNG]
12 | $MyRng2 seed $i
13 |
14 | set r1 [new RandomVariable/Pareto]
15 | $r1 use-rng $MyRng1
16 | $r1 set avg_ 10.0
17 | $r1 set shape_ 1.2
18 | puts stdout "Testing Pareto Distribution, avg = [$r1 set avg_] shape = [$r1 set shape_]"
19 | $r1 test $count
20 |
21 | set r2 [new RandomVariable/Pareto]
22 | $r2 use-rng $MyRng2
23 | $r2 set avg_ 10.0
24 | $r2 set shape_ 1.2
25 | puts stdout "Testing Pareto Distribution, avg = [$r2 set avg_] shape = [$r2 set shape_]"
26 | $r2 test $count
27 | }
28 |
--------------------------------------------------------------------------------
/web_framework/mydjango/learn/migrations/0003_student.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | from __future__ import unicode_literals
3 |
4 | from django.db import models, migrations
5 |
6 |
7 | class Migration(migrations.Migration):
8 |
9 | dependencies = [
10 | ('learn', '0002_article'),
11 | ]
12 |
13 | operations = [
14 | migrations.CreateModel(
15 | name='Student',
16 | fields=[
17 | ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
18 | ('name', models.CharField(max_length=30, verbose_name='\u59d3\u540d')),
19 | ('grade', models.IntegerField(verbose_name='\u5e74\u7ea7')),
20 | ],
21 | ),
22 | ]
23 |
--------------------------------------------------------------------------------
/sdn/akaedu/ch37/wrap.h:
--------------------------------------------------------------------------------
1 | /* wrap.h */
2 | #ifndef __WRAP_H__
3 | #define __WRAP_H__
4 |
5 | void perr_exit(const char* s);
6 | int Accept(int fd, struct sockaddr* sa, socklen_t* salenptr);
7 | void Bind(int fd, const struct sockaddr* sa, socklen_t salen);
8 | void Connect(int fd, const struct sockaddr* sa, socklen_t salen);
9 | void Listen(int fd, int backlog);
10 | int Socket(int family, int type, int protocol);
11 | ssize_t Read(int fd, void* ptr, size_t nbytes);
12 | ssize_t Write(int fd, const void* ptr, size_t nbytes);
13 | void Close(int fd);
14 | ssize_t Readn(int fd, void* vptr, size_t n);
15 | ssize_t Writen(int fd, const void* vptr, size_t n);
16 | static ssize_t my_read(int fd, char* ptr);
17 | ssize_t Readline(int fd, void* vptr, size_t maxlen);
18 |
19 | #endif
20 |
--------------------------------------------------------------------------------
/EduLogging/lesson8/task4/task.html:
--------------------------------------------------------------------------------
1 |
2 | You should typically not configure any logging handlers if you are writing a library. It is quite obnoxious for
3 | a library developer to do this, since it should be under the control of the developer using your library.
4 |
5 |
6 | If you are the developer of the library, then configure your logging handlers in a test application instead.
7 |
8 |
9 | Let's assume in this task, this is a library module. It explicitly creates a FileHandler and adds it to the module's
10 | logger at file scope. This is "NOT" a good practice. Let's at least replace this using the NullHandler, which
11 | will not write the logs anywhere. If the library user wants to log somewhere, he can do that himself at the
12 | application level.
13 |
--------------------------------------------------------------------------------
/ns2/dctcp-sigcomm10/index.html:
--------------------------------------------------------------------------------
1 |
2 |
4 | Figure 1
5 |
6 |
7 |
9 | Figure 13
10 |
11 |
12 |
14 | Figure 14
15 |
16 |
--------------------------------------------------------------------------------
/EduLogging/lesson6/task2/task.html:
--------------------------------------------------------------------------------
1 |
2 | In this task, we need to identify an instance name for a Handler object. Use the name "handler1". Again, the
3 | name is arbitrary, but has to match references to the same object.
4 |
5 |
6 | Notice under "[handler_handler1]", there are some additional keys used to initialize the "handler1" instance:
7 |
8 |
9 | "class" is the logging module class name (example: StreamHandler or FileHandler).
10 |
11 |
12 | "args" is a tuple containing the arguments to the class constructor. Here we are going to use the default arguments, so
13 | are specifying an empty tuple.
14 |
15 |
16 | "formatter" is a key reference to a Formatter object. Here we are using "formatter1" because that is the instance
17 | we created in the previous task.
18 |
--------------------------------------------------------------------------------
/sdn/akaedu/ch37/README.md:
--------------------------------------------------------------------------------
1 |
2 | ### Unix Socket 实验
3 |
4 | 实验1. bind() `ex37.unix.bind` bind创建文件套接字, 重复绑定(文件已存在时)时会报`bind error: Address already in use`错误.
5 | ```
6 | rm -f /tmp/sdn/aka*.socket; make && sudo ./ex37.unix.bind
7 | ```
8 |
9 | 实验2. server/client 连接.
10 | ada book 提供的 unix 代码不完整. 改为使用这里的代码[UNIX domain sockets](http://troydhanson.github.io/network/Unix_domain_sockets.html)
11 | ```
12 | ./unix_server
13 | ./unix_client
14 | ```
15 |
16 | ### UDP 代码实验
17 | ada book 提供的代码 `ex37.udp_server` 运行不了. 代码陈旧, 不再使用.
18 |
19 | 改为使用 rutgers CS417 的 `udp_server(udp-recv)` `udp_client(udp-send)` 代码
20 |
21 | 参考: [CS417 Introduction to Sockets Programming] (https://www.cs.rutgers.edu/~pxk/417/notes/sockets/index.html)
22 |
23 | ### TCP 代码实验
24 |
25 | ```
26 | ./ex37.tcp_client
27 | ./ex37.tcp_server
28 | ```
--------------------------------------------------------------------------------
/EduLogging/lesson3/task5/task.html:
--------------------------------------------------------------------------------
1 |
2 | We have replaced the console (stderr) handler with the file handler. Sometimes, it's useful to log to both
3 | places at the same time.
4 |
5 |
6 | You can call "addHandler()" on a Logger multiple times. All of the Handler objects will receive the log messages.
7 |
8 |
9 | In this task, we have created a new StreamHandler instance. Instead of using "stderr" stream, you should
10 | pass "sys.stdout" to see how you could use another output stream. Then pass this StreamHandler instance to
11 | "addHandler()".
12 |
13 |
14 | You should also not forget to add the Formatter to the StreamHandler object. In this task, re-use the same Formatter
15 | you used with the FileHandler. You should also note you can specify different formatters for each handler.
16 |
--------------------------------------------------------------------------------
/EduLogging/lesson8/task2/task.html:
--------------------------------------------------------------------------------
1 |
2 | Most of our Logger instances have been defined at module scope. This is certainly the most convenient way to use
3 | logging, but in some cases you want to have more control over loggers. You can defer creating a logger instance
4 | until it's actually needed.
5 |
6 |
7 | In this example, we show how to create a private logger instance in the class constructor. We use the name of the
8 | current module and append the class name. This will allow us to enable selective logging on just the output from
9 | the class.
10 |
11 |
12 | 1) Complete the name of the FirstClass logger instance
13 |
14 | 2) Set the instance logger level to DEBUG
15 |
16 |
17 | You should not see any DEBUG output, except the log messages coming from the FirstClass object.
18 |
--------------------------------------------------------------------------------
/EduLogging/lesson5/task2/tests.py:
--------------------------------------------------------------------------------
1 | from test_helper import run_common_tests, failed, passed, get_answer_placeholders, check_answers
2 |
3 |
4 | def test_answer_placeholders():
5 | placeholders = get_answer_placeholders()
6 | placeholder = placeholders[0]
7 | try:
8 | int_value = int(placeholder)
9 | if int_value > 0:
10 | passed()
11 | else:
12 | failed()
13 |
14 | except ValueError:
15 | if placeholder == 'True':
16 | passed()
17 | else:
18 | failed()
19 |
20 | placeholder = placeholders[1]
21 | if placeholder == 'root.addFilter(sanitize_filter)':
22 | passed()
23 | else:
24 | failed()
25 |
26 | if __name__ == '__main__':
27 | run_common_tests()
28 | test_answer_placeholders()
29 |
30 |
31 |
--------------------------------------------------------------------------------
/gurobi/examples-python/interact-open-pit-mining.py:
--------------------------------------------------------------------------------
1 | from gurobipy import *
2 |
3 | # Example data for problem
4 | cost = [100, 100, 100, 100, 200, 200];
5 | value = [50, 150, 150, 150, 300, 50];
6 | edges = [[4,0], [4,1], [4,2], [5,1], [5,2], [5,3]];
7 |
8 | m = Model()
9 | n = len(cost) # number of blocks
10 |
11 | # Indicator variable for each block
12 | x = {}
13 | for i in range(n):
14 | x[i] = m.addVar(vtype=GRB.BINARY, name="x%d" % i)
15 |
16 | m.update()
17 |
18 | # Set objective
19 | m.setObjective(quicksum((value[i] - cost[i])*x[i] for i in range(n)), GRB.MAXIMIZE)
20 |
21 | # Add constraints
22 | for edge in edges:
23 | u = edge[0]
24 | v = edge[1]
25 | m.addConstr(x[u] <= x[v])
26 |
27 | m.optimize()
28 |
29 | for v in m.getVars():
30 | if v.X != 0:
31 | print("%s %f" % (v.Varname, v.X))
32 |
--------------------------------------------------------------------------------
/ns2/cuc-buffer/verify/run-flows-vs-link.sh:
--------------------------------------------------------------------------------
1 | if [ $# -ne 1 ]
2 | then
3 | echo "Usage: `basename $0` {experiment_name}"
4 | echo " Examples: `basename $0` 100-64-900-cubic"
5 | echo " Debug: `basename $0` 150-64-60-cubic" # 调试数据
6 | exit
7 | fi
8 |
9 | exp=$1
10 | for flownum in 5 10 20; do
11 |
12 | foldername=${flownum}-${exp}
13 |
14 | if ! [[ -d ${foldername} ]] ; then
15 | echo "ERROR: 目录 ${foldername} 不存在, 请检查参数 ..."
16 | else
17 |
18 | # 在终端显示
19 | #../verify/flows-vs-link.py --dir 5-150-64-60-cubic/ | column -t
20 |
21 | # 输出 rate0-flows
22 | ../verify/flows-vs-link.py --out rate0-flows --dir ${foldername}/
23 | cd ${foldername}
24 | rm -f rate*.png
25 | echo "*** 验证显示 ${flownum}条流 的带宽图形"
26 | xgraph.py -m rate*
27 | cd ..
28 | fi
29 | done
--------------------------------------------------------------------------------
/ns3/practical_csocket2/AdminClient2.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include "PracticalSocket.h"
3 | #include "SurveyCommon.h"
4 |
5 | using namespace std;
6 |
7 | int main(int argc, char *argv[]) {
8 | try {
9 | // Connect to the server's administrative interface.
10 | TCPSocket sock("localhost", SURVEY_PORT + 1);
11 |
12 | // Read the server's report a block at a time.
13 | char buffer[ 1025 ];
14 | int len;
15 | while ((len = sock.recv(buffer, sizeof(buffer) - 1)) != 0) {
16 | buffer[len] = '\0'; // Null terminate the sequence
17 | cout << buffer; // And print it like as a string
18 | }
19 | } catch(SocketException &e) {
20 | cerr << e.what() << endl; // Report errors to the console.
21 | exit(1);
22 | }
23 |
24 | return 0;
25 | }
26 |
--------------------------------------------------------------------------------
/EduLogging/lesson2/task5/log_objects.py:
--------------------------------------------------------------------------------
1 | # This example shows logging objects
2 | #
3 |
4 | import logging
5 |
6 | logger = logging.getLogger('mortgage')
7 |
8 | class Mortgage(object):
9 | def __init__(self, principal, rate, term):
10 | self.principal = principal
11 | self.rate = rate
12 | self.term = term
13 |
14 | def __str__(self):
15 | return 'Mortgage principal %f for %f years at %f rate' % (
16 | self.principal, self.term, self.rate)
17 |
18 | def __repr__(self):
19 | return 'Mortgage(%f, %f, %f)' % (self.principal, self.rate, self.term)
20 |
21 |
22 | if __name__ == '__main__':
23 | logging.basicConfig(level=logging.DEBUG)
24 |
25 | obj = Mortgage(100000, 4.1, 15)
26 | ## eval(repr(obj) == obj
27 | logger.debug('Created object: %s', repr(obj))
28 |
--------------------------------------------------------------------------------
/turtle/random-stamps.py:
--------------------------------------------------------------------------------
1 | #REF: cheatsheet2.pdf
2 |
3 | import turtle
4 | import random
5 | random.seed()
6 | turtle.speed(10)
7 | turtle.resizemode('auto')
8 |
9 | myColourList = ['red', 'black', 'orange', 'blue', 'purple']
10 |
11 | myShapeList = ['turtle', 'arrow', 'square', 'circle', 'triangle', 'classic']
12 |
13 | def makeStamp():
14 | turtle.setheading(random.randint(1, 360))
15 | turtle.pensize(random.randint(1, 7))
16 | turtle.color(random.choice(myColourList))
17 | turtle.shape(random.choice(myShapeList))
18 | turtle.stamp()
19 |
20 | for i in range(200):
21 | makeStamp()
22 | # turtle.setheading(90)
23 | turtle.penup()
24 |
25 | turtle.fd(random.randint(50,100))
26 | if (turtle.pos()[0]) > 400 or (turtle.pos()[0]) < -400:
27 | turtle.home()
28 | turtle.pendown()
29 |
30 | turtle.done()
--------------------------------------------------------------------------------
/EduLogging/lesson1/task4/task.html:
--------------------------------------------------------------------------------
1 |
2 | The previous tasks have been logging messages through helper functions provided in the logging library and using
3 | the root Logger.
4 |
5 |
6 | Typically you will get local Logger objects for each module and call logging functions on that object. This
7 | is done by calling "logging.getLogger()" which returns a Logger object for a given name. You should never directly
8 | create instances of a Logger object.
9 |
10 |
11 | Calling "logging.getLogger()" with no arguments, will return the root Logger.
12 |
13 |
14 | In this task, we have created a module scoped "logger" instance with the name "mortgage". Replace the logging calls with references to this instance.
15 |
16 |
17 | After you execute this code, you should notice the name "mortgage" is now included in the output.
18 |
--------------------------------------------------------------------------------
/ns2/tcpsuit/analysis/process_ef.pl:
--------------------------------------------------------------------------------
1 | $filename = @ARGV[0];
2 | $ext = @ARGV[1];
3 | open (FILE, "$filename.$ext");
4 | @lines = ;
5 |
6 | %cluster1;
7 | %cluster2;
8 |
9 | foreach $line (@lines) {
10 | chomp($line);
11 | ($band, $utiliz) = split(/ /, $line);
12 | #print "$band $utiliz = ";
13 | $index = int($band / 200);
14 | if (not defined($cluster1{$index})) {
15 | #print "not def ";
16 | $cluster1{$index} = $utiliz;
17 | $cluster2{$index} = 1;
18 | } else {
19 | #print "def ";
20 | $temp = $cluster1{$index};
21 | $temp = $temp + $utiliz;
22 | $cluster1{$index} = $temp;
23 | $cluster2{$index} = $cluster2{$index} + 1;
24 | }
25 | #print "$index ($cluster1{$index}/$cluster2{$index})\n";
26 | }
27 |
28 | foreach $key (sort(keys %cluster1)) {
29 | $avg = $cluster1{$key} / $cluster2{$key};
30 | print "$key $avg\n";
31 | }
32 |
--------------------------------------------------------------------------------
/sdn/akaedu/ch08/ex08.5.game.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | int main(void)
6 | {
7 | char gesture[3][10] = { "scissor", "stone", "cloth" };
8 | int man, computer, result, ret;
9 |
10 | srand(time(NULL));
11 | while (1) {
12 | computer = rand() % 3;
13 | printf("\nInput your gesture (0-scissor 1-stone 2-cloth):\n");
14 | ret = scanf("%d", &man);
15 | if (ret != 1 || man < 0 || man > 2) {
16 | printf("Invalid input! Please input 0, 1 or 2.\n");
17 | continue;
18 | }
19 | printf("Your gesture: %s\tComputer's gesture: %s\n",
20 | gesture[man], gesture[computer]);
21 |
22 | result = (man - computer + 4) % 3 - 1;
23 | if (result > 0)
24 | printf("You win!\n");
25 | else if (result == 0)
26 | printf("Draw!\n");
27 | else
28 | printf("You lose!\n");
29 | }
30 | return 0;
31 | }
--------------------------------------------------------------------------------
/EduLogging/lesson8/task3/task.html:
--------------------------------------------------------------------------------
1 |
2 | If you are calling an expensive function and passing the result to a logging statement, you may want to prevent
3 | that function from being called unless the current logging level is going to output the log message.
4 |
5 |
6 | This can be done by checking the return value from "isEnabledFor()" on the Logger object. This function takes
7 | the logging level, and if the logger is going to output the message, the return value is True.
8 |
9 |
10 | In this example, the root logger level is set to WARNING. We output a debug level log message, passing in the
11 | result of calculate_expensive_result(). This code executes, even though the debug level message is being filtered out.
12 |
13 |
14 | Add a conditional statement to not log this message if the log level will not apply to the handler.
15 |
--------------------------------------------------------------------------------
/ns3/practical_csocket2/TCPEchoServer.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include "Practical.h"
3 | #include
4 |
5 | int main(int argc, char *argv[]) {
6 |
7 | if (argc != 2) // Test for correct number of arguments
8 | DieWithUserMessage("Parameter(s)", "");
9 |
10 | char *service = argv[1]; // First arg: local port
11 |
12 | // Create socket for incoming connections
13 | int servSock = SetupTCPServerSocket(service);
14 | if (servSock < 0)
15 | DieWithUserMessage("SetupTCPServerSocket() failed", service);
16 |
17 | for (;;) { // Run forever
18 | // New connection creates a connected client socket
19 | int clntSock = AcceptTCPConnection(servSock);
20 |
21 | HandleTCPClient(clntSock); // Process client
22 | close(clntSock);
23 | break;
24 | }
25 | // NOT REACHED
26 | close(servSock);
27 | }
28 |
--------------------------------------------------------------------------------
/EduLogging/lesson3/task3/task.html:
--------------------------------------------------------------------------------
1 |
2 | Up to this point we have been relying on the "basicConfig()" function to help configure logging. You can also
3 | configure the logging objects yourself for more flexibility.
4 |
5 |
6 | In this task, we are going to create a FileHandler object ourselves and add this to the root logger.
7 |
8 |
9 | 1) Update the task to create a new FileHandler object. The first argument is the filename. Use "log_filename" for this task.
10 |
11 | 2) Next, we have to call addHandler() on the Logger object. In this task we are adding the handler to the
12 | root logger, so any child loggers will also be output to our handler.
13 |
14 |
15 | Note: To see the file "create_file_handler.log" in your Sandbox, you may have to collapse/expand the "Sandbox" folder in your Project view to
16 | see the new file created.
17 |
--------------------------------------------------------------------------------
/ns2/otcl/README.md:
--------------------------------------------------------------------------------
1 | # OTcl 官方文档
2 |
3 | Source: https://www.isi.edu/nsnam/otcl/README.html
4 |
5 | ## 环境准备
6 | * 安装 pawk `sudo pip install python-awk`
7 |
8 | ## How do I use it?
9 |
10 | There's a quickstart tutorial to help you become familiar with OTcl syntax and style. It's included in the distribution.
11 |
12 | * Tutorial https://www.isi.edu/nsnam/otcl/README.html
13 | - `tutorial.tcl` 官方文档代码
14 | - `tutorial-tcp.tcl` 参考分析 Agent/TCP 类
15 |
16 | * `class_info.tcl` 通过命令 `[Class info instances]` 查看 OTcl 中的对象
17 | - `./class_info.sh > class_info.txt` 通过 `pawk` 将对象排序后存储, ns-2.35 标准对象为 660 个
18 |
19 | ## 参考
20 | * CS558 Network Simulation using NS2: Tcl - 1 week: http://www.mathcs.emory.edu/~cheung/Courses/558/Syllabus/syl.html
21 | * ns-by-exampels OTcl: The User Language: http://nile.wpi.edu/NS/otcl.html
22 | - `ns ../ns_by_example/basic02_ex-otcl.tcl`
--------------------------------------------------------------------------------
/sdn/mininet-tests/buffersizing/iperf-2.0.5-wait-syn.patch:
--------------------------------------------------------------------------------
1 | diff --git a/Client.cpp b/Client.cpp
2 | index 71a5b5c..6aa25f8 100644
3 | --- a/Client.cpp
4 | +++ b/Client.cpp
5 | @@ -213,6 +213,7 @@ void Client::Run( void ) {
6 |
7 | #if HAVE_THREAD
8 | if ( !isUDP( mSettings ) ) {
9 | + sleep(5); // Sleep a bit before blasting data
10 | RunTCP();
11 | return;
12 | }
13 | diff --git a/Listener.cpp b/Listener.cpp
14 | index 94e32de..0071a59 100644
15 | --- a/Listener.cpp
16 | +++ b/Listener.cpp
17 | @@ -338,7 +338,7 @@ void Listener::Listen( ) {
18 | // listen for connections (TCP only).
19 | // default backlog traditionally 5
20 | if ( !isUDP( mSettings ) ) {
21 | - rc = listen( mSettings->mSock, 5 );
22 | + rc = listen( mSettings->mSock, 1024 );
23 | WARN_errno( rc == SOCKET_ERROR, "listen" );
24 | }
25 |
26 |
--------------------------------------------------------------------------------
/web_framework/mydjango/demoapp/templates/d01_first_steps/polls_detail.html:
--------------------------------------------------------------------------------
1 |
10 |
11 |
12 |
13 | {{ question.question_text }}
14 |
15 | {% if error_message %} {{ error_message }}
{% endif %}
16 |
17 |
--------------------------------------------------------------------------------
/ns2/caltech-ns2tcplinux/tutorial/linux.tcl:
--------------------------------------------------------------------------------
1 | #Create a simulator object
2 | set ns [new Simulator]
3 |
4 | #Create two nodes and a link
5 | set bs [$ns node]
6 | set br [$ns node]
7 | $ns duplex-link $bs $br 100Mb 10ms DropTail
8 |
9 | #setup sender side
10 | set tcp [new Agent/TCP/Linux]
11 | $tcp set timestamps_ true
12 | #$tcp set windowOption_ 8
13 | $ns attach-agent $bs $tcp
14 |
15 | #set up receiver side
16 | set sink [new Agent/TCPSink/Sack1]
17 | $sink set ts_echo_rfc1323_ true
18 | $ns attach-agent $br $sink
19 |
20 | #logical connection
21 | $ns connect $tcp $sink
22 |
23 | #Setup a FTP over TCP connection
24 | set ftp [new Application/FTP]
25 | $ftp attach-agent $tcp
26 | $ftp set type_ FTP
27 |
28 | $ns at 0 "$tcp select_ca highspeed"
29 |
30 | #Start FTP
31 | $ns at 0 "$ftp start"
32 | $ns at 10 "$ftp stop"
33 | $ns at 11 "exit 0"
34 | $ns run
35 |
36 |
--------------------------------------------------------------------------------
/sdn/mininet-tests/buffersizing-red/iperf-2.0.5-wait-syn.patch:
--------------------------------------------------------------------------------
1 | diff --git a/Client.cpp b/Client.cpp
2 | index 71a5b5c..6aa25f8 100644
3 | --- a/Client.cpp
4 | +++ b/Client.cpp
5 | @@ -213,6 +213,7 @@ void Client::Run( void ) {
6 |
7 | #if HAVE_THREAD
8 | if ( !isUDP( mSettings ) ) {
9 | + sleep(5); // Sleep a bit before blasting data
10 | RunTCP();
11 | return;
12 | }
13 | diff --git a/Listener.cpp b/Listener.cpp
14 | index 94e32de..0071a59 100644
15 | --- a/Listener.cpp
16 | +++ b/Listener.cpp
17 | @@ -338,7 +338,7 @@ void Listener::Listen( ) {
18 | // listen for connections (TCP only).
19 | // default backlog traditionally 5
20 | if ( !isUDP( mSettings ) ) {
21 | - rc = listen( mSettings->mSock, 5 );
22 | + rc = listen( mSettings->mSock, 1024 );
23 | WARN_errno( rc == SOCKET_ERROR, "listen" );
24 | }
25 |
26 |
--------------------------------------------------------------------------------
/EduLogging/lesson7/task3/task.html:
--------------------------------------------------------------------------------
1 |
2 | The standard library does not include a database handler for storing log messages in a database. The Python logging
3 | system is easy to extend with our own database logging. Having log data in a database is useful for writing queries
4 | and reports against your log data.
5 |
6 |
7 | In this example, we have created a SQLite database handler. Since, the SQLite
8 | database module is included in the standard library, you don't have to
9 | install any databases.
10 |
11 |
12 | This custom handler will attempt to create the database table named 'logger' with
13 | the necessary schema to store most of the LogRecord attributes.
14 |
15 |
16 | In the Handler's emit() method we will insert the LogRecord data into the table.
17 |
18 |
19 | At the end of the task we write several queries to the database.
20 |
--------------------------------------------------------------------------------
/ns2/caltech-ns2tcplinux/tutorial/sack1.tcl:
--------------------------------------------------------------------------------
1 | #Create a simulator object
2 | set ns [new Simulator]
3 |
4 | #Create two nodes and a link
5 | set bs [$ns node]
6 | set br [$ns node]
7 | $ns duplex-link $bs $br 100Mb 10ms DropTail
8 |
9 | #setup sender side
10 | set tcp [new Agent/TCP/Sack1]
11 | $tcp set timestamps_ true
12 | $tcp set windowOption_ 8
13 | $ns attach-agent $bs $tcp
14 |
15 | #set up receiver side
16 | set sink [new Agent/TCPSink/Sack1]
17 | $sink set ts_echo_rfc1323_ true
18 | $ns attach-agent $br $sink
19 |
20 | #logical connection
21 | $ns connect $tcp $sink
22 |
23 | #Setup a FTP over TCP connection
24 | set ftp [new Application/FTP]
25 | $ftp attach-agent $tcp
26 | $ftp set type_ FTP
27 |
28 | # $ns at 0 "$tcp($i) select_ca $TCP_Name"
29 |
30 | #Start FTP
31 | $ns at 0 "$ftp start"
32 | $ns at 10 "$ftp stop"
33 | $ns at 11 "exit 0"
34 | $ns run
35 |
36 |
--------------------------------------------------------------------------------
/pythonchallenge/05.py:
--------------------------------------------------------------------------------
1 | # -*- coding:utf-8 -*-
2 | """
3 | filename:
4 | author:
5 | version:
6 | url: http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345
7 | solution: http://www.pythonchallenge.com/pc/def/peak.html
8 | """
9 | import math
10 | import mylib
11 | import requests
12 |
13 | """
14 | 循环抓取,直到最后一个页面
15 | """
16 | urlprefix = "http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing="
17 | url = urlprefix+"12345"
18 | response = requests.get(url)
19 | while response.status_code == 200:
20 | content = response.text
21 | print "content: ", content
22 | if (len(content.split(" "))>=6):
23 | newid = content.split(" ")[-1] #取出后缀id
24 | print "newid", newid
25 | url = urlprefix + newid
26 | print "get url: ", url
27 | response = requests.get(url) #抓取新id页面
28 | else: #如果缺少id, 停止
29 | break
30 |
--------------------------------------------------------------------------------
/ns2/course-for-beginners/ch02-random.tcl:
--------------------------------------------------------------------------------
1 | puts "随机变量例子 ch02, pp. 30 copy from rv1.tcl"
2 |
3 | # 测试数量
4 | set count 5
5 | for {set i 0} {$i<2} {incr i} {
6 | set seed $i
7 | puts "===== i = $i "
8 |
9 | set MyRng1 [new RNG]
10 | $MyRng1 seed $seed
11 |
12 | set MyRng2 [new RNG]
13 | $MyRng2 seed $seed
14 |
15 | set r1 [new RandomVariable/Pareto]
16 | $r1 use-rng $MyRng1
17 | $r1 set avg_ 10.0
18 | $r1 set shape_ 1.2
19 | puts stdout "Testing Pareto Distribution, avg = [$r1 set avg_] shape = [$r1 set shape_]"
20 |
21 | # 生成测试数量的变量
22 | $r1 test $count
23 |
24 | set r2 [new RandomVariable/Pareto]
25 | $r2 use-rng $MyRng2
26 | $r2 set avg_ 10.0
27 | $r2 set shape_ 1.2
28 | puts stdout "Testing Pareto Distribution, avg = [$r2 set avg_] shape = [$r2 set shape_]"
29 | $r2 test $count
30 |
31 | set rstart [$r2 test 1]
32 | puts "随机变量: $rstart"
33 | }
34 |
35 |
36 |
--------------------------------------------------------------------------------
/EduLogging/lesson8/task5/right_levels.py:
--------------------------------------------------------------------------------
1 | import logging
2 |
3 | if __name__ == '__main__':
4 | logging.basicConfig(level=logging.DEBUG)
5 |
6 | user_id = 1001
7 | ip = '10.0.0.15'
8 | port = 5555
9 | account_id = 3551
10 | version = '1.5.2'
11 |
12 | logging.log(logging.enter level name, 'Service restarted - version %s', version)
13 |
14 | logging.log(logging.enter level name, 'Failed to connect to calculator service at ip=%s:%d', ip, port)
15 |
16 | logging.log(logging.enter level name, 'Created user account id=%d', user_id)
17 |
18 | logging.log(logging.enter level name, 'User entered invalid account id=%d account_id=%d', user_id, account_id)
19 |
20 | logging.log(logging.enter level name, 'Could not connect to user database')
21 |
22 | logging.log(logging.enter level name, 'DB Transaction created for updating user id=%d', user_id)
23 |
--------------------------------------------------------------------------------
/ns2/caltech-ns2tcplinux/script-gnuplot.txt:
--------------------------------------------------------------------------------
1 | ## 批量调用此文件方法
2 | #```
3 | # # 在 MacOSX 下使用 gnuplot 生成的 cwnd 图形;
4 | # for x in `ls -1d 1-100-64-900-*`; do cd $x; gnuplot ../../script-gnuplot.txt; ALG=`head -n2 ./config | tail -n1`; mv cwnd.png cwnd-$ALG.png; open cwnd-$ALG.png; cd .. ; done
5 | #```
6 |
7 | set term png
8 | set title "cwnd"
9 | set out "cwnd.png"
10 | set xrange [0:500]
11 | set yrange [0:2500]
12 | plot "result0" u 1:2 w li
13 |
14 | set term png
15 | set title "rate"
16 | set out "rate.png"
17 | set xrange [0:500]
18 | set yrange [0:150]
19 | plot "result0" u 1:3 w li
20 |
21 | #
22 | # gnuplot 的坐标计算, 不如 matplotlib 更加智能
23 | #
24 | # 需要制定清晰才能更好的浏览图形
25 | #
26 | # 在 xgraph.py 支持 -f 参数后, 可以不使用下面的绘图方法
27 |
28 | #set term png
29 | #set title "ack"
30 | #set out "gnup-ack.png"
31 | #set xrange [0:500]
32 | #set yrange [0:5000000]
33 | #plot "result0" u 1:4 w li
34 |
35 |
36 |
--------------------------------------------------------------------------------
/ns3/cplusplus.com/ch05_default_delete.cpp:
--------------------------------------------------------------------------------
1 | // default and delete implicit members
2 | // http://www.cplusplus.com/doc/tutorial/classes2/
3 |
4 | #include
5 | using namespace std;
6 |
7 | class Rectangle {
8 | int width, height;
9 | public:
10 | Rectangle (int x, int y) : width(x), height(y) {}
11 | Rectangle() = default; // default
12 | Rectangle (const Rectangle& other) = delete; //delete 之后就不能使用了
13 |
14 | // 下面这两句的效果是一样的
15 | // Rectangle::Rectangle (const Rectangle& other) = default;
16 | // Rectangle::Rectangle (const Rectangle& other) : width(other.width), height(other.height) {}
17 |
18 | int area() {return width*height;}
19 | };
20 |
21 | int main () {
22 | Rectangle foo;
23 | Rectangle bar (10,20);
24 |
25 | // Rectangle foo2(bar); //delete 之后就不能使用了
26 |
27 | cout << "bar's area: " << bar.area() << '\n';
28 | return 0;
29 | }
--------------------------------------------------------------------------------
/sdn/ipc-bench-master/Makefile:
--------------------------------------------------------------------------------
1 |
2 | #CFLAGS = -g -Wall -O3
3 | CFLAGS = -g -O3 -w # disable warning
4 |
5 | build: \
6 | tc_shell_lat \
7 | tc_shell_p_lat \
8 | udp_lat \
9 | tcp_lat \
10 | unix_lat_client \
11 | unix_lat_server \
12 | unix_lat
13 |
14 |
15 | all: pipe_lat pipe_thr \
16 | unix_lat unix_thr \
17 | tcp_lat tcp_thr \
18 | get_tc_queue_lat \
19 | tc_shell_lat \
20 | tcp_local_lat tcp_remote_lat
21 |
22 |
23 | run:
24 | ./pipe_lat 100 10000
25 | ./unix_lat 100 10000
26 | ./tcp_lat 100 10000
27 | ./pipe_thr 100 10000
28 | ./unix_thr 100 10000
29 | ./tcp_thr 100 10000
30 |
31 | clean:
32 | #rm -f *.o
33 | rm -f *~ core
34 | rm -f pipe_lat pipe_thr
35 | rm -f unix_lat unix_thr
36 | rm -f tcp_lat tcp_thr
37 | rm -f tcp_local_lat tcp_remote_lat
38 | rm -f tc_shell_p_lat
39 | rm -f tc_shell_lat
40 | rm -f udp_lat
41 | rm -f unix_lat_server unix_lat_client
42 |
--------------------------------------------------------------------------------
/web_framework/mydjango/demoapp/migrations/0012_auto_20150806_1331.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | from __future__ import unicode_literals
3 |
4 | from django.db import models, migrations
5 |
6 |
7 | class Migration(migrations.Migration):
8 |
9 | dependencies = [
10 | ('demoapp', '0011_auto_20150806_1248'),
11 | ]
12 |
13 | operations = [
14 | migrations.AddField(
15 | model_name='d02album',
16 | name='type',
17 | field=models.CharField(max_length=10, null=True, choices=[(b'CLA', b'\xe5\x8f\xa4\xe5\x85\xb8'), (b'POP', b'\xe7\x8e\xb0\xe4\xbb\xa3')]),
18 | ),
19 | migrations.AddField(
20 | model_name='d02album',
21 | name='type_int',
22 | field=models.IntegerField(null=True, choices=[(1, b'\xe6\x91\x87\xe6\xbb\x9a'), (2, b'\xe7\x88\xb5\xe5\xa3\xab')]),
23 | ),
24 | ]
25 |
--------------------------------------------------------------------------------
/EduLogging/lesson3/task4/task.html:
--------------------------------------------------------------------------------
1 |
2 | In the previous task, you may have noticed the only thing output in our log file was the log message.
3 |
4 |
5 | This is because we have no Formatter object set on our handler. In previous examples, we have relied
6 | on "basicConfig()" to build a formatter for us.
7 |
8 |
9 | The Formatter is responsible for taking a LogRecord object and creating a string result that can be used
10 | by the Handler to output a log message. Each Handler has one Formatter.
11 |
12 |
13 | In this task we need to construct a "Formatter" object, passing it our format string. Then we need
14 | to call "setHandler" on our new file handler instance.
15 |
16 |
17 | Note: To see the file "file_handler_with_formatter.log" in your Sandbox, you may have to collapse/expand the "Sandbox" folder in your Project view to
18 | see the new file created.
19 |
--------------------------------------------------------------------------------
/lecture/bit_program_design/10CalThreeKingdomsV1.py:
--------------------------------------------------------------------------------
1 | #coding:utf-8
2 | #CalThreeKingdomsV1.py
3 | # 下载文本地址 https://www.icourse163.org/learn/BIT-268001?tid=1002788003#/learn/content?type=detail&id=1004072178&cid=1005006157
4 | # 下载地址 https://www.icourse163.org/course/attachment.htm?fileName=%E5%AE%9E%E4%BE%8B10-%E6%96%87%E6%9C%AC%E8%AF%8D%E9%A2%91%E7%BB%9F%E8%AE%A1%E6%BA%90%E4%BB%A3%E7%A0%81.zip&nosKey=3EB5816FF36E20A17232A1CE826DAA79-1523925499203
5 | import jieba
6 | txt = open("threekingdoms.txt", "r", encoding='utf-8').read()
7 | words = jieba.lcut(txt)
8 | counts = {}
9 | for word in words:
10 | if len(word) == 1:
11 | continue
12 | else:
13 | counts[word] = counts.get(word,0) + 1
14 | items = list(counts.items())
15 | items.sort(key=lambda x:x[1], reverse=True)
16 | for i in range(15):
17 | word, count = items[i]
18 | print ("{0:<10}{1:>5}".format(word, count))
19 |
--------------------------------------------------------------------------------
/sdn/mininet-tests/cpuiso/cpu/test_cpu.py:
--------------------------------------------------------------------------------
1 |
2 | import sys
3 | sys.path = ['/home/jvimal/mininet'] + sys.path
4 |
5 | from util import Command
6 |
7 |
8 | MIN = 10000
9 | ratios = xrange(2, 10+1)
10 |
11 |
12 | def container_start(name, quota, period, program):
13 | cmd = [
14 | "lxc-execute",
15 | "-n", name,
16 | "-s", "lxc.cgroup.cpuset.cpus=0",
17 | "-s", "lxc.cgroup.cpu.cfs_quota_us=%d" % quota,
18 | "-s", "lxc.cgroup.cpu.cfs_period_us=%d" % period,
19 | ] + program.split(' ')
20 |
21 | return Command(cmd).read_full()
22 |
23 | for denom in ratios:
24 | print '###### CPU ratio: %d/%d ######' % (1, denom)
25 | for mul in [1, 2, 5, 10]:
26 | quota = mul * MIN
27 | period = denom * quota
28 | print "----- quota=%d, period=%d, 10second run -----" % (quota, period)
29 | print container_start("foo", quota, period, "./cpu-stress 10 0")
30 | sys.stdout.flush()
31 |
--------------------------------------------------------------------------------
/EduLogging/lesson2/task6/limit_output.py:
--------------------------------------------------------------------------------
1 | import logging
2 |
3 | def truncate(obj, nlen=20):
4 | """ Convert 'obj' to string and truncate if greater than length"""
5 | str_value = str(obj)
6 | if len(str_value) > nlen:
7 | return str_value[:nlen-3] + '...'
8 | return str_value
9 |
10 | if __name__ == '__main__':
11 | logging.basicConfig(level=logging.DEBUG)
12 |
13 | long_string = 'A' * 2000
14 | logging.debug('something happened with value=%s', long_string)
15 |
16 | # Truncate result (no ellipses)
17 | logging.debug('something happened with value=%.10s', long_string)
18 |
19 | # Create a large list
20 | big_list = [1] * 2000
21 |
22 | # Log the full list
23 | logging.debug('something happened with the list=%s', big_list)
24 |
25 | # Truncate result (with ellipses)
26 | logging.debug('something happened with the list=%s', truncate(big_list, 30))
27 |
--------------------------------------------------------------------------------
/ns3/cplusplus.com/ch04_chars.cpp:
--------------------------------------------------------------------------------
1 | // strings and NTCS:
2 | // http://www.cplusplus.com/doc/tutorial/ntcs/
3 | #include
4 | #include
5 | using namespace std;
6 |
7 | int main ()
8 | {
9 |
10 | cout << "c-string 和 string 类的互转" << endl;
11 | char myntcs[] = "some text"; //c-string
12 | string mystring = myntcs; // convert c-string to string
13 | cout << mystring << endl; // printed as a library string
14 | cout << mystring.c_str() << endl ; // printed as a c-string
15 |
16 |
17 | cout << "c-string 固定长度, 而string 动态长度" << endl;
18 | char question1[] = "What is your name? ";
19 | string question2 = "Where do you live? ";
20 | char answer1 [80];
21 | string answer2;
22 | cout << question1;
23 | cin >> answer1;
24 | cout << question2;
25 | cin >> answer2;
26 | cout << "Hello, " << answer1;
27 | cout << " from " << answer2 << "!\n";
28 |
29 |
30 | return 0;
31 | }
--------------------------------------------------------------------------------
/EduLogging/lesson6/task1/file_config_formatters.py:
--------------------------------------------------------------------------------
1 | import logging
2 | import logging.config
3 |
4 | config = """
5 | [formatters]
6 | keys=enter a name for a new formatter object
7 |
8 | [handlers]
9 | keys=handler1
10 |
11 | [loggers]
12 | keys=root
13 |
14 | [formatter_add the formatter name here]
15 | format=%(asctime)s %(levelname)s %(message)s
16 |
17 | [handler_handler1]
18 | class=StreamHandler
19 | args=()
20 | formatter=formatter1
21 |
22 | [logger_root]
23 | handlers=handler1
24 | level=DEBUG
25 | """
26 |
27 | config_filename = 'logging.ini'
28 |
29 | def write_config_file(filename, data):
30 | with open(filename, 'w') as fp:
31 | fp.write(data)
32 |
33 |
34 | if __name__ == '__main__':
35 | write_config_file(config_filename, config)
36 |
37 | logging.config.fileConfig(config_filename)
38 |
39 | logging.debug('this is a debug message')
40 | logging.warning('this is a warning message')
--------------------------------------------------------------------------------
/sdn/akaedu/ch37/ex37.unix.bind.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 |
7 | /*
8 | 创建并绑定一个一个unix文件套接字
9 |
10 | ls /tmp/sdn; # 查看创建的套接字
11 | rm /tmp/sdn/aka*.socket; #删除套接字
12 | */
13 | int main(void)
14 | {
15 | int fd, size;
16 | struct sockaddr_un un;
17 |
18 | memset(&un, 0, sizeof(un));
19 | un.sun_family = AF_UNIX;
20 | strcpy(un.sun_path, "/tmp/sdn/aka_foo.socket");
21 | if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
22 | perror("socket error");
23 | exit(1);
24 | }
25 | // offsetof(struct sockaddr_un, sun_path)就是取sockaddr_un结构体的sun_path成员在结构体中的偏移,
26 | // 也就是从结构体的第几个字节开始是sun_path成员
27 | size = offsetof(struct sockaddr_un, sun_path) + strlen(un.sun_path);
28 | if (bind(fd, (struct sockaddr *)&un, size) < 0) {
29 | perror("bind error");
30 | exit(1);
31 | }
32 | printf("UNIX domain socket bound\n");
33 | exit(0);
34 | }
--------------------------------------------------------------------------------
/EduLogging/lesson6/task2/file_config_handlers.py:
--------------------------------------------------------------------------------
1 | import logging
2 | import logging.config
3 |
4 | config = """
5 | [formatters]
6 | keys=formatter1
7 |
8 | [handlers]
9 | keys=enter instance name for a handler object
10 |
11 | [loggers]
12 | keys=root
13 |
14 | [formatter_formatter1]
15 | format=%(asctime)s %(levelname)s %(message)s
16 |
17 | [handler_enter instance name for a handler object]
18 | class=StreamHandler
19 | args=()
20 | formatter=formatter1
21 |
22 | [logger_root]
23 | handlers=handler1
24 | level=DEBUG
25 | """
26 |
27 | config_filename = 'logging.ini'
28 |
29 | def write_config_file(filename, data):
30 | with open(filename, 'w') as fp:
31 | fp.write(data)
32 |
33 |
34 | if __name__ == '__main__':
35 | write_config_file(config_filename, config)
36 |
37 | logging.config.fileConfig(config_filename)
38 |
39 | logging.debug('this is a debug message')
40 | logging.warning('this is a warning message')
--------------------------------------------------------------------------------
/web_framework/mydjango/demoapp/migrations/0015_auto_20150819_0238.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | from __future__ import unicode_literals
3 |
4 | from django.db import models, migrations
5 | from django.conf import settings
6 |
7 |
8 | class Migration(migrations.Migration):
9 |
10 | dependencies = [
11 | migrations.swappable_dependency(settings.AUTH_USER_MODEL),
12 | ('demoapp', '0014_snippet'),
13 | ]
14 |
15 | operations = [
16 | migrations.AddField(
17 | model_name='snippet',
18 | name='highlighted',
19 | field=models.TextField(default=''),
20 | preserve_default=False,
21 | ),
22 | migrations.AddField(
23 | model_name='snippet',
24 | name='owner',
25 | field=models.ForeignKey(related_name='snippets', default=1, to=settings.AUTH_USER_MODEL),
26 | preserve_default=False,
27 | ),
28 | ]
29 |
--------------------------------------------------------------------------------
/EduLogging/lesson8/task4/library_logging.py:
--------------------------------------------------------------------------------
1 | # mortgage library
2 | #
3 | import logging
4 |
5 | logger = logging.getLogger(__name__)
6 | logger.addHandler(None)
7 |
8 | def get_current_rate(years):
9 | logger.debug('Fetching current interest rate for %d years', years)
10 | rate = 5.3 # Stub external service call
11 | logger.debug('Service returned interest rate %f', rate)
12 | return rate
13 |
14 | def get_monthly_payment(principal, years):
15 | logger.info('Calling mortgage calculator')
16 |
17 | if years > 50:
18 | logger.warn('Term greater than 50 years')
19 |
20 | mon_rate = get_current_rate(years)/1200
21 | payments = years * 12
22 | logger.debug('Number of monthly payments %d', payments)
23 | result = principal * (mon_rate/(1-math.pow((1+mon_rate), -payments)))
24 |
25 | logger.debug('Calculated result is %f', result)
26 | logger.debug('Leaving mortgage calculator')
27 | return result
--------------------------------------------------------------------------------
/turtle/interact.py:
--------------------------------------------------------------------------------
1 | # REF: ttps://docs.python.org/3.7/library/turtle.html#turtle.onkey
2 |
3 |
4 | from turtle import *
5 |
6 | def f():
7 | fd(50)
8 | lt(60)
9 |
10 | onscreenclick(goto) # 鼠标绑定
11 | onkey(f, "Up") # 键盘绑定
12 | listen() # set focus on screen / 不加这一句 onkey 不起作用, 但是 onclick 可以
13 |
14 | done() # 在 命令行(不马上退出) 或 ipython (能获取焦点) 中执行需要
15 |
16 | """
17 | mainloop() # 在命令行中执行
18 | Starts event loop - calling Tkinter's mainloop function.
19 | Must be last statement in a turtle graphics program.
20 | """
21 |
22 |
23 | """
24 | onclick / onrelease 不起作用, 待调试
25 |
26 | from turtle import *
27 | class MyTurtle(Turtle):
28 | def glow(self,x,y):
29 | self.fillcolor("red")
30 | def unglow(self,x,y):
31 | self.fillcolor("")
32 |
33 | turtle = MyTurtle()
34 | turtle.onclick(turtle.glow) # clicking on turtle turns fillcolor red,
35 | turtle.onrelease(turtle.unglow) # releasing turns it to transparent.
36 | """
--------------------------------------------------------------------------------
/EduLogging/lesson4/task5/task.html:
--------------------------------------------------------------------------------
1 |
2 | One thing you should be aware of when working with more advanced handlers, is how the logging system gracefully
3 | closes and cleans up any resources it is using. For example, if a handler is buffering log messages such as
4 | the MemoryHandler, then how does the logging system ensure those messages are handled.
5 |
6 |
7 | This is done through the "logging.shutdown()" function. The logging module will automatically register this function
8 | to be called when the interpreter is shutting down. So, normally you shouldn't have to worry about it. However, there
9 | are some cases where you might want to explicitly shutdown your handlers. For example, if you are debugging your
10 | handlers "close()" method or the handler is using some resources that may be uninitialized by the time
11 | the close() method is called.
12 |
13 |
14 | In this task, insert the call to explicitly shutdown the logging system.
15 |
--------------------------------------------------------------------------------
/EduLogging/lesson6/task3/file_config_loggers.py:
--------------------------------------------------------------------------------
1 | import logging
2 | import logging.config
3 |
4 | config = """
5 | [formatters]
6 | keys=formatter1
7 |
8 | [handlers]
9 | keys=handler1
10 |
11 | [loggers]
12 | keys=enter root logger instance name
13 |
14 | [formatter_formatter1]
15 | format=%(asctime)s %(levelname)s %(message)s
16 |
17 | [handler_handler1]
18 | class=StreamHandler
19 | args=()
20 | formatter=formatter1
21 |
22 | [logger_enter name of root logger instance]
23 | handlers=enter name of handler instance
24 | level=DEBUG
25 | """
26 |
27 | config_filename = 'logging.ini'
28 |
29 | def write_config_file(filename, data):
30 | with open(filename, 'w') as fp:
31 | fp.write(data)
32 |
33 |
34 | if __name__ == '__main__':
35 | write_config_file(config_filename, config)
36 |
37 | logging.config.fileConfig(config_filename)
38 |
39 | logging.debug('this is a debug message')
40 | logging.warning('this is a warning message')
--------------------------------------------------------------------------------
/EduLogging/lesson6/task7/dict_config_root.py:
--------------------------------------------------------------------------------
1 | import logging
2 | import logging.config
3 |
4 | logger = logging.getLogger(__name__)
5 |
6 | if __name__ == '__main__':
7 | log_config = {
8 | 'version': 1,
9 | 'disable_existing_loggers': False,
10 | 'handlers': {
11 | 'console': {
12 | 'class': 'logging.StreamHandler',
13 | 'formatter': 'formatter1',
14 | 'stream': 'ext://sys.stdout'
15 | }
16 |
17 | },
18 | 'formatters': {
19 | 'formatter1': {
20 | 'format': '%(asctime)s - %(levelname)s - %(message)s'
21 | }
22 | },
23 | 'enter name of root logger': {
24 | 'level': 'DEBUG',
25 | 'handlers': ['console', ]
26 | }
27 | }
28 |
29 | logging.config.dictConfig(log_config)
30 |
31 | logger.warn('This is a warning')
32 | logger.debug('test_mylib')
33 |
--------------------------------------------------------------------------------
/EduLogging/lesson2/task6/task.html:
--------------------------------------------------------------------------------
1 |
2 | When logging you should be aware of the type and size of data you might be logging.
3 |
4 |
5 | If you have a value that could be very large, such as long string, you might want to limit the output, so you
6 | don't make it difficult to look at your log output.
7 |
8 |
9 | One simple way to do this with string values is to use the format specification ".NNs", where NN is the number of
10 | characters to limit the string output. See the task for an example of this.
11 |
12 |
13 | In some cases, you might want to truncate an object, but indicate that the object was truncated. The common
14 | convention is to append the ellipses "..." to the end of the string to indicate there was more data. The following
15 | example shows how you could create a helper function that uses string slicing to do this.
16 |
17 |
18 | In this task, wrap the "big_list" object in a call to our "truncate()" helper function.
19 |
--------------------------------------------------------------------------------
/lecture/bit_program_design/10CalThreeKingdomsV2.py:
--------------------------------------------------------------------------------
1 | #coding:utf-8
2 | #CalThreeKingdomsV2.py
3 | import jieba
4 | excludes = {"将军","却说","荆州","二人","不可","不能","如此"}
5 | txt = open("threekingdoms.txt", "r", encoding='utf-8').read()
6 | words = jieba.lcut(txt)
7 | counts = {}
8 | for word in words:
9 | if len(word) == 1:
10 | continue
11 | elif word == "诸葛亮" or word == "孔明曰":
12 | rword = "孔明"
13 | elif word == "关公" or word == "云长":
14 | rword = "关羽"
15 | elif word == "玄德" or word == "玄德曰":
16 | rword = "刘备"
17 | elif word == "孟德" or word == "丞相":
18 | rword = "曹操"
19 | else:
20 | rword = word
21 | counts[rword] = counts.get(rword,0) + 1
22 | for word in excludes:
23 | del counts[word]
24 | items = list(counts.items())
25 | items.sort(key=lambda x:x[1], reverse=True)
26 | for i in range(10):
27 | word, count = items[i]
28 | print ("{0:<10}{1:>5}".format(word, count))
29 |
--------------------------------------------------------------------------------
/pygame/README.md:
--------------------------------------------------------------------------------
1 | #pygame
2 |
3 | 使用 python 播放音频
4 |
5 | ## 运行方法
6 | ```
7 | python3 pygame_demo_audio.py
8 | ```
9 |
10 | ## 运行版本环境
11 | ```
12 | xxx$ python3
13 | Python 3.5.1 (default, Jan 22 2016, 08:54:32)
14 | [GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin
15 | Type "help", "copyright", "credits" or "license" for more information.
16 | >>> import pygame
17 | >>> pygame.get_sdl_version()
18 | (1, 2, 15)
19 | >>> pygame.version.ver
20 | '1.9.2a0'
21 | ```
22 |
23 | ##pygame安装参考
24 | 下载与安装: http://www.pygame.org/download.shtml
25 |
26 | ###Mac OSX 安装
27 | Source: http://pygame.org/wiki/macintosh
28 |
29 | ```
30 | brew install python3 hg sdl sdl_image sdl_ttf portmidi libvorbis sdl_mixer --with-libvorbis
31 | hg clone http://bitbucket.org/pygame/pygame
32 | python3 setup.py build
33 | CC=/usr/bin/gcc python3 setup.py build
34 | sudo python3 setup.py install
35 | ```
36 |
37 | TODO: 待解决 mp3播放问题: https://github.com/justinmeister/Mario-Level-1/issues/5
38 |
--------------------------------------------------------------------------------
/sdn/akaedu/ch10/ex10.2.break.c:
--------------------------------------------------------------------------------
1 | /**
2 |
3 | 个程序的作用是:首先从键盘读入一串数字存到字符数组input中,然后转换成整型存到sum中,然后打印出来,一直这样循环下去。
4 |
5 | make && gdb ex10.2.break
6 |
7 | display 命令使得每次停下来的时候都显示当前sum的值
8 | undisplay 命令可以取消跟踪显示
9 | break 命令的参数也可以是函数名,表示在某个函数开头设断点
10 |
11 | (gdb) break 19 if sum != 0 # 条件断点
12 |
13 | -----
14 | 命令 描述
15 | break(或b) 行号 在某一行设置断点
16 | break 函数名 在某个函数开头设置断点
17 | break ... if ... 设置条件断点
18 | continue(或c) 从当前位置开始连续运行程序
19 | delete breakpoints 断点号 删除断点
20 | display 变量名 跟踪查看某个变量,每次停下来都显示它的值
21 | disable breakpoints 断点号 禁用断点
22 | enable 断点号 启用断点
23 | info(或i) breakpoints 查看当前设置了哪些断点
24 | run(或r) 从头开始连续运行程序
25 | undisplay 跟踪显示号 取消跟踪显示
26 |
27 |
28 | */
29 | #include
30 |
31 | int main(void)
32 | {
33 | int sum = 0, i = 0;
34 | char input[5];
35 |
36 | while (1) {
37 | // sum = 0; 缺少的赋值语句
38 | scanf("%s", input);
39 | for (i = 0; input[i] != '\0'; i++)
40 | sum = sum*10 + input[i] - '0';
41 | printf("input=%d\n", sum);
42 | }
43 | return 0;
44 | }
--------------------------------------------------------------------------------
/EduLogging/lesson1/task1/replacing_print.py:
--------------------------------------------------------------------------------
1 | from __future__ import print_function
2 | import math
3 | import logging
4 |
5 | def get_current_rate(years):
6 | logging.debug('Fetching current interest rate for %d years' % years)
7 | rate = 7.5 # Stub external service call
8 | logging.debug('Service returned interest rate %f' % rate)
9 | return rate
10 |
11 | def get_monthly_payment(principal, years):
12 | logging.debug('Calling mortgage calculator')
13 |
14 | mon_rate = get_current_rate(years)/1200
15 | payments = years * 12
16 | logging.debug('Number of monthly payments %d' % payments)
17 | result = principal * (mon_rate/(1-math.pow((1+mon_rate), -payments)))
18 |
19 | logging.debug('Calculated result is %f' % result)
20 | logging.debug('Leaving mortgage calculator')
21 | return result
22 |
23 | if __name__ == '__main__':
24 | payment = get_monthly_payment(100000, 30)
25 | logging.debug('Monthly payment is %f' % payment)
26 |
--------------------------------------------------------------------------------
/ns3/scratch/cfi16-plot-fig2-drop-packets.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | #coding: utf-8
3 | # Learn about API authentication here: https://plot.ly/python/getting-started
4 | # Find your api_key here: https://plot.ly/settings/api
5 |
6 | # Source https://plot.ly/matplotlib/bar-charts/
7 | #
8 |
9 | import matplotlib.pyplot as plt
10 | # import plotly.plotly as py
11 |
12 | dictionary = plt.figure()
13 |
14 | tcp_vars = [u'Reno', u'Vegas', u'HS', u'STCP', 'W+', 'BIC', 'CUBIC', 'YeAH']
15 | drop_packets = [2492, 6, 3102, 4872, 2965, 3675, 0, 1682]
16 |
17 |
18 | # ax.set_title('axes title')
19 | width = 0.5
20 | plt.bar(range(len(tcp_vars)), drop_packets, width, align='center',)
21 | plt.xticks(range(len(tcp_vars)), tcp_vars)
22 | plt.title("Figure 2: Total number of dropped packets")
23 | plt.xlabel('TCP variants')
24 | plt.ylabel('number of dropped packets')
25 | plt.axis([-1, 8, 0, 14000])
26 |
27 | plt.show()
28 | #plot_url = py.plot_mpl(dictionary, filename='mpl-dictionary')
29 |
--------------------------------------------------------------------------------
/sdn/mininet-tests/buffersizing/README.iperf:
--------------------------------------------------------------------------------
1 | This buffersizing binary search test requires an iperf that has
2 | been modified in two ways:
3 |
4 | * Larger SYN backlog (1024, instead of 2, to avoid dropped connections)
5 |
6 | * Wait a while before transmitting packets
7 | Without this change, iperf quickly connects to the server and fills
8 | the bottleneck queue, which causes subsequent SYNs to take longer to
9 | complete. This can be a pain when running the experiment. This patch
10 | is no perfect cure, but speeds things up a bit, by forcing iperf to
11 | sleep for 5 seconds (arbitrary) before sending data.
12 |
13 | To apply the changes, download iperf-2.0.5.tar.gz from:
14 |
15 | http://sourceforge.net/projects/iperf/
16 |
17 | To apply the patch:
18 |
19 | $ tar xzvf iperf-2.0.5.tar.gz
20 | $ cd iperf-2.0.5/src
21 | $ patch -p1 < iperf-2.0.5-wait-syn.patch
22 | $ cd ..
23 | $ (build the package)
24 |
25 | Alternatively, excecute build-patched-iperf.sh
26 |
27 |
--------------------------------------------------------------------------------
/sdn/linux-header/int-l64.h:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | typedef __signed__ short __s16;
4 |
5 | lxr: http://lxr.free-electrons.com/source/include/uapi/asm-generic/int-l64.h?v=3.13#L23
6 |
7 | * asm-generic/int-l64.h
8 | *
9 | * Integer declarations for architectures which use "long"
10 | * for 64-bit types.
11 | */
12 |
13 | #ifndef _UAPI_ASM_GENERIC_INT_L64_H
14 | #define _UAPI_ASM_GENERIC_INT_L64_H
15 |
16 | #include
17 |
18 | #ifndef __ASSEMBLY__
19 | /*
20 | * __xx is ok: it doesn't pollute the POSIX namespace. Use these in the
21 | * header files exported to user space
22 | */
23 |
24 | typedef __signed__ char __s8;
25 | typedef unsigned char __u8;
26 |
27 | typedef __signed__ short __s16;
28 | typedef unsigned short __u16;
29 |
30 | typedef __signed__ int __s32;
31 | typedef unsigned int __u32;
32 |
33 | typedef __signed__ long __s64;
34 | typedef unsigned long __u64;
35 |
36 | #endif /* __ASSEMBLY__ */
37 |
38 |
39 | #endif /* _UAPI_ASM_GENERIC_INT_L64_H */
40 |
--------------------------------------------------------------------------------
/sdn/mininet-tests/buffersizing-red/README.iperf:
--------------------------------------------------------------------------------
1 | This buffersizing binary search test requires an iperf that has
2 | been modified in two ways:
3 |
4 | * Larger SYN backlog (1024, instead of 2, to avoid dropped connections)
5 |
6 | * Wait a while before transmitting packets
7 | Without this change, iperf quickly connects to the server and fills
8 | the bottleneck queue, which causes subsequent SYNs to take longer to
9 | complete. This can be a pain when running the experiment. This patch
10 | is no perfect cure, but speeds things up a bit, by forcing iperf to
11 | sleep for 5 seconds (arbitrary) before sending data.
12 |
13 | To apply the changes, download iperf-2.0.5.tar.gz from:
14 |
15 | http://sourceforge.net/projects/iperf/
16 |
17 | To apply the patch:
18 |
19 | $ tar xzvf iperf-2.0.5.tar.gz
20 | $ cd iperf-2.0.5/src
21 | $ patch -p1 < iperf-2.0.5-wait-syn.patch
22 | $ cd ..
23 | $ (build the package)
24 |
25 | Alternatively, excecute build-patched-iperf.sh
26 |
27 |
--------------------------------------------------------------------------------
/EduLogging/lesson4/task6/task.html:
--------------------------------------------------------------------------------
1 |
2 | A handler can be removed from a logger using the Logger's removeHandler().
3 |
4 |
5 | At some point in your life with the logging module, you will encounter a problem
6 | with duplicate log messages. The likely cause is an extra handler was inserted
7 | somewhere in your logger hierarchy. Since log messages are sent up the
8 | hierarchy to each handler, you can get the same output duplicated. One extremely
9 | useful module to use in debugging problems like this is the "logging_tree"
10 | module by Brandon Rhodes. I encourage you to try this module after this course.
11 |
12 |
13 | In this code, we are simulating two stream handlers that have been added to
14 | our logging hierarchy.
15 |
16 |
17 | Add the necessary code to leave the root handler, but remove all the handlers
18 | from the "A.B" logger. Since, removeHandler() takes a handler object, we
19 | have to get the handler from the handlers attribute on the Logger.
20 |
--------------------------------------------------------------------------------
/lecture/bit_program_design/09CalStatisticsV1.py:
--------------------------------------------------------------------------------
1 | #coding:utf-8
2 | #CalStatisticsV1.py
3 | def getNum(): #获取用户不定长度的输入
4 | nums = []
5 | iNumStr = input("请输入数字(回车退出): ")
6 | while iNumStr != "":
7 | nums.append(eval(iNumStr))
8 | iNumStr = input("请输入数字(回车退出): ")
9 | return nums
10 |
11 | def mean(numbers): #计算平均值
12 | s = 0.0
13 | for num in numbers:
14 | s = s + num
15 | return s / len(numbers)
16 |
17 | def dev(numbers, mean): #计算方差
18 | sdev = 0.0
19 | for num in numbers:
20 | sdev = sdev + (num - mean)**2
21 | return pow(sdev / (len(numbers)-1), 0.5)
22 |
23 | def median(numbers): #计算中位数
24 | sorted(numbers)
25 | size = len(numbers)
26 | if size % 2 == 0:
27 | med = (numbers[size//2-1] + numbers[size//2])/2
28 | else:
29 | med = numbers[size//2]
30 | return med
31 |
32 | n = getNum() #主体函数
33 | m = mean(n)
34 | print("平均值:{},方差:{:.2},中位数:{}.".format(m, dev(n,m),median(n)))
--------------------------------------------------------------------------------
/EduLogging/lesson4/task6/remove_handler.py:
--------------------------------------------------------------------------------
1 | import logging
2 |
3 | def setup_loggers():
4 | stream_handler = logging.StreamHandler()
5 | fmt = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
6 | stream_handler.setFormatter(fmt)
7 |
8 | root = logging.getLogger()
9 | root.addHandler(stream_handler)
10 | #root.setLevel(logging.DEBUG)
11 |
12 | b_log = logging.getLogger('A.B')
13 | b_log.addHandler(stream_handler)
14 |
15 |
16 | if __name__ == '__main__':
17 | setup_loggers()
18 |
19 | c_log = logging.getLogger('A.B.C')
20 | c_log.warn('This message should be output once to console (but is output twice instead)')
21 |
22 | b_log = logging.getLogger(enter the logger name)
23 |
24 | # Remove all handlers attached to logger
25 | while len(b_log.handlers):
26 | handler = b_log.handlers[0]
27 | insert code to remove handler from A.B logger
28 |
29 | c_log.warn('This message should be output once to console')
30 |
--------------------------------------------------------------------------------
/lecture/bit_program_design/15HollandRadarDraw2Plotly.py:
--------------------------------------------------------------------------------
1 | #HollandRadarDraw2Ploly
2 |
3 | # Source: https://plot.ly/python/radar-chart/
4 |
5 | # Learn about API authentication here: https://plot.ly/pandas/getting-started
6 | # Find your api_key here: https://plot.ly/settings/api
7 |
8 | """
9 | pip install plotly
10 | """
11 |
12 | import os
13 | import plotly
14 | import plotly.plotly as py
15 | import plotly.graph_objs as go
16 |
17 | data = [go.Scatterpolar(
18 | r = [39, 28, 8, 7, 28, 39],
19 | theta = ['A','B','C', 'D', 'E', 'A'],
20 | fill = 'toself'
21 | )]
22 |
23 | layout = go.Layout(
24 | polar = dict(
25 | radialaxis = dict(
26 | visible = True,
27 | range = [0, 50]
28 | )
29 | ),
30 | showlegend = False
31 | )
32 |
33 | fig = go.Figure(data=data, layout=layout)
34 | # 标准例子是在线绘制 Online plot
35 | #py.iplot(fig, filename = "radar/basic")
36 | # 修改为离线绘制
37 | plotly.offline.plot(fig, filename = "15radar-plotly")
38 | os.system("open 15radar-plotly.html")
39 |
--------------------------------------------------------------------------------
/web_framework/mydjango/learn/templates/step06d.html:
--------------------------------------------------------------------------------
1 | Dict字典 for 遍历
2 |
3 |
4 |
5 | key: value
6 | {% for key, value in info_dict.items %}
7 | {{ key }}: {{ value }} {% if not forloop.last%},{% endif %}
8 | {% endfor %}
9 |
10 |
11 |
12 |
13 |
14 | list列表 for 遍历 + if判断跳过最后一个元素
15 | {% for item in List %}
16 | {{ item }} {% if not forloop.last%},{% endif %}
17 | {% endfor %}
18 |
19 |
20 | 空列表处理 empty
21 |
22 | {% for athlete in athlete_list %}
23 | {{ athlete.name }}
24 | {% empty %}
25 | 抱歉,列表为空
26 | {% endfor %}
27 |
28 |
29 | 备注
30 |
31 |
32 | 在for循环中还有很多有用的东西,如下:
33 |
34 | 变量 描述
35 | forloop.counter 索引从 1 开始算
36 | forloop.counter0 索引从 0 开始算
37 | forloop.revcounter 索引从最大长度到 1
38 | forloop.revcounter0 索引从最大长度到 0
39 | forloop.first 当遍历的元素为第一项时为真
40 | forloop.last 当遍历的元素为最后一项时为真
41 | forloop.parentloop
42 | 用在嵌套的 for 循环中,获取上一层 for 循环的 forloop (???)
43 |
44 |
--------------------------------------------------------------------------------
/ns3/practical_csocket2/TestSizes.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | int main(int argc, char *argv[]) {
6 | printf("CHAR_BIT is %d\n\n",CHAR_BIT); // Bits in a char (usually 8!)
7 |
8 | printf("sizeof(char) is %d\n", sizeof(char)); // ALWAYS 1
9 | printf("sizeof(short) is %d\n", sizeof(short));
10 | printf("sizeof(int) is %d\n", sizeof(int));
11 | printf("sizeof(long) is %d\n", sizeof(long));
12 | printf("sizeof(long long) is %d\n\n", sizeof(long long));
13 |
14 | printf("sizeof(int8_t) is %d\n", sizeof(int8_t));
15 | printf("sizeof(int16_t) is %d\n", sizeof(int16_t));
16 | printf("sizeof(int32_t) is %d\n", sizeof(int32_t));
17 | printf("sizeof(int64_t) is %d\n\n", sizeof(int64_t));
18 |
19 | printf("sizeof(uint8_t) is %d\n", sizeof(uint8_t));
20 | printf("sizeof(uint16_t) is %d\n", sizeof(uint16_t));
21 | printf("sizeof(uint32_t) is %d\n", sizeof(uint32_t));
22 | printf("sizeof(uint64_t) is %d\n", sizeof(uint64_t));
23 | }
24 |
--------------------------------------------------------------------------------
/EduLogging/lesson1/task7/task.html:
--------------------------------------------------------------------------------
1 |
2 | We mentioned in a previous task, there are 5 severity levels : CRITICAL, ERROR, INFO, WARNING, DEBUG.
3 |
4 |
5 | There are a few exceptions. First, a few of the levels have several constants defined.
6 |
7 | FATAL can be used instead of CRITICAL. There is also a fatal() helper method for this level. Both CRITICAL and
8 | FATAL share the same numeric log level of 50. They can be used interchangeably.
9 |
10 |
11 | WARN can also be used as a shortcut for WARNING. They mean the same thing.
12 |
13 |
14 | NOTSET is a special constant that represents the lowest possible log severity level. It has a value of 0. You should
15 | not log messages with this severity level. It is used when configuring loggers in the logging hierarchy.
16 |
17 |
18 | In this task, replace the logging level passed to basicConfig() with NOTSET. You will notice the output is
19 | similar to DEBUG, since NOTSET is a lower level (0) it includes every level.
20 |
--------------------------------------------------------------------------------
/web_framework/mydjango/learn/migrations/0002_article.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | from __future__ import unicode_literals
3 |
4 | from django.db import models, migrations
5 |
6 |
7 | class Migration(migrations.Migration):
8 |
9 | dependencies = [
10 | ('learn', '0001_initial'),
11 | ]
12 |
13 | operations = [
14 | migrations.CreateModel(
15 | name='Article',
16 | fields=[
17 | ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
18 | ('title', models.CharField(max_length=256, verbose_name='\u6807\u9898')),
19 | ('content', models.TextField(verbose_name='\u5185\u5bb9')),
20 | ('pub_date', models.DateTimeField(auto_now_add=True, verbose_name='\u53d1\u8868\u65f6\u95f4')),
21 | ('update_time', models.DateTimeField(auto_now=True, verbose_name='\u66f4\u65b0\u65f6\u95f4', null=True)),
22 | ],
23 | ),
24 | ]
25 |
--------------------------------------------------------------------------------
/EduLogging/lesson1/task2/log_output.py:
--------------------------------------------------------------------------------
1 | from __future__ import print_function
2 | import math
3 | import logging
4 |
5 | def get_current_rate(years):
6 | logging.debug('Fetching current interest rate for %d years' % years)
7 | rate = 7.5 # Stub external service call
8 | logging.debug('Service returned interest rate %f' % rate)
9 | return rate
10 |
11 | def get_monthly_payment(principal, years):
12 | logging.debug('Calling mortgage calculator')
13 |
14 | mon_rate = get_current_rate(years)/1200
15 | payments = years * 12
16 | logging.debug('Number of monthly payments %d' % payments)
17 | result = principal * (mon_rate/(1-math.pow((1+mon_rate), -payments)))
18 |
19 | logging.debug('Calculated result is %f' % result)
20 | logging.debug('Leaving mortgage calculator')
21 | return result
22 |
23 | if __name__ == '__main__':
24 | logging.basicConfig(level=logging.DEBUG)
25 | payment = get_monthly_payment(100000, 30)
26 | print('Monthly payment is %f' % payment)
27 |
--------------------------------------------------------------------------------
/EduLogging/lesson8/task2/private_logger.py:
--------------------------------------------------------------------------------
1 | import logging
2 |
3 | logger = logging.getLogger(__name__)
4 |
5 | class FirstClass():
6 | def __init__(self):
7 | self.log = logging.getLogger(__name__ + '.first_class')
8 |
9 | def do_something(self):
10 | self.log.debug('FirstClass do_something() called')
11 |
12 |
13 | class SecondClass():
14 | def __init__(self):
15 | self.log = logging.getLogger(__name__ + '.second_class')
16 |
17 | def do_something(self):
18 | self.log.debug('SecondClass do_something() called')
19 |
20 | if __name__ == '__main__':
21 | logging.basicConfig(level=logging.WARNING)
22 |
23 | logger.debug('module scope log output')
24 |
25 | first = FirstClass()
26 | first.do_something()
27 |
28 | second = SecondClass()
29 | second.do_something()
30 |
31 | first_logger = logging.getLogger(__name__ + '.first_class')
32 | first_logger.setLevel(logging.DEBUG)
33 | first.do_something()
34 | second.do_something()
35 |
36 |
37 |
--------------------------------------------------------------------------------
/EduLogging/lesson1/task2/task.html:
--------------------------------------------------------------------------------
1 |
2 | In the previous task, only the application output was written to standard output. You do not see any
3 | of the debugging statements.
4 |
5 |
6 | There is no output because a default "Logger" instance was created for you by the "logging" module and the
7 | logging level was set to WARNING level. This default "Logger" is also known as the "root" Logger.
8 |
9 |
10 | The WARNING level is an example of how we can tag our log statements with a severity level and perform filtering
11 | based on the level.
12 |
13 |
14 | The "basicConfig()" function is a helper method for doing basic configuration of logging. Without any parameters, it
15 | will create a StreamHandler that writes logging output to the "stderr" output stream. We can also pass a keyword
16 | argument "level" to set the default logger level.
17 |
18 |
19 | In this task using "basicConfig()", set the logging level to a value of "logging.DEBUG". This will allow our debug statements to show up on stderr.
20 |
--------------------------------------------------------------------------------