├── .gitignore ├── AwesomeCourses.md ├── Cpp_Notes.md ├── EmacsRef.org ├── Functional_Notes.md ├── Git_Notes.md ├── Github_Tips.org ├── Go_Index.md ├── Javascript_Notes.md ├── K8S_Notes.md ├── Miscellaneous.md ├── MongoDB.org ├── PythonChallenge.md ├── Python_Index.md ├── README.md └── ShellNotes.org /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | _* 3 | *~ 4 | -------------------------------------------------------------------------------- /AwesomeCourses.md: -------------------------------------------------------------------------------- 1 | Awesome courses 2 | ------ 3 | 4 | 1. [The Art of Approximation in Science and Engineering by MIT][appr] 5 | 2. [Practical Programming in C by MIT][c] 6 | 3. [Python Review by MIT][python] 7 | 4. [Natural Language Processing][nlp] 8 | 5. [Javascript 修炼 by Stanford][callback] 9 | 6. [Web Application by Stanford][webapp] 10 | 7. [Operating System -- Standford(pintos)][pintos] 11 | 8. [Operating System Engineering by MIT6.828 xv6 jos][os-mit] 12 | 9. [the matasano crypto challenges][crypto] 13 | 10. [MIT 6.830 Database (impleement RMDB)][db-mit] 14 | 11. [MIT 6.824 Distributed System (Go implement KV db)][dis-mit] 15 | 12. [Programming Languages by University of Washington][pro-lang] 16 | 13. [Functional Programming in Scala][scala] 17 | 14. [Compilers by Stanford][compilers] 18 | 15. [Computer System Security by Stanford][security] 19 | 16. [Design of Computer Programs][programs-design] 20 | 21 | --- 22 | 1. [Python tiny web framework][batpod] 23 | 2. [Express Examples][express] 24 | 25 | 26 | [appr]: 27 | http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-055j-the-art-of-approximation-in-science-and-engineering-spring-2008/readings/ 28 | [c]: 29 | http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-087-practical-programming-in-c-january-iap-2010/lecture-notes/ 30 | [python]: 31 | http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-189-a-gentle-introduction-to-programming-using-python-january-iap-2008/assignments/ 32 | [nlp]: 33 | http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-863j-natural-language-and-the-computer-representation-of-knowledge-spring-2003/lecture-notes/ 34 | [callback]: http://callbackjs.me/ 35 | [webapp]: http://www.stanford.edu/class/cs142/cgi-bin/projects.php 36 | [pintos]: http://www.stanford.edu/class/cs140/projects/pintos/pintos_1.html 37 | [batpod]: https://github.com/fengsp/batpod 38 | [express]: https://github.com/visionmedia/express/tree/master/examples 39 | [os-mit]: https://pdos.csail.mit.edu/6.828/2014/schedule.html 40 | [crypto]: http://cryptopals.com/ 41 | [db-mit]: http://db.csail.mit.edu/6.830/ 42 | [dis-mit]: http://nil.csail.mit.edu/6.824/2015/schedule.html 43 | [pro-lang]: https://courses.cs.washington.edu/courses/cse341/13wi/ 44 | [scala]: https://www.coursera.org/course/progfun 45 | [compilers]: https://www.coursera.org/course/compilers 46 | [security]: http://css.csail.mit.edu/6.858/2015/schedule.html 47 | [programs-design]: 48 | https://www.udacity.com/course/design-of-computer-programs--cs212 49 | -------------------------------------------------------------------------------- /Cpp_Notes.md: -------------------------------------------------------------------------------- 1 | ### Read 2 | + [CppTemplateTutorial](https://github.com/wuye9036/CppTemplateTutorial) 3 | + [CPP core guidelines](http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines) 4 | + [C++ FAQ](https://isocpp.org/faq) 5 | + 6 | + 7 | + 8 | + [EECS 381](http://www.umich.edu/~eecs381/) 9 | + [EECS 381 handouts](http://www.umich.edu/~eecs381/handouts/handouts.html) 10 | + [Herb Sutter's Blog](https://herbsutter.com/) 11 | 12 | ### Link 13 | + [<程序员的自我修养: 链接、装载与库>](https://book.douban.com/subject/3652388/) 14 | ### Good repos 15 | + [muduo](https://github.com/chenshuo/muduo): Code structure, cmake example, boost usages, how to write contrib/ 16 | + [rocksplicator](https://github.com/pinterest/rocksplicator): fbthrift usage, concurrent programming, how to write tests 17 | + [rethinkdb](https://github.com/rethinkdb/rethinkdb) 18 | + [TODO: nanolog](https://github.com/Iyengar111/NanoLog) 19 | + [TODO: fbthrift profiling and tracing](https://github.com/facebook/fbthrift/blob/master/thrift/lib/cpp/VirtualProfiling.cpp) 20 | + [TODO: rockslicator tgrep](https://github.com/pinterest/rocksplicator/tree/master/tgrep) 21 | + [TODO: glog stacktrace](https://github.com/google/glog/blob/master/src/stacktrace.h) 22 | ### FAQ 23 | + [Variable number of arguments in C++](http://stackoverflow.com/a/16338804/1035859) 24 | + [std::forward arguments](http://stackoverflow.com/questions/7257144/when-to-use-stdforward-to-forward-arguments) 25 | + [marco vs const](http://stackoverflow.com/questions/6393776/what-is-the-difference-between-a-macro-and-a-const-in-c) 26 | -------------------------------------------------------------------------------- /EmacsRef.org: -------------------------------------------------------------------------------- 1 | #+TITLE: The Art of Emacs 2 | #+AUTHOR: Wilbeibi 3 | #+EMAIL: wilbeibi AT gmail DOT com 4 | #+LANGUAGE: en 5 | #+OPTIONS: H:2 num:nil toc:t \n:nil @:t ::t |:t ^:nil f:t *:t TeX:t LaTeX:t skip:nil p:nil 6 | 7 | 8 | * Tricks 9 | - *M-x flyspell-mode* 10 | Online word spell checking, _*M-$* to check current word_ 11 | - *C-h m* 12 | Get help, manual and shortkey of current mode 13 | - *M-x toggle-debug-on-quit* 14 | 使用这条命令后,每次卡住后,马上按C-g, 15 | 就会打出当前执行函数的调用栈,是哪个函数造成的卡住,也就一目了然 16 | 了。然后根据这个造成卡住的函数属于哪个扩展包,再分别想解决办法 17 | - *F5* 18 | Goto-line 19 | - *M-x load-file ~/.emacs* 20 | Modify emacs and make it effect without reboot 21 | - *M-x artist-mode* 22 | Draw shapes in geek style 23 | - *M-x insert-table* 24 | Insert the table as you wanted 25 | - *C-up/down/left/right* 26 | Resize the split window 27 | - *C-j* 28 | Newline and indent 29 | - *C-x z* 30 | repeat last command 31 | - *M-x eval-buffer* 32 | load .emacs without restarting it 33 | - *M-x dired* to open current file 34 | - R to rename 35 | - C-x k to (go back to original buffer) 36 | - C-c C-e b 37 | publish, export to HTML 38 | 39 | * Navigating & Editing 40 | - *M-<* *M->* 41 | Begin of buffer/ End of buffer 42 | - *C-v* *M-v* 43 | Page Down and Page Up 44 | - *C-M-\* 45 | Auto typesetting 46 | - *C-Backspace* 47 | Kill a word backward 48 | - *M-x replace _oldstr_ RET _newstr_ VET* 49 | replace specific string 50 | - *C-h f func_name* 51 | Get description of the function 52 | - *C-x h* 53 | select all 54 | - *C-x o* 55 | Switch between windows 56 | - *M-<* *M->* 57 | Move to the head/end of text 58 | - *C-L* 59 | Move cursor to the center of the window 60 | - *M-=* 61 | Word count 62 | - *C-v* *M-v* 63 | PageUp and PageDown 64 | - *M-a* *M-e* 65 | Head of sentence, tail of sentence 66 | - *M-<* *M->* 67 | Head or tail of entire buffer 68 | - *M-=* 69 | Word count 70 | 71 | * ORG-mode Tips 72 | ** Basic keys 73 | - *C-c C-x C-v* 74 | View inline picture 75 | - *C-c C-t* 76 | So, let's mark the _TODO_ item _DONE_ by moving the cursor 77 | onto that line and hitting C-c C-t, which runs the 78 | command org-todo. 79 | - *C-c C-s* 80 | C-c C-s to run _org-schedule_. 81 | - *C-c a t* 82 | Press C-c a t to enter the global todo list. 83 | - *C-c C-c* 84 | Add _tags_ as ordered. 85 | - *Description List* 86 | use ‘ :: ’ to separate the term from the description. 87 | - *Agenda files* 88 | 'C-c [' Add current file to the list of agenda files. 89 | - *Switch buffers: C-x C-b* 90 | - *C-u C-c .* 91 | Insert timestamp 92 | - *C-u TAB* 93 | Switch Overview/Content/Details 94 | - Insert Picture 95 | #+CAPTION: This is the caption for the next figure link (or table) 96 | #+NAME: fig:SED-HR4049 97 | Name in it [[]] 98 | - Subscripts and superscripts 99 | 10^30, R_{sun} 100 | ** Navigating 101 | - *C-c C-u* 102 | up 103 | - *C-c C-f/b* 104 | forward or back in same level 105 | - *C-c C-p/n* 106 | jump to previous/next heading 107 | ** GTD 108 | - *M-shift-RET* 109 | Start a TODO headline. 110 | - *S-LEFT/RIGHT* 111 | Change states between TODO/DONE/INPROGRESS 112 | - *C-c .* 113 | Add a timestamp, 'S-LEFT/RIGHT' to change at cursor by one day. 114 | - *C-c C-d* 115 | to insert a _DEADLINE_ keyword with a stamp. 116 | - *C-c C-s* 117 | Insert a _SCHEDULED_ keyword with a stamp. 118 | ** Mess 119 | *** Reference 120 | [[http://orgmode.org/worg/org-tutorials/orgtutorial_dto.html][David O'Toole Org tutorial]] 121 | *** Syntax 122 | make words *bold*, /italic/ , _underlined_, =code= 123 | and ~verbatim~, and, if you must, ‘+strike-through+’. 124 | *** insert code 125 | - 46 | - git push origin --delete (or git push origin :) 47 | * roll back 48 | - git reflog show (find revision hash) 49 | - git checkout . 50 | 51 | * undo a commit 52 | - [[http://stackoverflow.com/questions/927358/undo-the-last-git-commit][Stackoverflow anwser]] 53 | - git reset --hard HEAD^1 54 | - edit & commit 55 | or 56 | - git rm --cached badfile 57 | - edit & git commit --amend 58 | 59 | * manually merge 60 | - git pull (will auto merge unconflict parts) 61 | - edit conflict file (edit file with <<< >>> ) 62 | - git add & commit 63 | * delete remote file 64 | - git rm --cached 'merge-*' : delete remote file start with merge- 65 | - git commit & push 66 | * about git commit -a 67 | - '-a' will auto add the modified file which was git add before 68 | but for new file, we have to add, or create alias 69 | 70 | * git reset 71 | - what is head: http://stackoverflow.com/questions/2304087/what-is-git-head-exactly 72 | - git reset -hard: http://stackoverflow.com/questions/9529078/git-for-a-beginner-git-reset-hard-head 73 | - git reset in plain english: http://stackoverflow.com/questions/2530060/can-you-explain-what-git-reset-does-in-plain-english 74 | * Tags 75 | - *list all tags* git tag -l 76 | * repo rename 77 | - git remote set-url origin new_url 78 | -------------------------------------------------------------------------------- /Go_Index.md: -------------------------------------------------------------------------------- 1 | ## Libraries 2 | ### [gorm](https://godoc.org/github.com/jinzhu/gorm) 3 | + [Tutorial](http://doc.gorm.io/crud.html) 4 | + default value: `gorm:"default:18"` 5 | -------------------------------------------------------------------------------- /Javascript_Notes.md: -------------------------------------------------------------------------------- 1 | # Javascript Notes 2 | ---- 3 | ## Knowledge 4 | 1. [JSLint 文档][jslint] 5 | 2. [理解Javascript的闭包][closure] 6 | 3. [学习Javascript闭包(Closure)][closure2] 7 | 3. [undefined与null的区别][null] 8 | 4. [Javascript异步编程的4种方法][async] 9 | 5. [Javascript编程风格][style] 10 | 6. [Javascript继承机制的设计思想][inheritance] 11 | 7. [什么是Event Loop?][event_loop] 阮老师写错了,勿点 12 | 8. [A re-introduction to JavaScript (JS Tutorial)][reintro] 13 | 9. [Immediately-Invoked Function Expression (IIFE)][iife] 14 | 10. [how does Array.prototype.slice.call() work?][slice] 15 | 11. [MDN JavaScript Guide][mdn] 16 | 12. [Inheritance and the prototype chain][chain] 17 | 13. [Working with objects][obj] 18 | 14. [What does the exclamation mark do before the function?][excla] 19 | 15. [Why do you need to invoke an anonymous function on the same line?][in_an] 20 | 16. [how to stop Javascript forEach?][break] 21 | 17. [JavaScript “this” keyword][jthis] 22 | 18. [Principles of Writing Consistent, Idiomatic JavaScript][jstyle] 23 | 19. [Airbnb JavaScript Style Guide][astyle] 24 | 20. [You-Dont-Know-JS][dont] 25 | 26 | 27 | ## Nodejs 28 | 1. [Difference between readFile and readFileSync][readfile] 29 | 2. [module.exports vs exports in nodeJS][exports] 30 | 3. [How do I get started with Node.js][best_start] 31 | 4. [Error handling principles for NodeJS + Express apps][errorh] 32 | 5. [Understanding Error-First Callbacks][errfirst] 33 | 6. [Designing Singletons][single] 34 | 7. [How `require()` Actually Works][require] 35 | 8. [《Node.js 包教不包会》][bao] 36 | 37 | ## Libraries 38 | 1. Lodash 39 | 2. chalk 40 | 3. shelljs 41 | 42 | ## Miscellaneous 43 | 1. [Javascript 最大堆栈数量][stack_max] 44 | 2. [Github上有趣的js资料][collection1] 45 | 3. [Debugging Javascript][debug] 46 | 47 | 48 | Update: Fri Aug 8 00:03:11 EDT 2014 49 | 50 | 51 | [jslint]: http://jiongks.name/blog/jslint-docs-zh-cn/ 52 | [stack_max]: http://ourjs.com/detail/53a650fa41a7309c4200000e 53 | [closure]: http://coolshell.cn/articles/6731.html 54 | [null]: http://ourjs.com/detail/53a650fa41a7309c4200000e 55 | [async]: http://www.ruanyifeng.com/blog/2012/12/asynchronous%EF%BC%BFjavascript.html 56 | [style]: http://www.ruanyifeng.com/blog/2012/04/javascript_programming_style.html 57 | [inheritance]: http://www.ruanyifeng.com/blog/2011/06/designing_ideas_of_inheritance_mechanism_in_javascript.html 58 | [closure2]: http://www.ruanyifeng.com/blog/2009/08/learning_javascript_closures.html 59 | [event_loop]: http://www.ruanyifeng.com/blog/2013/10/event_loop.html 60 | [collection1]:http://jianshu.io/p/7c9aa9508641 61 | [reintro]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript 62 | [debug]: https://developer.chrome.com/devtools/docs/javascript-debugging 63 | [iife]: http://benalman.com/news/2010/11/immediately-invoked-function-expression/ 64 | [slice]: http://stackoverflow.com/questions/7056925/how-does-array-prototype-slice-call-work 65 | [readfile]: http://stackoverflow.com/questions/17604866/difference-between-readfile-and-readfilesync 66 | [exports]: http://stackoverflow.com/questions/7137397/module-exports-vs-exports-in-nodejs 67 | [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide 68 | [chain]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Inheritance_and_the_prototype_chain 69 | [obj]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects 70 | [excla]: http://stackoverflow.com/questions/3755606/what-does-the-exclamation-mark-do-before-the-function 71 | [in_an]: http://stackoverflow.com/questions/1140089/why-do-you-need-to-invoke-an-anonymous-function-on-the-same-line 72 | [best_start]: http://stackoverflow.com/questions/2353818/how-do-i-get-started-with-node-js 73 | [errorh]: http://stackoverflow.com/questions/7151487/error-handling-principles-for-nodejs-express-apps 74 | [errfirst]: http://fredkschott.com/post/2014/03/understanding-error-first-callbacks-in-node-js/ 75 | [break]: http://stackoverflow.com/questions/6260756/how-to-stop-javascript-foreach 76 | [jthis]: http://stackoverflow.com/questions/3127429/javascript-this-keyword 77 | [single]: http://fredkschott.com/post/2013/12/node-js-cookbook---designing-singletons/ 78 | [require]: http://fredkschott.com/post/2014/06/require-and-the-module-system/ 79 | [jstyle]: https://github.com/rwaldron/idiomatic.js 80 | [astyle]: https://github.com/airbnb/javascript 81 | [dont]: https://github.com/getify/You-Dont-Know-JS 82 | [bao]: https://github.com/alsotang/node-lessons 83 | -------------------------------------------------------------------------------- /K8S_Notes.md: -------------------------------------------------------------------------------- 1 | # Kubernetes Notes 2 | ## Books and readings 3 | ### Kubernetes Up and Running 4 | ### [Kubernetes By Example](http://kubernetesbyexample.com/) 5 | ### Kubernetes in Action 6 | ### [Kubernetes Handbook](https://jimmysong.io/kubernetes-handbook/) 7 | ### [Kubebuilder Book](https://book.kubebuilder.io/) -------------------------------------------------------------------------------- /Miscellaneous.md: -------------------------------------------------------------------------------- 1 | # Miscellaneous Notes 2 | --- 3 | 4 | ### Technical books/papers 5 | 1. [Linux inside][inside] 6 | 2. [CIS 194: Introduction to Haskell by Upenn][194] 7 | 3. [Advanced Bash-Scripting Guide][abs] 8 | 4. [MySQL Small Cookbook][mysql] 9 | 5. [软件构建实践 0.1][pm] 10 | 6. [Composing Programs][compose] 11 | 7. [C++ Core Guidelines][isocpp] 12 | 8. [A beginners guide to writing documentation][write_doc] 13 | 14 | ### Collections 15 | 1. [Awesome Web Performance Optimization][wpo] 16 | 2. [A List of Programming Screencast Series][screencast] 17 | 3. [Free podcasts and screencasts][free] 18 | 4. [Awesome Sysadmin][sysadmin] 19 | 5. [Devops Tools][devops] 20 | 6. [Form: Prototype 工具][Form] 21 | 7. [Animated and interactive prototype desigin][Principle] 22 | 8. [Sentry: The web’s check engine][sentry] 23 | 9. [CppCon2015][cppcon2015] 24 | 25 | ### Repository: 26 | 1. [httpbin: HTTP Request & Response Service][httpbin] 27 | 2. [masscan: fastest TCP port scanner][masscan] 28 | 3. [Favico animate][favicojs] 29 | 4. [List of Post-mortems][post-mortems] 30 | 5. [Phabricator: Open software engineering platform and fun adventure][phabricator] 31 | 32 | ### Tornado 33 | 1. [Asynchronous and non-Blocking I/O][async] 34 | 35 | 36 | ### Side Project 百宝箱 37 | #### Infra & DevOps 38 | 1. [Process manager: supervisord](http://supervisord.org/) 39 | 2. [Real-time crash reporting for web app: Sentry](https://getsentry.com/welcome/) 40 | 3. [Zappa: Serverless Python Web Services](https://github.com/Miserlou/Zappa) 41 | 4. [Algo wiki](https://github.com/vicky002/AlgoWiki) 42 | 5. [MailChimp vs. Amazon SES](https://coursetro.com/posts/other/95/MailChimp-vs.-Amazon-SES---How-I-Reduced-My-Monthly-Bill-by-92%) 43 | 6. [Visual Studio Team Services](https://www.visualstudio.com/team-services/) 44 | 45 | #### Tools * Libs 46 | 1. [Smart CDN: uploadcare](https://uploadcare.com/) 47 | 2. [Fontmin: 字体子集化](http://ecomfe.github.io/fontmin/en) 48 | 3. [Python alfred-workflow SDK](https://github.com/deanishe/alfred-workflow) 49 | 4. [uchardet: An encoding detector library ported from Mozilla](https://github.com/BYVoid/uchardet) 50 | 5. [Google reCAPTCHA](https://www.google.com/recaptcha/intro/) 51 | 6. [lz4: Extremely Fast Compression algorithm](https://github.com/lz4/lz4) 52 | 7. [Spooky: super fast hash algorithm](http://burtleburtle.net/bob/hash/spooky.html) 53 | 8. [CeleryBeat: periodic task](http://docs.celeryproject.org/en/latest/userguide/periodic-tasks.html) 54 | 9. [Uptimerobot: 定时访问网站](https://uptimerobot.com/) 55 | 10. [Mercury](https://mercury.postlight.com/) 56 | 11. [Mozilla Common Voice dataset](https://voice.mozilla.org/data) 57 | 12. [Small chat: Talk to your visitors](https://small.chat/) 58 | 13. [Apache Tika: detects and extracts metadata and text from various file types](http://tika.apache.org/) 59 | 14. [Varnish Cache: high-performance HTTP accelerator](https://varnish-cache.org/) 60 | 61 | 62 | #### Misc 63 | 1. [99 Designs: 悬赏设计](https://99designs.com/) 64 | 2. [Algolia: 3rd party search solution $49/month](https://www.algolia.com/) 65 | 66 | [httpbin]: https://github.com/Runscope/httpbin 67 | [wpo]: https://github.com/davidsonfellipe/awesome-wpo 68 | [screencast]: http://devblog.avdi.org/2013/06/21/a-list-of-programming-screencast-series/ 69 | [free]: https://github.com/vhf/free-programming-books/blob/master/free-podcasts-screencasts-en.md 70 | [194]: http://www.cis.upenn.edu/~cis194/spring13/lectures.htmlA 71 | [abs]: http://tldp.org/LDP/abs/html/ 72 | [sysadmin]: https://github.com/n1trux/awesome-sysadmin 73 | [masscan]: https://github.com/robertdavidgraham/masscan 74 | [inside]: http://0xax.gitbooks.io/linux-insides/content/index.html 75 | [mysql]: http://andrewliu.tk/2015/05/24/MySQL-Small-Cookbook/ 76 | [devops]: https://devops.zeef.com/christian.peper 77 | [pm]: http://pm.readthedocs.org/ 78 | [async]: http://www.tornadoweb.org/en/stable/guide/async.html 79 | [compose]: http://www.composingprograms.com/ 80 | [favicojs]: http://lab.ejci.net/favico.js/ 81 | [post-mortems]: https://github.com/danluu/post-mortems 82 | [Form]: http://relativewave.com/form/ 83 | [Principle]: http://principleformac.com/index.html 84 | [phabricator]: https://github.com/phacility/phabricator 85 | [sentry]: https://getsentry.com/welcome/ 86 | [isocpp]: http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines 87 | [cppcon2015]: https://github.com/cppcon/cppcon2015 88 | [write_doc]: http://www.writethedocs.org/guide/writing/beginners-guide-to-docs/ 89 | -------------------------------------------------------------------------------- /MongoDB.org: -------------------------------------------------------------------------------- 1 | #+TITLE: MongoDB Notes 2 | #+AUTHOR: Wilbeibi 3 | #+EMAIL: wilbeibi AT gmail DOT com 4 | #+LANGUAGE: en 5 | #+OPTIONS: H:2 num:nil toc:t \n:nil @:t ::t |:t ^:nil f:t *:t TeX:t LaTeX:t skip:nil p:nil 6 | 7 | * Useful Commands 8 | - db.help() 9 | - db.COLLCECTION_NAME.find(**).count() 10 | - db.stats() :: show statistics of current database 11 | - help 12 | - help keys 13 | - db :: show current database name 14 | - db.COLLCECTION_NAME.findOne() :: Returns one document that satisfies the 15 | specified query criteria. If multiple documents satisfy the query, this 16 | method returns the first document according to the natural order 17 | - avoid print result, add *null;* after the statement; 18 | - > use mydb; 19 | > db.dropDatabase(); 20 | - mongoimport --type csv --headerline weather.csv -d weather -c data 21 | - db.example.update({},{$unset: {words:1}},false,true) :: delete word field 22 | from doc 23 | db.collection.update( criteria, objNew, upsert, multi ) 24 | - totalIndex 25 | 26 | 27 | * Mongoose 28 | ** Schema 29 | - Define document's style, like struct in C [[http://mongoosejs.com/docs/guide.html][link]] 30 | ** Model 31 | - name the schema in databse, like typedef, can pre-initialize value. [[http://mongoosejs.com/docs/models.html][link]] 32 | ** Problems 33 | - statics 34 | - [[http://stackoverflow.com/questions/5535610/mongoose-unique-index-not-working][unique index]] 35 | - [[http://stackoverflow.com/questions/16209681/what-is-the-difference-between-save-and-insert-in-mongo-db][save VS insert]] 36 | save insert or update a document. 37 | insert does only an insertion 38 | - get result from mongoose query 39 | mongoose promise 40 | - or: https://github.com/olegp/mongo-sync 41 | 42 | ** find 43 | - search more than one field : User.find({name:'wil', score: 80}) 44 | 45 | ** find and remove 46 | - [[http://stackoverflow.com/questions/5809788/how-do-i-remove-documents-using-node-js-mongoose][Remove documents using Nodejs]] 47 | - FindOneAndRemove 48 | - MyModel.remove({search: criteria}, function() {} 49 | 50 | * Express 51 | 52 | * Miscellaneous 53 | - one single document should be less than 16M(BSON document size) 54 | - upsert (if exists, update, else create) 55 | - enable upsert by pass {upsert:true} in update 56 | - *denormalization* (in RDBS) improve database reading performance by add redunct data 57 | - *durability* http://www.techopedia.com/definition/27416/durability-databases 58 | - *Capped Collection* are fixed-size collections, once a collection fills its 59 | allocated space, it makes room for new documents by overwriting the oldest 60 | documents in the collection. 61 | - db is the variable that references the current database. The variable is 62 | automatically set to the default database test or is set when you use the 63 | use to switch current database. 64 | - Cursor: A pointer to the result set of a query. Clients can iterate through 65 | a cursor to retrieve results. 66 | - GridFS 67 | - you cannot have parrael array for multi-key 68 | - *compound index* : used in sort and find, leftmost 69 | for example, {a:1, b:1, c:1}, find({a:1}), find({a:1, b:1}) use compound 70 | index, find({b:1, c:1}) not use, but find({b:1,c:1}).sort({a:1,b:1}) use it 71 | - Index Selectivity: 最有区分度的,变化最多的,作为选择 72 | - hint : Tell mongodb which index to use 73 | - find and sort canot use sparse index(就是不是所有document都有的index) 74 | - _id can be a document 75 | ** Types && op 76 | - NumberInt 77 | - NumberLong 78 | - new Date() 79 | - mongodb comparision will not cross types 80 | - $exists :: find whether a field is exist 81 | - $type :: specify whether the value match a type 82 | - $regex: Perl style regex (optimization problem) 83 | - Dot Notation, find a part of document 84 | 85 | 86 | ** Operations 87 | 1) $group 88 | 2) $match 89 | 3) $project 90 | 4) $pop:{array_name: -1} :: pop from left 91 | 5) db.COLLCECTION_NAME.drop() is more efficient than db.COLLCECTION_NAME.remove({}) 92 | 6) save :: if this doc _id exists, update, otherwise, create one. 93 | ** week2 hw1 94 | - db.data.find({"Wind Direction": {$gte: 180, $lte: 360}}, {"State":1, "Temperature":1}).sort({"Temperature":1}).limit(1) 95 | ** week3 hw1 96 | - db.students.update({}, {$push: {scores: { $each: [], $sort:{type: 1, 97 | score: 1} }}}, {multi: true}) 98 | - db.students.update({}, {$unset:{'scores.1':1}}, {multi:true}) 99 | - db.students.update({}, {$pull:{'scores':null}}, {multi:true}) 100 | 101 | ** week4 hw3 102 | - homepage: db.posts.ensureIndex({ date: -1}) 103 | - perlink: db.posts.ensureIndex({ permalink: 1}, {unique: true}) 104 | - pertag: db.posts.ensureIndex({ tags: 1}) 105 | 106 | ** week4 hw4 107 | - db.profile.find({op: 'query', ns: 'school2.students'}, {millis: 1, _id: 0}).sort({millis:-1}).limit(1) 108 | 109 | ** Final 110 | *** Q1 111 | - db.messages.ensureIndex({From:1, To:1}) 112 | - db.messages.find({ "headers.From": "andrew.fastow@enron.com", "headers.To": "jeff.skilling@enron.com"}).count() 113 | 114 | *** Q2 115 | - 116 | * Questions 117 | - B Tree 118 | - document-level locking 2.8 119 | - aggregation framework 120 | - sort memory, limit 121 | - unwind will generate same _id 122 | - assert: command failed: { 123 | "errmsg" : "exception: Exceeded memory limit for $group, but didn't allow 124 | external sort. Pass allowDiskUse:true to opt in.", 125 | "code" : 16945, 126 | "ok" : 0 127 | } : aggregate failed 128 | - index can be use for sort 129 | - index has to be maintain, will slow the insert 130 | - w = 0, j = 0 131 | -------------------------------------------------------------------------------- /PythonChallenge.md: -------------------------------------------------------------------------------- 1 | Python Challenge 2 | --- 3 | 4 | ## Level 0 5 | 6 | 7 | In [21]: 1<<38 8 | Out[21]: 274877906944 9 | 10 | 11 | 12 | ## Level 1 13 | 14 | # src:http://www.pythonchallenge.com/pc/def/map.html 15 | 16 | from string import maketrans 17 | ori = 'abcdefghijklmnopqrstuvwxyz' 18 | des = 'cdefghijklmnopqrstuvwxyzab' 19 | 20 | tbl = maketrans(ori, des) 21 | 22 | text = "g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. \ 23 | bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. \ 24 | sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj." 25 | 26 | print text.translate(tbl) 27 | 28 | # So, the answer is: 29 | print 'map'.translate(tbl) 30 | 31 | # Output: ocr 32 | 33 | 34 | ## Level 2 ## 35 | 36 | 37 | #src http://www.pythonchallenge.com/pc/def/ocr.html 38 | 39 | import requests 40 | import re 41 | 42 | rep = requests.get("http://www.pythonchallenge.com/pc/def/ocr.html") 43 | html = rep.text 44 | 45 | html = ''.join(html.split()) # strip all newline, tab, space 46 | text = re.findall(r'', html)[1] # get the second comment 47 | wc = {} 48 | 49 | for i in text: 50 | wc[i] = 1 if i not in wc else wc[i]+1 51 | 52 | l = [i for i in wc if wc[i]==1] 53 | 54 | # retrive answer in text in order 55 | print ''.join(i for i in text if i in l) 56 | # Output: equality 57 | 58 | 59 | ## Level 3 ## 60 | 61 | #src: http://www.pythonchallenge.com/pc/def/equality.html 62 | import requests 63 | import re 64 | 65 | rep = requests.get("http://www.pythonchallenge.com/pc/def/equality.html") 66 | html = rep.text 67 | 68 | html = ''.join(html.split()) 69 | text = re.findall(r'', html)[0] 70 | 71 | res = re.findall(r'[^A-Z][A-Z]{3}([a-z])[A-Z]{3}[^A-Z]', text) 72 | print ''.join(res) 73 | # Output: linkedlist 74 | 75 | 76 | ## Level 4 ## 77 | 78 | # src: http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345 79 | 80 | import urllib2 81 | import re 82 | link = "http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345" 83 | # link = "http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=8022" 84 | for i in range(400): 85 | text = urllib2.urlopen(link).read() 86 | num = re.findall(r"and the next nothing is (\d+)", text)[0] 87 | 88 | link = re.sub('\d+',num, link) 89 | print num + "\t" + link 90 | 91 | # Output: peak.html 92 | 93 | ## Level 5 ## 94 | 95 | 96 | # src: http://www.pythonchallenge.com/pc/def/peak.html 97 | 98 | import cPickle as pickle 99 | import urllib2 100 | import re 101 | 102 | link = "http://www.pythonchallenge.com/pc/def/banner.p" 103 | 104 | text = urllib2.urlopen(link).read() 105 | data = pickle.loads(text) 106 | 107 | for line in data: 108 | print ''.join(i[0]*i[1] for i in line) 109 | 110 | # Output: channel 111 | 112 | 113 | -------------------------------------------------------------------------------- /Python_Index.md: -------------------------------------------------------------------------------- 1 | Python Notes Collections 2 | ------- 3 | 4 | ![Alt text](https://www.python.org/static/img/python-logo.png) 5 | 6 | 1. [“我基础学完了,接下来该学点什么” ][newbie] 7 | 2. [Python yield 使用浅析 by IBM][yield] 8 | 3. [Difference between _, __ and __xx__ in Python][__xx__] 9 | 4. [Python修饰器的函数式编程 | 酷 壳][decorator] And [Prime on decorators][decorator2] 10 | 5. [Python Regular Expression by Google][regex] 11 | 6. [Python 2.7.6 Glossary][glossary] 12 | 7. [Python Best Practice Patterns][patterns] 13 | 8. [`yield` keyword explained][yield] 14 | 9. [Python IAQ by Peter Norvig][iaq] 15 | 10. [Python Useful Tips][tips] 16 | 11. [python 线程,GIL 和 ctypes][GIL] 17 | 12. [An Introduction to List Comprehensions in Python][lc] 18 | 13. [Advanced Python Constructs][constructs] 19 | 14. [Python 文本处理 by IBM][text] 20 | 15. [Python 代码性能优化技巧 by IBM][optimize] 21 | 16. [可爱的 Python: Python 中的函数编程 by IBM][functional] 22 | 17. [*args and **kwargs in python explained][args] 23 | 18. [Python 内建函数用法][built-in] 24 | 19. [How does zip(*[iter(s)]*n) work in Python][zip_iter] 25 | 20. [Why Python is Slow: Looking Under the Hood][slow] 26 | 21. [Bouncing Python's Generators With a Trampoline][tramp] 27 | 22. [A collection of not-so-obvious Python stuff you should know!][n_ob] 28 | 23. [What is the python “with” statement designed for?][with] 29 | 24. [Parsing English with 500 lines of Python][parse_eng] 30 | 25. [Python List Comprehension Vs. Map][lc_map] 31 | 26. [Key differences between Python 2.7.x and Python 3.x][diff23] 32 | 27. [What is a Python egg?][egg1] 33 | 28. [The Internal Structure of Python Eggs][egg2] 34 | 29. [is None vs. ==None][is_equal] 35 | 30. [Python call function within class][call_call] 36 | 31. [Syntax behind sorted(key=lambda :)][key_lambda] 37 | 32. [The self variable in python explained][self_] 38 | 33. [How to retrieve an element from a set without removing it?][set_get] 39 | 34. [How to read aloud Python List Comprehensions?][list_com] 40 | 35. [How collections.defaultdict work][defaultdict] 41 | 36. [使用 Python 进行线程编程][ibm_multi] 42 | 37. [What is the difference between @staticmethod and @classmethod in Python?][de_meth] 43 | 38. [What is \__init__.py for][initpy] 44 | 39. [可变的call by reference,不可变的call by value][callby] 45 | 40. [Why does Python assignment not return a value?][noreturn] 46 | 41. [Sort list of list with custom compare function in Python][cus_func] 47 | 42. [Useful code which uses reduce() in python][reduce_use] 48 | 43. [装饰器与函数式Python][dfp] 49 | 44. [Python Patterns - An Optimization Anecdote][optp] 50 | 45. [Python threading multiple bash subprocesses?][thread_sub] 51 | 46. [Any gotchas using unicode_literals in Python 2.6?][unicode_] 52 | 48. [Iterators, Generators and Decorators][igd] 53 | 49. [with 48, Functional Programming in Python][igd2] 54 | 50. [Writing 2.x & 3.x Compatible Code][23code] 55 | 51. [Why is [] faster than list()?][fastlist] 56 | 52. [What does ** (double star) and * (star) do for Python parameters?][star_star] 57 | 53. [What is the 'cls' variable used in python classes?][cls] 58 | 54. [print unicode dict as it is rather than code points][unicode1] 59 | 55. [How to get back an overridden python built-in function?][over_builtin] 60 | 56. [Parallel Programming][parallel] 61 | 57. [Decorators the right way][decorators] 62 | 58. [PEP 0 -- Index of Python Enhancement Proposals (PEPs)][pep] 63 | 59. [Extending/Embedding FAQ][extending] 64 | 60. [Purpose of star operator when used on List][star_list] 65 | 61. [Python @classmethod and @staticmethod for beginner?][cls_static] 66 | 62. [A Guide to Python's Magic Methods][magics] 67 | 63. [In-memory size of a Python structure][pysize] 68 | 64. [Ned Batchelder: Getting Started Testing - PyCon 2014][test0] 69 | 65. [CPython internals: A ten-hour codewalk through the Python interpreter 70 | source code][internals] 71 | 66. [理解 Python super][super2] 72 | 67. [Python debugging tips][pydebug] 73 | 68. [Fix "Attempted relative import in non-package"][python.m] 74 | 69. [How to make a chain of function decorators?][chain_decorator] 75 | 70. [Class method differences in Python: bound, unbound and static][class_methods] 76 | 77 | ## Examples 78 | 1. [Solving Every Sudoku Puzzle by Peter Norvig][sudoku] 79 | 2. [如何使用Python编写一个Lisp解释器 by Peter Norvig][lisp] 80 | 3. [Python 贪吃蛇][snake] 81 | 4. [How to write a spell checker][spell] 82 | 5. [用 Python 秒掉八皇后问题][8queen] 83 | 6. [自然语言分词 by Peter Norvig][beau_data] 84 | 7. [Algorithm X in 30 lines!][algoX] 85 | 8. [500 Lines or Less ☆][500] 86 | 9. [Hidden features of Python ☆][hidd] 87 | 10. [Are list-comprehensions and functional functions faster than “for loops”?][lcvsfl] 88 | 11. [What's the difference between these two ways of initializing an array?][init_arr] 89 | 12. [Generator Tricks for Systems Programmers by DAVE BEAZLEY][generator_tricks] 90 | 13. [A Curious Course on Coroutines and Concurrency by DAVE BEAZLEY][corountines] 91 | 14. [DAVE BEAZLEY's Blog][dave] 92 | 15. [Python Decorator Library][pdl] 93 | 16. [Code Like a Pythonista: Idiomatic Python][Idiomatic] 94 | 17. [What does functools.wraps do?][wraps] Keep function information (name, docstring...) 95 | 96 | 97 | ## Miscellaneous 98 | 99 | 1. [Python资源#1][coll1] 100 | 2. [Python程序员必知必会的开发者工具][coll2] (pydoc, doctest, unittest, trace, profile, timit...) 101 | 3. [Ipython Notebook][ipython] 102 | 4. [XKCD Plots in Matplotlib: Going the Whole Way][xkcd] 103 | 5. [Django资源][django] 104 | 6. [Scipy科学计算][scipy] 105 | 7. [Matplotlib Tutorial][matplotlib] 106 | 8. [Python常见面试题][interview] 107 | 9. [Emacs for Python Programming][emacs] 108 | 10. [Python web scraping resource][scrape] 109 | 11. [Powerful network tool: scapy][scapy] 110 | 12. Bool operator priority 111 | 112 | ![](https://s3.amazonaws.com/Blog_Notes_CDN/python_bool_priority.png) 113 | 114 | 13. [Python Performance Tips][performance] 115 | 14. [High Performance Python Extensions: Part 1][perf1] 116 | 15. [Example Google Style Python Docstrings][Gstyle] 117 | 16. [key differences between Python 2.x and Python 3.x][diff23] 118 | 17. [Why isn't Python very good for functional programming?][functional2] 119 | 18. [Must-watch videos about Python][pymust] 120 | 19. [python_articles from Flowerowl][pas] 121 | 20. [Python best practices guidebook, written for Humans][human] 122 | 21. [Github: howdoi - instant coding answers via the command line][howdoi] 123 | 22. [Collection of less popular features and tricks for the Python][pytricks] 124 | 23. [How to become a proficient Python programmer][howto2] 125 | 24. [tqdm: Add a progress meter to your loops in a second][tqdm] 126 | 25. [BeeWare: The IDEs of Python][pybee] 127 | 26. [Python Time complexity][complexity] 128 | 27. [Test with mock][mock] 129 | 28. [Use curses, dont swear][curses] 130 | 29. [Hitchhiker's Guide to Python (for humans)][human] 131 | 30. [The Elements of Python Style][el_style] 132 | 31. [Complexity of Python Operations][complexity] 133 | 32. [traceback usage][traceback] 134 | 33. [Celery Task Checklist](http://celerytaskschecklist.com/) 135 | 136 | ## Flask 137 | 1. [Explore Flask](http://exploreflask.com/en/latest/index.html) 138 | ## Cheatsheets 139 | ### Virtualwrapper 140 | 1. in ~/.zshrc, add: 141 | source /usr/local/bin/virtualenvwrapper.sh 142 | export WORKON_HOME=~/Dropbox/Programs/Python/VIRTUAL_ENV 143 | 2. Create environment: 144 | mkvirtualenv py_box 145 | 3. Switch to environment: 146 | workon py_box 147 | 4. Exit environment: 148 | deactivate 149 | 150 | ------ 151 | Author: Wilbeibi 152 | Update: Wed Apr 16 17:55:41 EDT 2014 153 | Update: Wed May 7 21:54:10 EDT 2014 154 | Update: Wed May 14 04:12:05 EDT 2014 155 | Update: Sat Jul 12 13:09:46 EDT 2014 156 | Update: Sat Jul 19 08:56:20 EDT 2014 157 | Update: Sun Aug 10 23:36:46 EDT 2014 158 | Update: Wed Aug 27 14:02:59 EDT 2014 159 | Update: Tue Oct 7 23:16:47 EDT 2014 160 | Update: Wed Oct 22 00:49:30 EDT 2014 161 | Update: Wed Nov 5 22:07:20 EST 2014 162 | Update: Mon Dec 29 00:03:49 CST 2014 163 | Update: Sat Feb 21 01:10:24 EST 2015 164 | Update: Wed Apr 15 21:32:20 EDT 2015 165 | Update: Mon May 11 00:13:00 EDT 2015 166 | Update: Fri May 29 08:51:53 EDT 2015 167 | Update: Thu Jun 11 22:01:13 EDT 2015 168 | Update: Mon Nov 16 12:58:19 PST 2015 169 | Update: Sun Dec 6 17:32:34 PST 2015 170 | Update: Wed Jan 13 16:47:43 PST 2016 171 | Update: Sat May 14 23:50:28 PDT 2016 172 | Update: Tue Jun 28 23:15:48 PDT 2016 173 | Update: Thu Dec 15 16:10:05 PST 2016 174 | Update: Mon Aug 28 10:38:48 PDT 2017 175 | 176 | 177 | [newbie]: http://www.the5fire.com/what-should-i-do-as-newbie.html 178 | [yield]: http://www.ibm.com/developerworks/cn/opensource/os-cn-python-yield/index.html 179 | [__xx__]: http://igorsobreira.com/2010/09/16/difference-between-one-underline-and-two-underlines-in-python.html 180 | [decorator]: http://coolshell.cn/articles/11265.html 181 | [decorator2]: http://www.realpython.com/blog/python/primer-on-python-decorators/#.UvQEs0JdUwJ 182 | [regex]: https://developers.google.com/edu/python/regular-expressions 183 | [coll1]: http://blog.csdn.net/lanxuezaipiao/article/details/19048521 184 | [coll2]: http://blog.jobbole.com/58226/ 185 | [ipython]: http://opentechschool.github.io/python-data-intro/core/notebook.html 186 | [glossary]: http://docs.python.org/2/glossary.html 187 | [patterns]: http://stevenloria.com/python-best-practice-patterns-by-vladimir-keleshev-notes/ 188 | [sudoku]: http://norvig.com/sudoku.html 189 | [lisp]: http://www.googies.info/articles/lispy.html 190 | [xkcd]: http://jakevdp.github.io/blog/2013/07/10/XKCD-plots-in-matplotlib/ 191 | [yield]: http://stackoverflow.com/questions/231767/the-python-yield-keyword-explained 192 | [iaq]: http://norvig.com/python-iaq.html 193 | [django]: http://haoluobo.com/trac/wiki/Django 194 | [snake]: http://hawstein.com/posts/snake-ai.html 195 | [tips]: https://pyzh.readthedocs.org/en/latest/improving-your-python-productivity.html 196 | [GIL]: http://zhuoqiang.me/python-thread-gil-and-ctypes.html 197 | [lc]: http://carlgroner.me/Python/2011/11/09/An-Introduction-to-List-Comprehensions-in-Python.html 198 | [constructs]: http://reverland.org/python/2013/03/13/advanced-python-constructs/ 199 | [spell]: http://blog.youxu.info/spell-correct.html 200 | [scipy]: http://reverland.org/python/2012/10/22/scipy/ 201 | [matplotlib]: http://reverland.org/python/2012/09/07/matplotlib-tutorial/ 202 | [interview]: http://blog.csdn.net/darkchampion/article/details/4484467 203 | [text]: http://www.ibm.com/developerworks/cn/linux/sdk/python/python-5/index.html 204 | [optimize]: http://www.ibm.com/developerworks/cn/linux/l-cn-python-optim/ 205 | [functional]: http://www.ibm.com/developerworks/cn/linux/sdk/python/charm-10/index.html 206 | [8queen]: http://www.iteye.com/topic/106747#3075 207 | [beau_data]: http://norvig.com/ngrams/ 208 | [args]: http://freepythontips.wordpress.com/2013/08/04/args-and-kwargs-in-python-explained/ 209 | [built-in]: http://blog.csdn.net/starstarstone/article/details/7968185 210 | [emacs]: http://www.kurup.org/blog/2012/10/24/emacs-for-python-programming/ 211 | [zip_iter]: http://stackoverflow.com/questions/2233204/how-does-zipitersn-work-in-python 212 | [slow]: http://jakevdp.github.io/blog/2014/05/09/why-python-is-slow/ 213 | [scrape]: http://jakeaustwick.me/python-web-scraping-resource/ 214 | [tramp]: http://www.usrsb.in/blog/blog/2012/08/12/bouncing-pythons-generators-with-a-trampoline/ 215 | [cc]: http://www.dabeaz.com/coroutines/index.html 216 | [n_ob]: http://nbviewer.ipython.org/github/rasbt/python_reference/blob/master/tutorials/not_so_obvious_python_stuff.ipynb 217 | [with]: http://stackoverflow.com/questions/3012488/what-is-the-python-with-statement-designed-for 218 | [parse_eng]: http://honnibal.wordpress.com/2013/12/18/a-simple-fast-algorithm-for-natural-language-dependency-parsing/ 219 | [lc_map]: http://stackoverflow.com/questions/1247486/python-list-comprehension-vs-map 220 | [algox]: http://www.cs.mcgill.ca/~aassaf9/python/algorithm_x.html 221 | [diff23]: http://nbviewer.ipython.org/github/rasbt/python_reference/blob/master/tutorials/key_differences_between_python_2_and_3.ipynb?create=1 222 | [egg1]: http://stackoverflow.com/questions/2051192/what-is-a-python-egg 223 | [egg2]: https://pythonhosted.org/setuptools/formats.html 224 | [is_equal]: http://stackoverflow.com/questions/3257919/is-none-vs-none 225 | [call_call]: http://stackoverflow.com/questions/5615648/python-call-function-within-class 226 | [key_lambda]: http://stackoverflow.com/questions/8966538/syntax-behind-sortedkey-lambda 227 | [performance]: https://wiki.python.org/moin/PythonSpeed/PerformanceTips 228 | [self_]: http://freepythontips.wordpress.com/2013/08/07/the-self-variable-in-python-explained/ 229 | [set_get]: http://stackoverflow.com/questions/59825/how-to-retrieve-an-element-from-a-set-without-removing-it 230 | [list_com]: http://stackoverflow.com/questions/9061760/how-to-read-aloud-python-list-comprehensions 231 | [perf1]: https://www.crumpington.com/blog/2014/10-19-high-performance-python-extensions-part-1.html 232 | [Gstyle]: http://sphinxcontrib-napoleon.readthedocs.org/en/latest/example_google.html 233 | [defaultdict]: http://stackoverflow.com/questions/5900578/how-collections-defaultdict-work 234 | [ibm_multi]: http://www.ibm.com/developerworks/cn/aix/library/au-threadingpython/ 235 | [de_meth]: http://stackoverflow.com/questions/136097/what-is-the-difference-between-staticmethod-and-classmethod-in-python 236 | [500]: https://github.com/aosabook/500lines 237 | [diff23]: http://nbviewer.ipython.org/github/rasbt/python_reference/blob/master/tutorials/key_differences_between_python_2_and_3.ipynb 238 | [initpy]: http://stackoverflow.com/questions/448271/what-is-init-py-for 239 | [callby]: http://www.douban.com/note/226827597/ 240 | [noreturn]: http://stackoverflow.com/questions/4869770/why-does-python-assignment-not-return-a-value 241 | [functional2]: http://stackoverflow.com/questions/1017621/why-isnt-python-very-good-for-functional-programming 242 | [cus_func]: http://stackoverflow.com/questions/5213033/sort-list-of-list-with-custom-compare-function-in-python 243 | [reduce_use]: http://stackoverflow.com/questions/15995/useful-code-which-uses-reduce-in-python 244 | [dfp]: http://youngsterxyf.github.io/2013/01/04/Decorators-and-Functional-Python/ 245 | [hidd]: http://stackoverflow.com/questions/101268/hidden-features-of-python 246 | [optp]: https://www.python.org/doc/essays/list2str/ 247 | [lcvsfl]: http://stackoverflow.com/questions/22108488/are-list-comprehensions-and-functional-functions-faster-than-for-loops 248 | [thread_sub]: http://stackoverflow.com/questions/14533458/python-threading-multiple-bash-subprocesses 249 | [init_arr]: http://stackoverflow.com/questions/11336541/whats-the-difference-between-these-two-ways-of-initializing-an-array 250 | [generator_tricks]: http://www.dabeaz.com/generators-uk/index.html 251 | [unicode_]: http://stackoverflow.com/questions/809796/any-gotchas-using-unicode-literals-in-python-2-6 252 | [corountines]: http://www.dabeaz.com/coroutines/ 253 | [dave]: http://www.dabeaz.com/ 254 | [scapy]: http://www.secdev.org/projects/scapy/doc/usage.html 255 | [pdl]: https://wiki.python.org/moin/PythonDecoratorLibrary 256 | [igd]: http://www.python-academy.com/download/ep14deco/iter_gen_dec_handout.pdf 257 | [igd2]: https://www.youtube.com/watch?v=Ta1bAMOMFOI 258 | [curses]: https://www.youtube.com/watch?v=eN1eZtjLEnU 259 | [pymust]: https://github.com/s16h/py-must-watch 260 | [23code]: http://wescpy.blogspot.com/2011/12/writing-2x-3x-compatible-code.html 261 | [pas]: https://github.com/Flowerowl/python_articles 262 | [human]: https://github.com/kennethreitz/python-guide 263 | [howdoi]: https://github.com/gleitz/howdoi 264 | [pytricks]: https://github.com/brennerm/PyTricks 265 | [fastlist]: http://stackoverflow.com/questions/30216000/why-is-faster-than-list 266 | [howto2]: http://blog.dispatched.ch/2011/06/12/how-to-become-a-proficient-python-programmer/ 267 | [tqdm]: https://github.com/noamraph/tqdm 268 | [star_star]: http://stackoverflow.com/questions/36901/what-does-double-star-and-star-do-for-python-parameters 269 | [pybee]: http://pybee.org/# 270 | [cls]: http://stackoverflow.com/questions/4613000/what-is-the-cls-variable-used-in-python-classes 271 | [unicode1]: http://stackoverflow.com/questions/5648573/python-print-unicode-strings-in-arrays-as-characters-not-code-points 272 | [complexity]: https://wiki.python.org/moin/TimeComplexity 273 | [mock]: http://pyvideo.org/video/392/pycon-2011--testing-with-mock 274 | [over_builtin]: http://stackoverflow.com/questions/20885760/how-to-get-back-an-overridden-python-built-in-function 275 | [parallel]: http://www.composingprograms.com/pages/48-parallel-computing.html 276 | [Idiomatic]: http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html 277 | [decorators]: https://github.com/GrahamDumpleton/wrapt/tree/master/blog 278 | [pep]: https://www.python.org/dev/peps/ 279 | [human]: https://github.com/kennethreitz/python-guide 280 | [el_style]: https://github.com/amontalenti/elements-of-python-style 281 | [complexity]: https://www.ics.uci.edu/~pattis/ICS-33/lectures/complexitypython.txt 282 | [extending]: https://docs.python.org/2/faq/extending.html 283 | [star_list]: http://stackoverflow.com/questions/8077268/purpose-of-star-operator-when-used-on-list 284 | [cls_static]: http://stackoverflow.com/questions/12179271/python-classmethod-and-staticmethod-for-beginner 285 | [magics]: http://www.rafekettler.com/magicmethods.html 286 | [pysize]: http://stackoverflow.com/questions/1331471/in-memory-size-of-a-python-structure 287 | [test0]: https://www.youtube.com/watch?v=FxSsnHeWQBY 288 | [internals]: http://pgbovine.net/cpython-internals.htm 289 | [super2]: https://laike9m.com/blog/li-jie-python-super,70/ 290 | [pydebug]: http://stackoverflow.com/questions/1623039/python-debugging-tips 291 | [traceback]: https://docs.python.org/2/library/traceback.html 292 | [wraps]: http://stackoverflow.com/questions/308999/what-does-functools-wraps-do 293 | [python.m]: http://stackoverflow.com/questions/11536764/how-to-fix-attempted-relative-import-in-non-package-even-with-init-py 294 | [chain_decorator]: http://stackoverflow.com/questions/739654/how-to-make-a-chain-of-function-decorators/1594484#1594484 295 | [class_methods]: https://stackoverflow.com/questions/114214/class-method-differences-in-python-bound-unbound-and-static 296 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | NotesIndex 2 | ========== 3 | 4 | A collection of my Evernote notes 5 | 6 | 1. Python Notes Index ------ A collection of Python articles 7 | 2. Python Challenge ------ Python Challenge Solution code 8 | 3. Javascript Notes ------ A collection of Javascript articles and notes 9 | 4. Git Notes ------ Git FAQs 10 | 5. EmacsRef ------ Emacs usage references in org mode 11 | -------------------------------------------------------------------------------- /ShellNotes.org: -------------------------------------------------------------------------------- 1 | #+TITLE: Shell Programming Notes 2 | #+LANGUAGE: en 3 | #+AUTHOR: Hongyi Shen 4 | #+EMAIL: wilbeibi@gmail.com 5 | #+OPTIONS: H:3 num:t toc:3 \n:nil @:t ::t |:t ^:nil -:t f:t *:t <:nil 6 | #+OPTIONS: TeX:t LaTeX:nil skip:nil d:nil todo:t pri:nil tags:not-in-toc 7 | #+OPTIONS: author:t creator:t timestamp:t email:t 8 | #+DESCRIPTION: A description of how I currently use org-mode 9 | #+KEYWORDS: org-mode Emacs organization GTD getting-things-done git 10 | #+SEQ_TODO: FIXME FIXED 11 | #+INFOJS_OPT: view:nil toc:t ltoc:t mouse:underline buttons:0 path:http://orgmode.org/org-info.js 12 | #+EXPORT_SELECT_TAGS: export 13 | #+EXPORT_EXCLUDE_TAGS: noexport 14 | 15 | * Basics 16 | ** Pre knowledge 17 | #+BEGIN_SRC sh 18 | 19 | # chmod +rx scriptname 20 | echo "Here" # A whitespace before '#' in comment 21 | echo -n $var # echo variable without newline character 22 | 23 | hello="A B C D" 24 | echo $hello # A B C D (variable reference) 25 | echo "$hello" # A B C D (variable itself) 26 | 27 | if [ -n "${10}" ] # Parameters > $9 must be enclosed in {brackets}. 28 | 29 | arch=$(uname -m) # get current OS's arch 30 | 31 | if [ ! -f "$filename" ] # Quoting $filename allows for possible spaces. 32 | 33 | find ~/ -name 'core*' -exec rm {} \; 34 | # Removes all core dump files from user's home directory. 35 | 36 | #+END_SRC 37 | - Ctrl-H 38 | Erases characters back 39 | - Bash sets the "integer value" of a string to 0. 40 | - $# : number of parameters 41 | - $*/$@ : all the positional parameters. P778 42 | - P53 : get keyboard input 43 | 44 | ** Redirect 45 | #+BEGIN_SRC sh 46 | 1>filename 47 | # Redirect stdout to file "filename." 48 | 1>>filename 49 | # Redirect and append stdout to file "filename." 50 | 2>filename 51 | # Redirect stderr to file "filename." 52 | 2>>filename 53 | # Redirect and append stderr to file "filename." 54 | &>filename 55 | # Redirect both stdout and stderr to file "filename." 56 | # This operator is now functional, as of Bash 4, final release. 57 | M>N 58 | # "M" is a file descriptor, which defaults to 1, if not explicitly set. 59 | # "N" is a filename. 60 | # File descriptor "M" is redirect to file "N." 61 | M>&N 62 | # "M" is a file descriptor, which defaults to 1, if not set. 63 | # "N" is another file descriptor. 64 | # 2>&1 ==> Redirects stderr to stdout. 65 | >&j 66 | # Redirects, by default, file descriptor 1 (stdout) to j. # All stdout gets sent to file pointed to by j. 67 | #+END_SRC 68 | 69 | * Useful Tips 70 | - space do matters 71 | - *Sed* almost always runs faster than *awk* 72 | - tree ignore by pattern [[http://unix.stackexchange.com/questions/47805/how-do-we-specify-multiple-ignore-patterns-for-tree-command][link]] 73 | $tree -I 'node_module*' to ignore node_modules/ 74 | 75 | - mess stuff 76 | #+BEGIN_SRC shell 77 | cat {file1,file2,file3} > combined_file 78 | # Concatenates the files file1, file2, and file3 into combined_file. 79 | 80 | cp file22.{txt,backup} 81 | # Copies "file22.txt" to "file22.backup" 82 | 83 | (cd /source/directory && tar cf - . ) | (cd /dest/directory && tar xpvf -) 84 | # Move entire file tree from one directory to another 85 | # abs-guide P28 86 | 87 | echo `date` | pbcopy 88 | # get date string into clipboard 89 | 90 | read -p "Want to start? (y/n) " res 91 | if [ "$res" = "y"]; then 92 | # do blah blah 93 | else 94 | # do blah blah 95 | fi 96 | #+END_SRC 97 | 98 | 99 | * Archieve 100 | ** Create 101 | $tar -cvf filename.tar ./path/file (dir) <--不压缩 102 | $tar -zcvf filename.tar.gz ./path/file (dir) <--以 gzip 压缩 103 | $tar -jcvf filename.tar.bz2 ./path/file (dir) <--以 bzip2压缩 104 | ** Unzip 105 | $tar -xvf filename.tar 106 | $tar -zxvf filename.tar.gz <--注意后缀要对应写正确 107 | $tar -jxvf filename.tar.bz2 108 | ** tee 109 | - pipe standard output to terminal and new file at same time 110 | ls | tee new_file 111 | ** [[http://superuser.com/questions/46139/what-does-source-do][What does 'source' do?]] 112 | - executes the content of the file passed as argument 113 | ** 圖片白色轉透明 114 | - mogrify -transparent white image*.png 115 | ** Execute founded files 116 | - find . -name "*.pyc" --exec rm -rf {} \; # delete files recursively 117 | - find . -name ".DS_Store" -print0 | xargs -0 rm -rf # delete directories 118 | recursively # print0 ensure file name contains space interpreted corretly 119 | - find . -depth 1 -name "*.py" --exec cp '{}' ./destination \; 120 | *in OSX, is -exec [only one dash]* 121 | 122 | ** execute find results 123 | ** colorful less 124 | - less file, then press v 125 | 126 | --------------------------------------------------------------------------------