Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)That's it!
| !------------------------------------------------------------------------------- | |
| ! Xft settings | |
| !------------------------------------------------------------------------------- | |
| Xft.dpi: 96 | |
| Xft.antialias: false | |
| Xft.rgba: rgb | |
| Xft.hinting: true | |
| Xft.hintstyle: hintslight |
Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)That's it!
Original transcript: http://allisonrandal.com/2012/04/15/open-source-enlightenment/
這幾年來,我慢慢覺得,我們參與開源社群,就像是在一條道路上並肩而行:這不僅讓我們成為更好的程式設計者,也讓我們通過與人合作,而成為更好的人。
您可以將它想成一條修行之道,讓身而為人的我們能夠不斷成長。接下來,我想談談我對開源世界的個人觀點,希望能與您分享。
首先,人是一切開源專案的核心。程式碼是很重要,但最核心的永遠是人。
| (use '[clojure.core.match :only [match]]) | |
| (defn evaluate [env [sym x y]] | |
| (match [sym] | |
| ['Number] x | |
| ['Add] (+ (evaluate env x) (evaluate env y)) | |
| ['Multiply] (* (evaluate env x) (evaluate env y)) | |
| ['Variable] (env x))) | |
| (def environment {"a" 3, "b" 4, "c" 5}) |
| (defvar rcirc-max-message-length 420 | |
| "Messages longer than this value will be split.") | |
| (defun rcirc-send-message (process target message &optional noticep silent) | |
| "Send TARGET associated with PROCESS a privmsg with text MESSAGE. | |
| If NOTICEP is non-nil, send a notice instead of privmsg. | |
| If SILENT is non-nil, do not print the message in any irc buffer." | |
| ;; max message length is 512 including CRLF | |
| (let* ((response (if noticep "NOTICE" "PRIVMSG")) | |
| (oversize (> (length message) rcirc-max-message-length)) |
先前在《開源應用程式架構》 一書中,我介紹了 SocialCalc 這個在瀏覽器中運行的試算表編輯器,以取代伺服器為中心的 WikiCalc 架構。SocialCalc 在瀏覽器中執行所有的運算,只有在載入和儲存試算表時才會使用伺服器。
追求效能是 Socialtext 團隊在 2006 年時設計 SocialCalc 的主要目的。重點在於:在 JavaScript 環境下執行客戶端運算,儘管在當年的速度僅有伺服器端 Perl 運算的十分之一,但仍然勝過 AJAX 來回傳輸資料造成的網路延遲:
| package codemasters.lambda.learn.streams; | |
| import java.util.List; | |
| import java.util.Iterator; | |
| import java.util.ArrayList; | |
| import java.util.NoSuchElementException; | |
| import java.util.function.Supplier; | |
| import java.util.function.Consumer; | |
| import java.util.function.Predicate; |
| (defun eshell-last-argument (n m) | |
| (let* ((input (substring-no-properties | |
| (eshell-previous-input-string (1- m)))) | |
| (parse (with-temp-buffer | |
| (insert input) | |
| (nth (1- n) (reverse (eshell-parse-arguments | |
| (point-min) (point-max))))))) | |
| (eval parse))) | |
| (defun eshell-insert-last-word (n) |
| type zero = unit | |
| type 'a succ = unit -> 'a | |
| type one = zero succ | |
| type 'a plus_1 = 'a succ | |
| type 'a plus_2 = 'a plus_1 plus_1 | |
| type 'a plus_4 = 'a plus_2 plus_2 | |
| type 'a plus_8 = 'a plus_4 plus_4 |