diff --git a/bash.html.markdown b/bash.html.markdown index 57fb5c55..dc7d32b6 100644 --- a/bash.html.markdown +++ b/bash.html.markdown @@ -8,6 +8,7 @@ contributors: - ["Denis Arh", "https://github.com/darh"] - ["akirahirose", "https://twitter.com/akirahirose"] - ["Anton Strömkvist", "http://lutic.org/"] + - ["Rahil Momin", "https://github.com/iamrahil"] filename: LearnBash.sh --- @@ -140,6 +141,12 @@ do echo "$VARIABLE" done +# Or write it the "traditional for loop" way: +for ((a=1; a <= 3; a++)) +do + echo $a +done + # They can also be used to act on files.. # This will run the command 'cat' on file1 and file2 for VARIABLE in file1 file2 diff --git a/c.html.markdown b/c.html.markdown index 8e170300..cbb6d289 100644 --- a/c.html.markdown +++ b/c.html.markdown @@ -4,6 +4,7 @@ filename: learnc.c contributors: - ["Adam Bard", "http://adambard.com/"] - ["Árpád Goretity", "http://twitter.com/H2CO3_iOS"] + - ["Jakub Trzebiatowski", "http://cbs.stgn.pl"] --- @@ -175,6 +176,9 @@ int main() { i2 * i1; // => 2 i1 / i2; // => 0 (0.5, but truncated towards 0) + // You need to cast at least one integer to float to get a floating-point result + (float)i1 / i2 // => 0.5f + i1 / (double)i2 // => 0.5 // Same with double f1 / f2; // => 0.5, plus or minus epsilon // Floating-point numbers and calculations are not exact @@ -194,9 +198,11 @@ int main() { 2 >= 2; // => 1 // C is not Python - comparisons don't chain. - // WRONG: - //int between_0_and_2 = 0 < a < 2; - // Correct: + // Warning: The line below will compile, but it means `(0 < a) < 2`. + // This expression is always true, because (0 < a) could be either 1 or 0. + // In this case it's 1, because (0 < 1). + int between_0_and_2 = 0 < a < 2; + // Instead use: int between_0_and_2 = 0 < a && a < 2; // Logic works on ints @@ -573,7 +579,7 @@ typedef void (*my_fnp_type)(char *); '\''; // single quote '\"'; // double quote '\xhh'; // hexadecimal number. Example: '\xb' = vertical tab character -'\ooo'; // octal number. Example: '\013' = vertical tab character +'\0oo'; // octal number. Example: '\013' = vertical tab character //print formatting: "%d"; // integer diff --git a/coffeescript.html.markdown b/coffeescript.html.markdown index d96eed39..6af692b9 100644 --- a/coffeescript.html.markdown +++ b/coffeescript.html.markdown @@ -11,7 +11,7 @@ As one of the succeeders of JavaScript, CoffeeScript tries its best to output re See also [the CoffeeScript website](http://coffeescript.org/), which has a complete tutorial on CoffeeScript. -``` coffeescript +```coffeescript # CoffeeScript is a hipster language. # It goes with the trends of many modern languages. # So comments are like Ruby and Python, they use number symbols. diff --git a/common-lisp.html.markdown b/common-lisp.html.markdown index 8de81549..08134e35 100644 --- a/common-lisp.html.markdown +++ b/common-lisp.html.markdown @@ -17,7 +17,7 @@ Another popular and recent book is -```scheme +```common_lisp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; 0. Syntax diff --git a/compojure.html.markdown b/compojure.html.markdown new file mode 100644 index 00000000..96555273 --- /dev/null +++ b/compojure.html.markdown @@ -0,0 +1,237 @@ +--- +category: tool +tool: compojure +contributors: + - ["Adam Bard", "http://adambard.com/"] +filename: learncompojure.clj +--- + +## Getting Started with Compojure + +Compojure is a DSL for *quickly* creating *performant* web applications +in Clojure with minimal effort: + +```clojure +(ns myapp.core + (:require [compojure.core :refer :all] + [org.httpkit.server :refer [run-server]])) ; httpkit is a server + +(defroutes myapp + (GET "/" [] "Hello World")) + +(defn -main [] + (run-server myapp {:port 5000})) +``` + +**Step 1:** Create a project with [Leiningen](http://leiningen.org/): + +``` +lein new myapp +``` + +**Step 2:** Put the above code in `src/myapp/core.clj` + +**Step 3:** Add some dependencies to `project.clj`: + +``` +[compojure "1.1.8"] +[http-kit "2.1.16"] +``` + +**Step 4:** Run: + +``` +lein run -m myapp.core +``` + +View at: + +Compojure apps will run on any ring-compatible server, but we recommend +[http-kit](http://http-kit.org/) for its performance and +[massive concurrency](http://http-kit.org/600k-concurrent-connection-http-kit.html). + +### Routes + +In compojure, each route is an HTTP method paired with a URL-matching pattern, +an argument list, and a body. + +```clojure +(defroutes myapp + (GET "/" [] "Show something") + (POST "/" [] "Create something") + (PUT "/" [] "Replace something") + (PATCH "/" [] "Modify Something") + (DELETE "/" [] "Annihilate something") + (OPTIONS "/" [] "Appease something") + (HEAD "/" [] "Preview something")) +``` + +Compojure route definitions are just functions which +[accept request maps and return response maps](https://github.com/mmcgrana/ring/blob/master/SPEC): + +```clojure +(myapp {:uri "/" :request-method :post}) +; => {:status 200 +; :headers {"Content-Type" "text/html; charset=utf-8} +; :body "Create Something"} +``` + +The body may be a function, which must accept the request as a parameter: + +```clojure +(defroutes myapp + (GET "/" [] (fn [req] "Do something with req"))) +``` + +Or, you can just use the request directly: + +```clojure +(defroutes myapp + (GET "/" req "Do something with req")) +``` + +Route patterns may include named parameters: + +```clojure +(defroutes myapp + (GET "/hello/:name" [name] (str "Hello " name))) +``` + +You can adjust what each parameter matches by supplying a regex: + +```clojure +(defroutes myapp + (GET ["/file/:name.:ext" :name #".*", :ext #".*"] [name ext] + (str "File: " name ext)) +``` + +Handlers may utilize query parameters: + +```clojure +(defroutes myapp + (GET "/posts" [] + (fn [req] + (let [title (get (:params req) "title") + author (get (:params req) "title")] + " Do something with title and author")))) +``` + +Or, for POST and PUT requests, form parameters + +```clojure +(defroutes myapp + (POST "/posts" [] + (fn [req] + (let [title (get (:params req) "title") + author (get (:params req) "title")] + "Do something with title and author")))) +``` + + +### Return values + +The return value of a route block determines at least the response body +passed on to the HTTP client, or at least the next middleware in the +ring stack. Most commonly, this is a string, as in the above examples. +But, you may also return a [response map](https://github.com/mmcgrana/ring/blob/master/SPEC): + +```clojure +(defroutes myapp + (GET "/" [] + {:status 200 :body "Hello World"}) + (GET "/is-403" [] + {:status 403 :body ""}) + (GET "/is-json" [] + {:status 200 :headers {"Content-Type" "application/json"} :body "{}"})) +``` + +### Static Files + +To serve up static files, use `compojure.route.resources`. +Resources will be served from your project's `resources/` folder. + +```clojure +(require '[compojure.route :as route]) + +(defroutes myapp + (GET "/") + (route/resources "/")) ; Serve static resources at the root path + +(myapp {:uri "/js/script.js" :request-method :get}) +; => Contents of resources/public/js/script.js +``` + +### Views / Templates + +To use templating with Compojure, you'll need a template library. Here are a few: + +#### [Stencil](https://github.com/davidsantiago/stencil) + +[Stencil](https://github.com/davidsantiago/stencil) is a [Mustache](http://mustache.github.com/) template library: + +```clojure +(require '[stencil.core :refer [render-string]]) + +(defroutes myapp + (GET "/hello/:name" [name] + (render-string "Hello {{name}}" {:name name}))) +``` + +You can easily read in templates from your resources directory. Here's a helper function + +```clojure +(require 'clojure.java.io) + +(defn read-template [filename] + (slurp (clojure.java.io/resource filename))) + +(defroutes myapp + (GET "/hello/:name" [name] + (render-string (read-template "templates/hello.html") {:name name}))) +``` + +#### [Selmer](https://github.com/yogthos/Selmer) + +[Selmer](https://github.com/yogthos/Selmer) is a Django and Jinja2-inspired templating language: + +```clojure +(require '[selmer.parser :refer [render-file]]) + +(defroutes myapp + (GET "/hello/:name" [name] + (render-file "templates/hello.html" {:name name}))) +``` + +#### [Hiccup](https://github.com/weavejester/hiccup) + +[Hiccup](https://github.com/weavejester/hiccup) is a library for representing HTML as Clojure code + +```clojure +(require '[hiccup.core :as hiccup]) + +(defroutes myapp + (GET "/hello/:name" [name] + (hiccup/html + [:html + [:body + [:h1 {:class "title"} + (str "Hello " name)]]]))) +``` + +#### [Markdown](https://github.com/yogthos/markdown-clj) + +[Markdown-clj](https://github.com/yogthos/markdown-clj) is a Markdown implementation. + +```clojure +(require '[markdown.core :refer [md-to-html-string]]) + +(defroutes myapp + (GET "/hello/:name" [name] + (md-to-html-string "## Hello, world"))) +``` + +Further reading: + +* [Official Compojure Documentation](https://github.com/weavejester/compojure/wiki) + +* [Clojure for the Brave and True](http://www.braveclojure.com/) diff --git a/es-es/markdown-es.html.markdown b/es-es/markdown-es.html.markdown index 3865126c..d90e3eb5 100644 --- a/es-es/markdown-es.html.markdown +++ b/es-es/markdown-es.html.markdown @@ -14,7 +14,7 @@ fácilmente a HTML (y, actualmente, otros formatos también). ¡Denme todo la retroalimentación que quieran! / ¡Sientanse en la libertad de hacer forks o pull requests! -``` +```markdown + + + + + + +# 这是一个

