渴死的火烈鸟
standalone · 共 356 篇文章
hexadecimal string to byte array in python
hex_string = "deadbeef" Convert it to a string (Python ≤ 2.6): hex_data = hex_string.decode("hex") hex_data "\xde\xad\xbe\xef" or since Python 2.7 and Python 3.0: bytearray.fromhex(hex_data) bytearray(b'\xde\xad\xbe\xef')
2017-09-25 09:58 · 评论(0) · Python
size of array
#define num(x) (sizeof (x) / sizeof (*x)) int main(){ int number[10] = {1,1,1,1,1,1}; char *teststr[20] = {"","","","","","","","",""}; printf("Size of number[10] is %d\n", (int)num(number)); printf("Size of teststr[20] is %d\n", (int)num(teststr)); return 0; }
2017-08-06 22:53 · c · 评论(0)
std::map
[code="c++"] std::map mymap; std::map > mmap; mmap['a'].insert("hello"); mmap['a'].insert("hello1"); map >::iterator iter = mmap.begin(); for(;iter!=mmap.end();++iter){ cout << iter->first << endl; set::iterator itt = iter->second.begin(); for (;itt != iter->second.end(); ++itt){ cout << *itt << en…
2017-08-06 22:41 · c++ · 评论(0)
Shell Parameter Expansion
http://stackoverflow.com/questions/12671406/bash-removing-part-of-a-string var="Memory Used: 19.54M" var=${var#*: } # Remove everything up to a colon and space var=${var%M} # Remove the M at the end
2016-01-16 13:30 · 评论(0) · Bash
lost on Py_DECREF/INCREF when handling PyList_Append in Python C extension
The main hint is in the docs, if it says 'Steals a reference' than the function basically takes ownership, if it says 'New Reference' than it did an INCREF for you, if nothing is said it probably does an INCREF and DECREF pair as needed. http://stackoverflow.com/questions/10863669/lost-on-py-decref…
How can I convert a character to a integer in Python, and viceversa?
Use chr() and ord(): chr(97) 'a' ord('a') 97
2015-10-27 14:38 · python · 评论(0) · Python
How to build a Ruby hash out of two equally-sized arrays?
ruby-doc.org/core-2.1.2/String.html
2014-09-03 15:54 · ruby · 评论(0) · Ruby
typedef struct in c
typedef struct atom { int element; struct atom *next; }; vs. typedef struct { int element; struct atom *next; } atom; http://stackoverflow.com/questions/18806392/typedef-struct-declarations
2014-04-29 16:18 · c · 评论(0) · C
An Example of Using std::tr1::bind
[code="c++"] #include #include using std::tr1::bind; using std::tr1::function; using std::tr1::placeholders::_1; using std::tr1::placeholders::_2; class CTest { public: int test( int a, int b , int c, int d) { return a - b + c*d; } }; int main() { CTest obj; std::tr1::function func = bind(&CTest::t…
2014-03-10 16:49 · c++ · 评论(0) · C++
c++中的virtual inheritance
http://stackoverflow.com/questions/21558/in-c-what-is-a-virtual-base-class 主要是为了避免歧义。
2014-01-27 10:20 · c++ · 评论(0) · C++
C中的宏 [Macro in C]
最近在学习c,话说从java转向c真的蛮痛苦。Anyway,学习就是一份好经历。 看到如下一段code: #define APP_TOOL_OP_TYPES(f) \ f(SIMPLE, "simple", FALSE) \ f(JSON, "json", TRUE) \ f(PYTHON, "python", TRUE) \ typedef enum { APP_TOOL_OP_INVALID, #define DEFINE_OP_TYPE(_x, _y, _z) APP_TOOL_OP_##_x, APP_TOOL_OP_TYPES(DEFINE_OP_TYPE) #undef DEFI…
2014-01-26 10:04 · c · 评论(0) · C · macro
Java NIO
看了这个java nio的教程,明白了什么是Selector.wakeUp() http://ifeve.com/selectors/ wakeUp() 某个线程调用select()方法后阻塞了,即使没有通道已经就绪,也有办法让其从select()方法返回。只要让其它线程在第一个线程调用select()方法的那个对象上调用Selector.wakeup()方法即可。阻塞在select()方法上的线程会立马返回。 如果有其它线程调用了wakeup()方法,但当前没有线程阻塞在select()方法上,下个调用select()方法的线程会立即“醒来(wake up)”。
2014-01-10 21:28 · java · 评论(0) · Java · nio
hadoop-2.2.0 build failure due to missing dependancy
The bug and fix is at https://issues.apache.org/jira/browse/HADOOP-10110
2014-01-06 13:18 · hadoop · 评论(0) · Hadoop
java i18n exception
http://www.cab.u-szeged.hu/WWW/java/tutorial/i18n/exception/subclass.html
2013-11-11 17:37 · 评论(0)