Skip to content

Instantly share code, notes, and snippets.

View ichaos's full-sized avatar

Jin Chen ichaos

  • Fudan University
View GitHub Profile
@ichaos
ichaos / solarized-dark.xcs
Created November 1, 2012 08:15 — forked from clyfish/solarized-dark.xcs
xshell solarized dark color theme
[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
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
@ichaos
ichaos / WriteToFileExample.java
Created March 25, 2013 11:43
Java: Write to file
/*
* 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 {
@ichaos
ichaos / Inside the C++ object model
Last active December 16, 2015 03:49
{读书笔记} C++ language
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)
@ichaos
ichaos / random select in a list
Created April 15, 2013 14:18
How to choose a item from a list randomly ?
//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;
@ichaos
ichaos / Entrepreneur's credo
Last active December 16, 2015 06:08
什么是有趣的事?
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.
@ichaos
ichaos / eprintf.c
Last active December 16, 2015 13:19
C: code snippets
#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)
@ichaos
ichaos / selfprint
Last active December 16, 2015 17:50
self print program
可以编写一个程序打印出自身的代码么?怎么写呢?为什么呢?
首先,当然是可以的,我们可以打开保存源代码的文件,把文件内容打印出来,当然就是代码本身了。但是,这里实际上程序和代码是分离的,不能算严格意义上的自我表示,二进制代码在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);}
不考虑代码存在文件里面结尾的那个换行符,它打印出了它自己。
@ichaos
ichaos / Path Sum
Last active December 17, 2015 18:59
LeetCode
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.
@ichaos
ichaos / Quorum.md
Last active December 17, 2015 19:29
Distributed system
Quorum system (最低法定人数系统)