+## 这是一个

+### 这是一个

+#### 这是一个

+##### 这是一个

+###### 这是一个
+ + +这是一个 h1 +============= + +这是一个 h2 +------------- + + + + +*此文本为斜体。* +_此文本也是。_ + +**此文本为粗体。** +__此文本也是__ + +***此文本是斜体加粗体。*** +**_或者这样。_** +*__这个也是!__* + + + +~~此文本为删除线效果。~~ + + + +这是第一段落. 这句话在同一个段落里,好玩么? + +现在我是第二段落。 +这句话也在第二段落! + +这句话在第三段落! + + + +此段落结尾有两个空格(选中以显示)。 + +上文有一个
! + + + +> 这是一个段落引用. 你可以 +> 手动断开你的句子,然后在每句句子前面添加 “>” 字符。或者让你的句子变得很长,以至于他们自动得断开。 +> 只要你的文字以“>” 字符开头,两种方式无异。 + +> 你也对文本进行 +>> 多层引用 +> 这多机智啊! + + + + +* 项目 +* 项目 +* 另一个项目 + +或者 + ++ 项目 ++ 项目 ++ 另一个项目 + +或者 + +- 项目 +- 项目 +- 最后一个项目 + + + +1. 项目一 +2. 项目二 +3. 项目三 + + + +1. 项目一 +1. 项目二 +1. 项目三 + + + + +1. 项目一 +2. 项目二 +3. 项目三 + * 子项目 + * 子项目 +4. 项目四 + + + + + This is code + So is this + + + + my_array.each do |item| + puts item + end + + + +John 甚至不知道 `go_to()` 方程是干嘛的! + + + +\`\`\`ruby +def foobar + puts "Hello world!" +end +\`\`\` + + + + + + +*** +--- +- - - +**************** + + + + +[点我点我!](http://test.com/) + + + +[点我点我!](http://test.com/ "连接到Test.com") + + + +[去 music](/music/). + + + +[点此链接][link1]以获取更多信息! +[看一看这个链接][foobar] 如果你愿意的话. + +[link1]: http://test.com/ "Cool!" +[foobar]: http://foobar.biz/ "Alright!" + + + + + +[This][] is a link. + +[this]: http://thisisalink.com/ + + + + + + +![这是我图像的悬停文本(alt text)](http://imgur.com/myimage.jpg "可选命名") + + + +![这是我的悬停文本.][myimage] + +[myimage]: relative/urls/cool/image.jpg "在此输入标题" + + + + + 与 +[http://testwebsite.com/](http://testwebsite.com/) 等同 + + + + + + + +我希望 *将这段文字置于星号之间* 但是我不希望它被 +斜体化, 所以我就: \*这段置文字于星号之间\*。 + + + + +| 第一列 | 第二列 | 第三列 | +| :---------- | :------: | ----------: | +| 左对齐 | 居个中 | 右对齐 | +| 某某某 | 某某某 | 某某某 | + + + +第一列 | 第二列 | 第三列 +:-- | :-: | --: +这太丑了 | 药不能 | 停 + + + +``` + +更多信息, 请于[此处](http://daringfireball.net/projects/Markdown/syntax)参见 John Gruber 关于语法的官方帖子,及于[此处](https://github.com/adam-p/Markdown-here/wiki/Markdown-Cheatsheet) 参见 Adam Pritchard 的摘要笔记。 diff --git a/zh-cn/r-cn.html.markdown b/zh-cn/r-cn.html.markdown index 19c5f25d..0c46bc22 100644 --- a/zh-cn/r-cn.html.markdown +++ b/zh-cn/r-cn.html.markdown @@ -13,7 +13,7 @@ lang: zh-cn R 是一门统计语言。它有很多数据分析和挖掘程序包。可以用来统计、分析和制图。 你也可以在 LaTeX 文档中运行 `R` 命令。 -```python +```r # 评论以 # 开始 # R 语言原生不支持 多行注释 diff --git a/zh-cn/scala-cn.html.markdown b/zh-cn/scala-cn.html.markdown index 28af8ddc..58f5cd47 100644 --- a/zh-cn/scala-cn.html.markdown +++ b/zh-cn/scala-cn.html.markdown @@ -11,7 +11,7 @@ lang: zh-cn Scala - 一门可拓展性的语言 -```cpp +```scala /* 自行设置: diff --git a/zh-cn/swift-cn.html.markdown b/zh-cn/swift-cn.html.markdown index c87f9d10..b9696c72 100644 --- a/zh-cn/swift-cn.html.markdown +++ b/zh-cn/swift-cn.html.markdown @@ -12,7 +12,7 @@ Swift 是Apple 开发的用于iOS 和OS X 开发的编程语言。Swift 于2014 参阅:Apple's [getting started guide](https://developer.apple.com/library/prerelease/ios/referencelibrary/GettingStarted/LandingPage/index.html) ——一个完整的Swift 教程 -```js +```swift // // 基础 //