2013年10月30日 星期三

雜事


2013.10.30

錶耳卡住新買的外套毛線,拿到 RSC 請師傅把毛線清一清,順便註冊。

服務小姐手上掛著迷你版的黑水鬼,頗有意思。



Mini-Lua 繼續卡在 symbol table,不知道怎麼實作比較好,

特別是 array 的部分,可以想想。

2013年10月20日 星期日

La Guitarra - Los Autenticos Decadentes


Tuve un problema de difícil solución,
en una época difícil de mi vida.
Estaba entre la espada y la pared,
y aguantando la opinión de mi familia.

Yo no quería una vida normal,
no me gustaban los horarios de oficina.
Mi espíritu rebelde se reía
del dinero, del lujo y el comfort.

Y tuve una revelación,
ya se que quiero en esta vida.
Voy a seguir mi vocación
será la música mi techo y mi comida.

Porque yo
no quiero trabajar,
no quiero ir a estudiar,
no me quiero casar.

Quiero tocar la guitarra todo el día,
y que la gente se enamore de mi voz.

Porque yo
no quiero trabajar,
no quiero ir a estudiar,
no me quiero casar.

Y en la cabeza tenia
la voz de mi viejo,
que me sonaba como
un rulo de tambor.

Vos, mejor que te afeites,
mejor que madures, mejor que labores.
Ya me cansé de que me tomes la cerveza,
te voy a dar con la guitarra en la cabeza.

Vos, mejor que te afeites,
mejor que madures, mejor que labores.
Ya me cansé de ser tu fuente de dinero,
voy a ponerte esa guitarra de sombrero.

Y tuve una revelación,
ya se que quiero en esta vida.
Voy a seguir mi vocación
será la música mi techo y mi comida.

Porque yo
no quiero trabajar,
no quiero ir a estudiar,
no me quiero casar.

Quiero tocar la guitarra todo el día,
y que la gente se enamore de mi voz.

Porque yo
no quiero trabajar,
no quiero ir a estudiar,
no me quiero casar.

Y en la cabeza tenia
la voz de mi viejo,
que me sonaba como
un rulo de tambor.

Vos, mejor que te afeites,
mejor que madures, mejor que labores.
Ya me cansé de que me tomes la cerveza,
te voy a dar con la guitarra en la cabeza.

Vos, mejor que te afeites,
mejor que madures, mejor que labores.
Ya me cansé de ser tu fuente de dinero,
voy a ponerte esa guitarra de sombrero.

2013年10月15日 星期二

Communicate your intentions through your code


Book: Implementation Patterns: Kent Beck



很棒的書,特別是寫了幾年的爛東西後,看這個特別有感覺。

  • Programs are read more often than they are written.
  • There is no such thing as “done”.  Much more investment will be spent modifying programs than developing them initially.
  • They are structured using a basic set of state and control flow concepts.
  • Readers need to understand programs in detail and in concept.  Sometimes they move from detail to concept, sometimes from concept to detail.

Using patterns helps programmers write reasonable solutions to common problems, leaving more time, energy, and creativity to apply to the truly unique problems.


Three values that are consistent with excellence in programming are
  • Communication
  • Simplicity
  • Flexibility

The implementation patterns aren’t the way they are “just because”. Each one expresses one or more of the values of communication, simplicity, and flexibility.  Principles are another level of general ideas, more specific to programming than the values, that also form the foundation of the patterns.


Several principles:
  • Local Consequences
  • Minimize Repetition
  • Logic and Data Together
  • Symmetry
  • Declarative Expression
  • Rate of Change



2013年10月14日 星期一

SQLite Compiler


The Architecture Of SQLite [http://www.sqlite.org/arch.html]


SQL Command Processor 可以往 source code 裡面看:
CAPI3REF: Compiling An SQL Statement
KEYWORDS: {SQL statement compiler}

The sqlite3_prepare function compiles an SQL statement, and produces an equivalent internal object. This object is commonly referred to as a prepared statement in database literature, and is implemented as a bytecode program in SQLite. A bytecode program is an abstract representation of an SQL statement that is run on a virtual machine or an interpreter. For more information, see the later section, Bytecode Programming Language. I use the terms bytecode program and prepared statement interchangeably in this book.


看圖片 SQL compiler 可以再分成三段:
  1. Tokenizer
  2. Parser
  3. Code generator

接下來就往 source code 裡面看進去了。繼續努力!
SQLITE_API int sqlite3_prepare(
  sqlite3 *db,            /* Database handle */
  const char *zSql,       /* SQL statement, UTF-8 encoded */
  int nByte,              /* Maximum length of zSql in bytes. */
  sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
  const char **pzTail     /* OUT: Pointer to unused portion of zSql */
);

註解寫的蠻詳細的

((應該使用 sqlite3_prepare_v2,不過因為相容性,所以舊的 API 也會留下來))

現在追到 sqlite3LockAndPrepare,看字面有 lock ((mutex))。



Lock 的 methods 有一對,sqlite3_mutex_enter() 以及 sqlite3_mutex_leave()。

sqlite3BtreeEnterAll() 及 sqlite3BtreeLeaveAll() 就是 backend,裡面有三個主要 modules,B+ tree,Pager,以及 OS Interface ((可以想像 B+ tree 是最頂層的抽象資料結構,每個 file fragments 以 pagers 抽象化,最後 implementor 當然就是 OS 的 file system,這個就看是 Windows 或者是 Unix 或者是你想的到的))。

((這是我的猜測與想像,B+ tree 應該是這樣子的吧?!))



鬼扯一堆,最重要的還是 sqlite3Prepare(),這個得仔細看下去了!
  1. Initialize.
  2. Try to get a read lock on all database schemas.
  3. sqlite3RunParser()
  4. sqlite3VdbeSetSql()



然後這個應該是關鍵:LEMON-generated LALR(1) parser

The Lemon Parser Generator [http://www.sqlite.org/src/doc/trunk/doc/lemon.html]



The main parser program: sqlite3Parser()


[FWD] TimeUnit


http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/TimeUnit.html



A TimeUnit represents time durations at a given unit of granularity and provides utility methods to convert across units, and to perform timing and delay operations in these units.



這是很不錯的設計。

有時候寫程式常常忘記用 second 為單位,或者是用 millisecond 為單位。

何不讓 code 變成 oral language?

2013年10月11日 星期五

[FWD] Bloom filters

WIKI: http://en.wikipedia.org/wiki/Bloom_filter

Tutorial: http://billmill.org/bloomfilter-tutorial/

實作細節不外乎 bloom filter 變形以及 hash functions 的選擇。



為什麼會講到 bloom filters?

因為雲端病毒碼就是利用這個技術減少 signatures 的大小。

如果能夠穿過許多道 bloom filters 引擎才上網把完整的 signatures 抓下來。