This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Solarized Dark] | |
text(bold)=839496 | |
magenta(bold)=6c71c4 | |
text=839496 | |
white(bold)=fdf6e3 | |
green=859900 | |
red(bold)=cb4b16 | |
green(bold)=586e75 | |
black(bold)=073642 | |
red=dc322f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Latency Comparison Numbers | |
-------------------------- | |
L1 cache reference 0.5 ns | |
Branch mispredict 5 ns | |
L2 cache reference 7 ns 14x L1 cache | |
Mutex lock/unlock 25 ns | |
Main memory reference 100 ns 20x L2 cache, 200x L1 cache | |
Compress 1K bytes with Zippy 3,000 ns | |
Send 1K bytes over 1 Gbps network 10,000 ns 0.01 ms | |
Read 4K randomly from SSD* 150,000 ns 0.15 ms |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* In Java, BufferedWriter is a character streams class to handle the character data. | |
* Unlike bytes stream (convert data into bytes), you can just write the strings, arrays or characters data directly to file. | |
*/ | |
import java.io.BufferedWriter; | |
import java.io.File; | |
import java.io.FileWriter; | |
import java.io.IOException; | |
public class WriteToFileExample { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Chapter 1: Objects lessons | |
C++ object model | |
Each class object in C++ has a pointer named vptr which points to a table that store all virtual function pointers this class | |
has and a type_info object associated with this class in support of runtime type identification (RTTI) is also addressed | |
within the virtual table, usually within the table's first slot. And all objects of this class share this virtual table, I | |
think. | |
Problem: it's still like this for new C++ (C11)? | |
Inheritance | |
In the case of virtual inheritance, only a single occurrence of the base class is maintained (called a subobject) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//only iterator the list once, but call the random function n times. | |
int count = 0; | |
Node *head = list_head(); | |
int value; | |
for (p = head; p; p = p->next) { | |
if (random() % ++count == 0) { | |
value = p->data; | |
} | |
} | |
return value; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I do not choose to be a common person. | |
It's my right to be uncommon -- if I can. | |
I seek opportunity -- not security. | |
I do not wish to be a kept citizen, hunbled and dulled by having the state look after me. | |
I want to take the calculated risk, | |
to dream and to build, | |
to fail and to succeed. | |
I refuse to barter incentive for a dole; | |
I prefer the challenges of life to the guaranteed existence; | |
the thrill of fulfillment to the state calm of Utopia. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdarg.h> | |
#include <string.h> | |
#include <errno.h> | |
/* eprintf: print error message and exit */ | |
void eprintf(char *fmt, ...) { | |
va_list args; | |
fflush(stdout); | |
if (progname() != NULL) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
可以编写一个程序打印出自身的代码么?怎么写呢?为什么呢? | |
首先,当然是可以的,我们可以打开保存源代码的文件,把文件内容打印出来,当然就是代码本身了。但是,这里实际上程序和代码是分离的,不能算严格意义上的自我表示,二进制代码在cpu上执行,它读取出磁盘的文件并打印出来,依赖于代码文件,没有实现自包含,如果代码文件不在就无法工作了。 | |
下面一个C版本完全自包含的实现: | |
char b = 0x22;char n = 0xa;char *c="char b = 0x22;char n = 0xa;char *c=%c%s%c;main(){printf(a, b, a, b);}";main(){printf(c, b, c, b);} | |
不考虑代码存在文件里面结尾的那个换行符,它打印出了它自己。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Problem: Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum. | |
Difficulty: * | |
Solution: just recursive the tree and if a node is leaf and its val equal current sum value, return true; or find a non null child node of this node and sub sum with this node's value and call the function again. |
OlderNewer