- 博客(25)
- 资源 (25)
- 收藏
- 关注
原创 Python idioms, 2 of n
1) Don't do trivial assignment in __init__ of the classDon't:class Foo(object): def __init__(self): self.attr1 = 0 self.attr2 = '' self.attr3 = [] self.at
2012-09-26 09:36:06 1324
原创 Python performance 1 of n
If you would like to improve the running performance of Python, try1) Use profile/cProfile to benchmark your program, find the possible hotspot, switch to correct data structure to solve problem etc
2012-09-25 22:43:34 495
原创 Python idioms, 1 of n
Pythonic way to solve problems .1) Sort character in a strings = 'hello'''.join(sorted(s))2) Sort listtable = [(1, 'john', 23), \ (2, 'tom', 13), \ (3, 'lucy', 25), \
2012-09-25 22:35:17 1346
原创 smart pointers - C++11, 15 of n
The smart pointers provided by C++11 is straight forward enough. So just providing the interface here for reference.1) shared_ptr2) weak_ptrLow level interfaces3) unique_ptr
2012-09-24 15:26:03 1258
原创 clock and time - C++11, 14 of n
C++11 provides chrono library to deal with clock and time.1) Durationsstd::chrono::duration twentySeconds(20);std::chrono::duration> halfAMinute(0.5);std::chrono::duration> oneMillisecond(1);
2012-09-24 14:39:40 3829
原创 ratio - C++11, 13 of n
C++11 provides ratio lib to specify compile-time fractions and to perform compile-time arithmetic with them.1) The definitiontemplate class ratio {public: typedef ratio type; stati
2012-09-23 21:33:21 1991
原创 Concurrency 5, atomics - C++11, 12 of n
1) The high level interfacesFootnote: compare_exchange_strong's implementation pseudocode :bool compare_exchange_strong (T& expected, T desired){ if (this->load() == expected) {
2012-09-23 16:48:19 1352
原创 Concurrency 4, condition_variable - C++11, 11 of n
1) condition_variableCalled without the predicate, both wait_for() and wait_until() return the following enumeration class values:std::cv_status::timeout if the absolute timeout happenedstd:
2012-09-23 15:56:24 1633
原创 Concurrency 3, mutex and lock - C++11, 10 of n
1) The mutex and lock2) The lock_guard3) The unique_lock4) call_onceclass X {private: mutable std::once_flag initDataFlag; void initData() const;public: data getDat
2012-09-23 15:20:17 1597
原创 Concurrency 2, thread and promise - C++11, 9 of n
1) Low level interfaces:std::thread(launch::async, ...)std::promise, it enables you to provide the data (by using one of its set_...() functions) and All member functions that set the value or e
2012-09-23 10:57:10 2272
原创 Concurrency 1, async and future - C++11, 8 of n
1) High level interfaces:async() provides an interface to let a piece of functionality, a callable object run in the background as a separate thread, if possible.Class futureExample:#inclu
2012-09-23 10:20:49 2227
原创 Random - C++11, 7 of n
Since C++11, the C++ standard library provides a random-number library. The library provides many well-known distributions, and in addition, it provides multiple engines, which are the sources of rand
2012-09-18 11:48:47 2985
原创 IO Stream
1) The class hierarchy. basic_stringbuf is the heart of the IOStream of STLDesign: The IOStream library is designed with a rigid separation of responsibilities.(a) The classes derived from basic
2012-09-16 18:59:09 1184
原创 Regex - C++11, 6 of n
1) Raw stringR"delim(...)delim", where delim is a character sequence of at most 16 basic characters except the backslash, whitespace and parentheses.2) Note regex algorithm is greedy3) Main in
2012-09-16 18:19:04 4642 4
原创 string - C++11, 5 of n
(1) Gotchasin C++98, string literals, such as 'hello', was changed to const char*. Sticktly speaking, the original type of a literal such as 'hello' is const char[6]. But this type automatically con
2012-09-16 11:21:55 1817
原创 Case ignore compare strings
Solution 1: strcasecmp#include // for strcasecmp#include strcasecmp(s1.c_str(), s2.c_str())Solution 2: equal algorithm +lambda#include #include #include equal(s1.cbegin(), s1.cend()
2012-09-15 20:12:20 1416
原创 Remove elements while looping the containers
Gotchas: When removing elements from containers, be careful not to saw off the branch on which you are sitting.There is a big danger that you will remove an element to which your iterator is refer
2012-09-15 10:01:07 530
原创 Function Adapters and Binders - C++11, 4 of n
A function adapter is a function object that enables the composition of function objects with each other, with certain values, or with special functions.Function adaptors provided by C++11.1) Th
2012-09-14 23:05:33 1249
原创 Predicates
Gotchas (Effective STL also mentions this gotcha):1) Predicates should be always stateless.2) The operator() member function should be always constclass Nth { // function object that returns t
2012-09-14 22:17:48 569
原创 iterator adaptors - stream iterators
A stream iterator is an iterator adapter that allows you to use a stream as a source or destination of algorithms. In particular, an istream iterator can be used to read elements from an input strea
2012-09-14 15:51:25 700
原创 iterator adaptors - insert iterators
Three different insert iteratorsThe trick Operations:Implementations of insert iterators usually use the following two-step trick:1) Operator * is implemented as a no-op that simply return
2012-09-14 11:30:51 452
原创 operator [] for map and multimap
Gotchas:1) When calling operator [] with a key (index) which doesn't exist in the map, a new key-value pair gets inserted into the map automatically.std::map coll; // empty mapcout ("hello", 0)
2012-09-14 10:36:38 399
原创 urllib in Python 3
urllib/urllib2 in Python 2 have been cleaned up and consolidated in Python 3.Request submodule diagram
2012-09-06 15:37:16 548
原创 shared_ptr enable_shared_from_this - C++11, 3 of n
#include struct S: enable_shared_from_this{};Don't do this:S *p = new S;shared_ptr sp2 = p->shared_from_this(); // throws std::bad_weak_refDo this:shared_ptr p(new S);shared_ptr s
2012-09-03 00:14:36 1446
MPEG-4 ISO 标准 ISO/IEC14496-3 part3
2009-02-26
MPEG-4 ISO 标准 ISO/IEC14496-3 part2
2009-02-26
MPEG-4 ISO 标准 ISO/IEC14496-3 part1
2009-02-26
MPEG-4 ISO 标准 ISO/IEC14496-1 2004 third edition
2009-02-26
the c++ Standard library C++标准程序库—自修教程与参考手册.part4.rar(中文版)
2007-10-12
the c++ Standard library C++标准程序库—自修教程与参考手册.part3.rar(中文版)
2007-10-11
the c++ Standard library C++标准程序库—自修教程与参考手册.part2.rar(中文版)
2007-10-11
the c++ Standard library C++标准程序库—自修教程与参考手册.part1.rar(中文版)
2007-10-10
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人