From 00302473841679ef7d3115fa03aac481f31d390f Mon Sep 17 00:00:00 2001 From: haiiiiiyun Date: Sat, 27 Aug 2016 13:38:04 +0800 Subject: zh-cn ruby page sync with English version & minor tweaks --- zh-cn/ruby-cn.html.markdown | 401 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 339 insertions(+), 62 deletions(-) diff --git a/zh-cn/ruby-cn.html.markdown b/zh-cn/ruby-cn.html.markdown index 14d38137..2d181de0 100644 --- a/zh-cn/ruby-cn.html.markdown +++ b/zh-cn/ruby-cn.html.markdown @@ -10,6 +10,7 @@ contributors: - ["ftwbzhao", "https://github.com/ftwbzhao"] translators: - ["Lin Xiangyu", "https://github.com/oa414"] + - ["Jiang Haiyun", "https://github.com/haiiiiiyun"] --- ```ruby @@ -35,6 +36,13 @@ translators: 8 - 1 #=> 7 10 * 2 #=> 20 35 / 5 #=> 7 +2**5 #=> 32 +5 % 3 #=> 2 + +# 位运算符 +3 & 5 #=> 1 +3 | 5 #=> 7 +3 ^ 5 #=> 6 # 算术符号只是语法糖而已 # 实际上是调用对象的方法 @@ -42,7 +50,7 @@ translators: 10.* 5 #=> 50 # 特殊的值也是对象 -nil # 空 +nil # 相当于其它语言中的 null true # 真 false # 假 @@ -54,13 +62,11 @@ false.class #=> FalseClass 1 == 1 #=> true 2 == 1 #=> false -# 不等运算符 +# 不相等运算符 1 != 1 #=> false 2 != 1 #=> true -!true #=> false -!false #=> true -# 除了false自己,nil是唯一的值为false的对象 +# 除了false自己,nil是唯一的另一个值为false的对象 !nil #=> true !false #=> true @@ -72,6 +78,26 @@ false.class #=> FalseClass 2 <= 2 #=> true 2 >= 2 #=> true + +# 组合比较运算符 +1 <=> 10 #=> -1 +10 <=> 1 #=> 1 +1 <=> 1 #=> 0 + +# 逻辑运算符 +true && false #=> false +true || false #=> true +!true #=> false + +# 也有优先级更低的逻辑运算符 +# 它们用于控制流结构中,用来串接语句,直到返回true或false。 + +# `do_something_else` 只当 `do_something` 返回true时才会被调用 +do_something() and do_something_else() +# `log_error` 只当 `do_something` 返回false时才会被调用 +do_something() or log_error() + + # 字符串是对象 'I am a string'.class #=> String @@ -81,9 +107,28 @@ placeholder = "use string interpolation" "I can #{placeholder} when using double quoted strings" #=> "I can use string interpolation when using double quoted strings" +# 尽可能优先使用单引号的字符串 +# 双引号的字符串会进行一些额外的内部处理 + +# 合并字符串,但不能和数字合并 +'hello ' + 'world' #=> "hello world" +'hello ' + 3 #=> TypeError: can't convert Fixnum into String +'hello ' + 3.to_s #=> "hello 3" + +# 合并字符串及其运算符 +'hello ' * 3 #=> "hello hello hello " + +# 字符串追加 +'hello' << ' world' #=> "hello world" -# 输出值 +# 打印输出,并在末尾加换行符 puts "I'm printing!" +#=> I'm printing! +#=> nil + +# 打印输出,不加换行符 +print "I'm printing!" +#=> I'm printing! => nil # 变量 x = 25 #=> 25 @@ -96,17 +141,16 @@ x = y = 10 #=> 10 x #=> 10 y #=> 10 -# 按照惯例,用 snake_case 作为变量名 +# 按照惯例,使用类似snake_case风格的变量名 snake_case = true -# 使用具有描述性的运算符 +# 使用有意义的变量名 path_to_project_root = '/good/name/' path = '/bad/name/' # 符号(Symbols,也是对象) -# 符号是不可变的,内部用整数类型表示的可重用的值。 -# 通常用它代替字符串来有效地表示有意义的值。 - +# 符号是不可变的,内部用整数值表示的可重用的常数 +# 通常用它代替字符串来有效地表示有意义的值 :pending.class #=> Symbol @@ -132,26 +176,36 @@ array = [1, 2, 3, 4, 5] #=> [1, 2, 3, 4, 5] array[0] #=> 1 array[12] #=> nil -# 像运算符一样,[var]形式的访问 -# 也就是一个语法糖 -# 实际上是调用对象的[] 方法 +# 像运算符一样,[var] 形式的访问 +# 也只是语法糖 +# 实际上是调用对象的 [] 方法 array.[] 0 #=> 1 array.[] 12 #=> nil # 从尾部开始 array[-1] #=> 5 +array.last #=> 5 # 同时指定开始的位置和长度 array[2, 3] #=> [3, 4, 5] -# 或者指定一个范围 +# 将数组逆序 +a=[1,2,3] +a.reverse! #=> [3,2,1] + +# 或者指定一个区间 array[1..3] #=> [2, 3, 4] # 像这样往数组增加一个元素 array << 6 #=> [1, 2, 3, 4, 5, 6] +# 或者像这样 +array.push(6) #=> [1, 2, 3, 4, 5, 6] -# 哈希表是Ruby的键值对的基本数据结构 -# 哈希表由大括号定义 +# 检查元素是否包含在数组中 +array.include?(1) #=> true + +# 哈希表是 Ruby 的主要键/值对表示法 +# 哈希表由大括号表示 hash = {'color' => 'green', 'number' => 5} hash.keys #=> ['color', 'number'] @@ -163,19 +217,14 @@ hash['number'] #=> 5 # 查询一个不存在地键将会返回nil hash['nothing here'] #=> nil -# 用 #each 方法来枚举哈希表: -hash.each do |k, v| - puts "#{k} is #{v}" -end - -# 从Ruby 1.9开始, 用符号作为键的时候有特别的记号表示: +# 从Ruby 1.9开始,用符号作为键的时候有特别的记号表示: -new_hash = { defcon: 3, action: true} +new_hash = { defcon: 3, action: true } new_hash.keys #=> [:defcon, :action] # 小贴士:数组和哈希表都是可枚举的 -# 它们可以共享一些有用的方法,比如each, map, count 等等 +# 它们共享一些有用的方法,比如each,map,count等等 # 控制流 @@ -196,9 +245,15 @@ end #=> iteration 4 #=> iteration 5 -# 然而 -# 没人用for循环 -# 用`each`来代替,就像这样 + +# 但是,没有人用for循环。 +# 你应该使用"each"方法,然后再传给它一个块。 +# 所谓块就是可以传给像"each"这样的方法的代码段。 +# 它类似于其它语言中的lambdas, 匿名函数或闭包。 +# +# 区间上的"each"方法会对区间中的每个元素运行一次块代码。 +# 我们将counter作为一个参数传给了块。 +# 调用带有块的"each"方法看起来如下: (1..5).each do |counter| puts "iteration #{counter}" @@ -209,6 +264,23 @@ end #=> iteration 4 #=> iteration 5 +# 你也可以将块包含在一个大括号中: +(1..5).each { |counter| puts "iteration #{counter}" } + +# 数据结构中的内容也可以使用each来遍历。 +array.each do |element| + puts "#{element} is part of the array" +end +hash.each do |key, value| + puts "#{key} is #{value}" +end + +# 如果你还需要索引值,可以使用"each_with_index",并且定义 +# 一个索引变量 +array.each_with_index do |element, index| + puts "#{element} is number #{index} in the array" +end + counter = 1 while counter <= 5 do puts "iteration #{counter}" @@ -220,6 +292,20 @@ end #=> iteration 4 #=> iteration 5 +# Ruby 中还有很多有用的循环遍历函数, +# 如"map","reduce","inject"等等。 +# 以map为例,它会遍历数组,并根据你在 +# 块中定义的逻辑对它进行处理,然后返回 +# 一个全新的数组。 +array = [1,2,3,4,5] +doubled = array.map do |element| + element * 2 +end +puts doubled +#=> [2,4,6,8,10] +puts array +#=> [1,2,3,4,5] + grade = 'B' case grade @@ -236,6 +322,33 @@ when 'F' else puts "Alternative grading system, eh?" end +#=> "Better luck next time" + +# case也可以用区间 +grade = 82 +case grade +when 90..100 + puts 'Hooray!' +when 80...90 + puts 'OK job' +else + puts 'You failed!' +end +#=> "OK job" + +# 异常处理: +begin + # 这里的代码可能会抛出异常 + raise NoMemoryError, 'You ran out of memory.' +rescue NoMemoryError => exception_variable + puts 'NoMemoryError was raised', exception_variable +rescue RuntimeError => other_exception_variable + puts 'RuntimeError was raised now' +else + puts 'This runs if no exceptions were thrown at all' +ensure + puts 'This code always runs no matter what' +end # 函数 @@ -243,7 +356,7 @@ def double(x) x * 2 end -# 函数 (以及所有的方法块) 隐式地返回了最后语句的值 +# 函数 (以及所有的块) 隐式地返回最后语句的值 double(2) #=> 4 # 当不存在歧义的时候括号是可有可无的 @@ -261,8 +374,8 @@ sum 3, 4 #=> 7 sum sum(3,4), 5 #=> 12 # yield -# 所有的方法都有一个隐式的块参数 -# 可以用yield参数调用 +# 所有的方法都有一个隐式的,可选的块参数 +# 可以用 'yield' 关键字调用 def surround puts "{" @@ -276,45 +389,84 @@ surround { puts 'hello world' } # hello world # } +# 可以向函数传递一个块 +# "&"标记传递的块是一个引用 +def guests(&block) + block.call 'some_argument' +end -# 用class关键字定义一个类 -class Human - - # 一个类变量,它被这个类地所有实例变量共享 - @@species = "H. sapiens" +# 可以传递多个参数,这些参数会转成一个数组, +# 这也是使用星号符 ("*") 的原因: +def guests(*array) + array.each { |guest| puts guest } +end - # 构造函数 - def initialize(name, age=0) - # 将参数name的值赋给实例变量@name - @name = name - # 如果没有给出age, 那么会采用参数列表中地默认地值 - @age = age - end +# 如果函数返回一个数组,在赋值时可以进行拆分: +def foods + ['pancake', 'sandwich', 'quesadilla'] +end +breakfast, lunch, dinner = foods +breakfast #=> 'pancake' +dinner #=> 'quesadilla' - # 基本的 setter 方法 - def name=(name) - @name = name - end +# 按照惯例,所有返回布尔值的方法都以?结尾 +5.even? # false +5.odd? # true - # 基本地 getter 方法 - def name - @name - end +# 如果方法名末尾有!,表示会做一些破坏性的操作,比如修改调用者自身。 +# 很多方法都会有一个!的版本来进行修改,和一个非!的版本 +# 只用来返回更新了的结果 +company_name = "Dunder Mifflin" +company_name.upcase #=> "DUNDER MIFFLIN" +company_name #=> "Dunder Mifflin" +company_name.upcase! # we're mutating company_name this time! +company_name #=> "DUNDER MIFFLIN" - # 一个类方法以self.开头 - # 它可以被类调用,但不能被类的实例调用 - def self.say(msg) - puts "#{msg}" - end - def species - @@species - end +# 用class关键字定义一个类 +class Human + # 一个类变量,它被这个类的所有实例变量共享 + @@species = "H. sapiens" + + # 基本构造函数 + def initialize(name, age = 0) + # 将参数值赋给实例变量"name" + @name = name + # 如果没有给出age,那么会采用参数列表中的默认值 + @age = age + end + + # 基本的setter方法 + def name=(name) + @name = name + end + + # 基本地getter方法 + def name + @name + end + + # 以上的功能也可以用下面的attr_accessor来封装 + attr_accessor :name + + # Getter/setter方法也可以像这样单独创建 + attr_reader :name + attr_writer :name + + # 类方法通过使用self与实例方法区别开来。 + # 它只能通过类来调用,不能通过实例调用。 + def self.say(msg) + puts "#{msg}" + end + + def species + @@species + end end -# 类的例子 +# 初始化一个类 jim = Human.new("Jim Halpert") dwight = Human.new("Dwight K. Schrute") @@ -327,7 +479,132 @@ jim.name #=> "Jim Halpert II" dwight.species #=> "H. sapiens" dwight.name #=> "Dwight K. Schrute" -# 调用对象的方法 -Human.say("Hi") #=> "Hi" +# 调用类方法 +Human.say('Hi') #=> "Hi" + +# 变量的作用域由它们的名字格式定义 +# 以$开头的变量具有全局域 +$var = "I'm a global var" +defined? $var #=> "global-variable" + +# 以@开头的变量具有实例作用域 +@var = "I'm an instance var" +defined? @var #=> "instance-variable" + +# 以@@开头的变量具有类作用域 +@@var = "I'm a class var" +defined? @@var #=> "class variable" + +# 以大写字母开头的变量是常数 +Var = "I'm a constant" +defined? Var #=> "constant" + +# 类也是对象。因此类也可以有实例变量。 +# 类变量在类以及其继承者之间共享。 + +# 基类 +class Human + @@foo = 0 + + def self.foo + @@foo + end + + def self.foo=(value) + @@foo = value + end +end + +# 派生类 +class Worker < Human +end + +Human.foo # 0 +Worker.foo # 0 + +Human.foo = 2 # 2 +Worker.foo # 2 + +# 类实例变量不能在继承类间共享。 + +class Human + @bar = 0 + + def self.bar + @bar + end + + def self.bar=(value) + @bar = value + end +end + +class Doctor < Human +end + +Human.bar # 0 +Doctor.bar # nil + +module ModuleExample + def foo + 'foo' + end +end + +# '包含'模块后,模块的方法会绑定为类的实例方法 +# '扩展'模块后,模块的方法会绑定为类方法 + +class Person + include ModuleExample +end + +class Book + extend ModuleExample +end + +Person.foo # => NoMethodError: undefined method `foo' for Person:Class +Person.new.foo # => 'foo' +Book.foo # => 'foo' +Book.new.foo # => NoMethodError: undefined method `foo' + +# 当包含或扩展一个模块时,相应的回调代码会被执行。 +module ConcernExample + def self.included(base) + base.extend(ClassMethods) + base.send(:include, InstanceMethods) + end + + module ClassMethods + def bar + 'bar' + end + end + + module InstanceMethods + def qux + 'qux' + end + end +end + +class Something + include ConcernExample +end + +Something.bar # => 'bar' +Something.qux # => NoMethodError: undefined method `qux' +Something.new.bar # => NoMethodError: undefined method `bar' +Something.new.qux # => 'qux' ``` + + +## 其它资源 + +- [Learn Ruby by Example with Challenges](http://www.learneroo.com/modules/61/nodes/338) - A variant of this reference with in-browser challenges. +- [An Interactive Tutorial for Ruby](https://rubymonk.com/) - Learn Ruby through a series of interactive tutorials. +- [Official Documentation](http://ruby-doc.org/core) +- [Ruby from other languages](https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/) +- [Programming Ruby](http://www.amazon.com/Programming-Ruby-1-9-2-0-Programmers/dp/1937785491/) - An older [free edition](http://ruby-doc.com/docs/ProgrammingRuby/) is available online. +- [Ruby Style Guide](https://github.com/bbatsov/ruby-style-guide) - A community-driven Ruby coding style guide. +- [Try Ruby](http://tryruby.org) - Learn the basic of Ruby programming language, interactive in the browser. -- cgit v1.2.3 From 678fa3b97468a903fc256d95c58f54db5a531a64 Mon Sep 17 00:00:00 2001 From: Patrick Callahan Date: Thu, 1 Sep 2016 02:28:23 -0400 Subject: Remove Python 2 resources from Python 3 page (#2350) There were several resources here that teach Python 2, but not Python 3. I removed them so that a reader will only see resources that apply to Python 3. --- python3.html.markdown | 5 ----- 1 file changed, 5 deletions(-) diff --git a/python3.html.markdown b/python3.html.markdown index 6b3486a6..09b041b8 100644 --- a/python3.html.markdown +++ b/python3.html.markdown @@ -887,12 +887,9 @@ print(say(say_please=True)) # Can you buy me a beer? Please! I am poor :( ### Free Online * [Automate the Boring Stuff with Python](https://automatetheboringstuff.com) -* [Learn Python The Hard Way](http://learnpythonthehardway.org/book/) -* [Dive Into Python](http://www.diveintopython.net/) * [Ideas for Python Projects](http://pythonpracticeprojects.com) * [The Official Docs](http://docs.python.org/3/) * [Hitchhiker's Guide to Python](http://docs.python-guide.org/en/latest/) -* [A Crash Course in Python for Scientists](http://nbviewer.ipython.org/5920182) * [Python Course](http://www.python-course.eu/index.php) * [First Steps With Python](https://realpython.com/learn/python-first-steps/) * [A curated list of awesome Python frameworks, libraries and software](https://github.com/vinta/awesome-python) @@ -903,5 +900,3 @@ print(say(say_please=True)) # Can you buy me a beer? Please! I am poor :( ### Dead Tree * [Programming Python](http://www.amazon.com/gp/product/0596158106/ref=as_li_qf_sp_asin_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=0596158106&linkCode=as2&tag=homebits04-20) -* [Dive Into Python](http://www.amazon.com/gp/product/1441413022/ref=as_li_tf_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1441413022&linkCode=as2&tag=homebits04-20) -* [Python Essential Reference](http://www.amazon.com/gp/product/0672329786/ref=as_li_tf_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=0672329786&linkCode=as2&tag=homebits04-20) -- cgit v1.2.3 From 3d270111bd45c8eac51a642951e81e3313436648 Mon Sep 17 00:00:00 2001 From: Alois Date: Thu, 1 Sep 2016 19:27:41 +0200 Subject: [WIP] [toml/en] Add TOML support (#2282) * Init support for TOML * Add scalar types section * Move comment to key value * Improve introduction * Move int comment to int key value * Add array support * Add version warning * Add support for table * Add inline table part * Add support array of table part * Fix bugs/typos to follow the review * Improve sub tables example * Fix wrong quotes on multiLineLiteralString * Fix letter case for coherence * Remove old comment * Move from variety to color Thanks @robochat --- toml.html.markdown | 274 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 274 insertions(+) create mode 100755 toml.html.markdown diff --git a/toml.html.markdown b/toml.html.markdown new file mode 100755 index 00000000..980563f9 --- /dev/null +++ b/toml.html.markdown @@ -0,0 +1,274 @@ +--- +language: toml +filename: learntoml.toml +contributors: + - ["Alois de Gouvello", "https://github.com/aloisdg"] +--- + +TOML stands for Tom's Obvious, Minimal Language. It is a data serialisation language designed to be a minimal configuration file format that's easy to read due to obvious semantics. + +It is an alternative to YAML and JSON. It aims to be more human friendly than JSON and simpler that YAML. TOML is designed to map unambiguously to a hash table. TOML should be easy to parse into data structures in a wide variety of languages. + +Be warned, TOML's spec is still changing a lot. Until it's marked as 1.0, you +should assume that it is unstable and act accordingly. This document follows TOML v0.4.0. + +```toml +# Comments in TOML look like this. + +################ +# SCALAR TYPES # +################ + +# Our root object (which continues for the entire document) will be a map, +# which is equivalent to a dictionary, hash or object in other languages. + +# The key, equals sign, and value must be on the same line +# (though some values can be broken over multiple lines). +key = "value" +string = "hello" +number = 42 +float = 3.14 +boolean = true +dateTime = 1979-05-27T07:32:00-08:00 +scientificNotation = 1e+12 +"key can be quoted" = true # Both " and ' are fine +"key may contains" = "letters, numbers, underscores, and dashes" + +# A bare key must be non-empty, but an empty quoted key is allowed +"" = "blank" # VALID but discouraged +'' = 'blank' # VALID but discouraged + +########## +# String # +########## + +# All strings must contain only valid UTF-8 characters. +# We can escape characters and some of them have a compact escape sequence. +# For example, \t add a tabulation. Refers to the spec to get all of them. +basicString = "are surrounded by quotation marks. \"I'm quotable\". Name\tJos" + +multiLineString = """ +are surrounded by three quotation marks +on each side and allow newlines.""" + +literalString = 'are surrounded by single quotes. Escaping are not allowed.' + +multiLineLiteralString = ''' +are surrounded by three single quotes on each side +and allow newlines. Still no escaping. +The first newline is trimmed in raw strings. + All other whitespace + is preserved. #! are preserved? +''' + +# For binary data it is recommended that you use Base64, another ASCII or UTF8 +# encoding. The handling of that encoding will be application specific. + +########### +# Integer # +########### + +## Integers can start with a +, a - or nothing. +## Leading zeros are not allowed. Hex, octal, and binary forms are not allowed. +## Values that cannot be expressed as a series of digits are not allowed. +int1 = +42 +int2 = 0 +int3 = -21 +integerRange = 64 + +## You can use underscores to enhance readability. Each +## underscore must be surrounded by at least one digit. +int4 = 5_349_221 +int5 = 1_2_3_4_5 # VALID but discouraged + +######### +# Float # +######### + +# Floats are an integer followed by a fractional and/or an exponent part. +flt1 = 3.1415 +flt2 = -5e6 +flt3 = 6.626E-34 + +########### +# Boolean # +########### + +bool1 = true +bool2 = false +boolMustBeLowercase = true + +############ +# Datetime # +############ + +date1 = 1979-05-27T07:32:00Z # follows the RFC 3339 spec +date2 = 1979-05-27T07:32:00 # without offset +date3 = 1979-05-27 # without offset nor time + +#################### +# COLLECTION TYPES # +#################### + +######### +# Array # +######### + +array1 = [ 1, 2, 3 ] +array2 = [ "Commas", "are", "delimiters" ] +array3 = [ "Don't mixed", "different", "types" ] +array4 = [ [ 1.2, 2.4 ], ["all", 'strings', """are the same""", '''type'''] ] +array5 = [ + "Whitespace", "is", "ignored" +] + +######### +# Table # +######### + +# Tables (or hash tables or dictionaries) are collections of key/value +# pairs. They appear in square brackets on a line by themselves. +# Empty tables are allowed and simply have no key/value pairs within them. +[table] + +# Under that, and until the next table or EOF are the key/values of that table. +# Key/value pairs within tables are not guaranteed to be in any specific order. +[table-1] +key1 = "some string" +key2 = 123 + +[table-2] +key1 = "another string" +key2 = 456 + +# Dots are prohibited in bare keys because dots are used to signify nested tables. +# Naming rules for each dot separated part are the same as for keys. +[dog."tater.man"] +type = "pug" + +# In JSON land, that would give you the following structure: +# { "dog": { "tater.man": { "type": "pug" } } } + +# Whitespace around dot-separated parts is ignored, however, best practice is to +# not use any extraneous whitespace. +[a.b.c] # this is best practice +[ d.e.f ] # same as [d.e.f] +[ j . "ʞ" . 'l' ] # same as [j."ʞ".'l'] + +# You don't need to specify all the super-tables if you don't want to. TOML knows +# how to do it for you. +# [x] you +# [x.y] don't +# [x.y.z] need these +[x.y.z.w] # for this to work + +# As long as a super-table hasn't been directly defined and hasn't defined a +# specific key, you may still write to it. +[a.b] +c = 1 + +[a] +d = 2 + +# You cannot define any key or table more than once. Doing so is invalid. + +# DO NOT DO THIS +[a] +b = 1 + +[a] +c = 2 + +# DO NOT DO THIS EITHER +[a] +b = 1 + +[a.b] +c = 2 + +# All table names must be non-empty. +[] # INVALID +[a.] # INVALID +[a..b] # INVALID +[.b] # INVALID +[.] # INVALID + +################ +# Inline table # +################ + +inlineTables = { areEnclosedWith = "{ and }", mustBeInline = true } +point = { x = 1, y = 2 } + +################### +# Array of Tables # +################### + +# An array of tables can be expressed by using a table name in double brackets. +# Each table with the same double bracketed name will be an item in the array. +# The tables are inserted in the order encountered. + +[[products]] +name = "array of table" +sku = 738594937 +emptyTableAreAllowed = true + +[[products]] + +[[products]] +name = "Nail" +sku = 284758393 +color = "gray" + +# You can create nested arrays of tables as well. Each double-bracketed +# sub-table will belong to the nearest table element above it. + +[[fruit]] + name = "apple" + + [fruit.Geometry] + shape = "round" + note = "I am an fruit's property" + + [[fruit.color]] + name = "red" + note = "I am an array's item in apple" + + [[fruit.color]] + name = "green" + note = "I am in the same array than red" + +[[fruit]] + name = "banana" + + [[fruit.color]] + name = "yellow" + note = "I am an array's item too but banana's one" +``` + +In JSON land, this code will be: + +```json +{ + "fruit": [ + { + "name": "apple", + "geometry": { "shape": "round", "note": "..."}, + "color": [ + { "name": "red", "note": "..." }, + { "name": "green", "note": "..." } + ] + }, + { + "name": "banana", + "color": [ + { "name": "yellow", "note": "..." } + ] + } + ] +} +``` + +### More Resources + ++ [TOML official repository](https://github.com/toml-lang/toml) -- cgit v1.2.3 From 425d1dee6704599029ef7e27445328ad4c91d341 Mon Sep 17 00:00:00 2001 From: ven Date: Thu, 1 Sep 2016 21:03:09 +0200 Subject: Delete HTML-fr.html.markdown --- HTML-fr.html.markdown | 115 -------------------------------------------------- 1 file changed, 115 deletions(-) delete mode 100644 HTML-fr.html.markdown diff --git a/HTML-fr.html.markdown b/HTML-fr.html.markdown deleted file mode 100644 index fdde9107..00000000 --- a/HTML-fr.html.markdown +++ /dev/null @@ -1,115 +0,0 @@ ---- -language: html -filename: learnhtml-fr.html -contributors: - - ["Christophe THOMAS", "https://github.com/WinChris"] -lang: fr-fr ---- -HTML signifie HyperText Markup Language. -C'est un langage (format de fichiers) qui permet d'écrire des pages internet. -C’est un langage de balisage, il nous permet d'écrire des pages HTML au moyen de balises (Markup, en anglais). -Les fichiers HTML sont en réalité de simple fichier texte. -Qu'est-ce que le balisage ? C'est une façon de hiérarchiser ses données en les entourant par une balise ouvrante et une balise fermante. -Ce balisage sert à donner une signification au texte ainsi entouré. -Comme tous les autres langages, HTML a plusieurs versions. Ici, nous allons parlons de HTML5. - -**NOTE :** Vous pouvez tester les différentes balises que nous allons voir au fur et à mesure du tutoriel sur des sites comme [codepen](http://codepen.io/pen/) afin de voir les résultats, comprendre, et vous familiariser avec le langage. -Cet article porte principalement sur la syntaxe et quelques astuces. - - -```HTML - - - - - - - - - - - Mon Site - - -

Hello, world!

- Venez voir ce que ça donne -

Ceci est un paragraphe

-

Ceci est un autre paragraphe

-
    -
  • Ceci est un item d'une liste non ordonnée (liste à puces)
  • -
  • Ceci est un autre item
  • -
  • Et ceci est le dernier item de la liste
  • -
- - - - - - - - - - - - - - - - - - - - Mon Site - - - - - - - -

Hello, world!

- - Venez voir ce que ça donne -

Ceci est un paragraphe

-

Ceci est un autre paragraphe

-
    - -
  • Ceci est un item d'une liste non ordonnée (liste à puces)
  • -
  • Ceci est un autre item
  • -
  • Et ceci est le dernier item de la liste
  • -
- - - - - - - - - - - - - - - - - - - - - - - - - -
First Header Second Header
Première ligne, première cellule Première ligne, deuxième cellule
Deuxième ligne, première celluleDeuxième ligne, deuxième cellule
- -## Utilisation - -Le HTML s'écrit dans des fichiers `.html`. - -## En savoir plus - -* [Tutoriel HTML](http://slaout.linux62.org/html_css/html.html) -* [W3School](http://www.w3schools.com/html/html_intro.asp) -- cgit v1.2.3 From 7beaa529b912ccda6e26eee85acae50e79c6d6d5 Mon Sep 17 00:00:00 2001 From: Patrick Callahan Date: Thu, 1 Sep 2016 17:27:33 -0400 Subject: [python3/en] Adding "Dive Into Python 3" (#2353) The previous version of this file had the original Dive Into Python, which was written with Python 2 in mind. It has come to my attention that the author of the original has published an updated version designed for Python 3, so I added this version back in. --- python3.html.markdown | 2 ++ 1 file changed, 2 insertions(+) diff --git a/python3.html.markdown b/python3.html.markdown index 09b041b8..dc534f74 100644 --- a/python3.html.markdown +++ b/python3.html.markdown @@ -896,7 +896,9 @@ print(say(say_please=True)) # Can you buy me a beer? Please! I am poor :( * [30 Python Language Features and Tricks You May Not Know About](http://sahandsaba.com/thirty-python-language-features-and-tricks-you-may-not-know.html) * [Official Style Guide for Python](https://www.python.org/dev/peps/pep-0008/) * [Python 3 Computer Science Circles](http://cscircles.cemc.uwaterloo.ca/) +* [Dive Into Python 3](http://www.diveintopython3.net/index.html) ### Dead Tree * [Programming Python](http://www.amazon.com/gp/product/0596158106/ref=as_li_qf_sp_asin_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=0596158106&linkCode=as2&tag=homebits04-20) +* [Dive Into Python 3](https://www.amazon.com/gp/product/1430224150?ie=UTF8&tag=diveintomark-20&creativeASIN=1430224150) -- cgit v1.2.3 From 66c8b036dcdbcd538f914e14d073194d704159fa Mon Sep 17 00:00:00 2001 From: robochat Date: Sat, 3 Sep 2016 19:30:53 +0200 Subject: [html/en] adding translation of html/fr (#2354) * [html/en] adding a translation of html/fr. * [html/en] small changes and 1 bug fix. * [html/fr] small bug fix. * [html/en] small bug fix. --- fr-fr/HTML-fr.html.markdown | 2 + html.html.markdown | 120 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 html.html.markdown diff --git a/fr-fr/HTML-fr.html.markdown b/fr-fr/HTML-fr.html.markdown index 4d2da921..b52fd34a 100644 --- a/fr-fr/HTML-fr.html.markdown +++ b/fr-fr/HTML-fr.html.markdown @@ -106,6 +106,8 @@ Cet article porte principalement sur la syntaxe et quelques astuces. +``` + ## Utilisation Le HTML s'écrit dans des fichiers `.html`. diff --git a/html.html.markdown b/html.html.markdown new file mode 100644 index 00000000..3e5e43c3 --- /dev/null +++ b/html.html.markdown @@ -0,0 +1,120 @@ +--- +language: html +filename: learnhtml.html +contributors: + - ["Christophe THOMAS", "https://github.com/WinChris"] +translators: + - ["Robert Steed", "https://github.com/robochat"] +--- + +HTML stands for HyperText Markup Language. +It is a language which us to write pages for the world wide web. +It is a markup language, it enables us to write to write webpages using code to indicate how text and data should be displayed. +In fact, html files are simple text files. +What is this markup? It is a method of organising the page's data by surrounding it with opening tags and closing tags. +This markup serves to give significance to the text that it encloses. +Like other computer languages, HTML has many versions. Here we will talk about HTML5. + +**NOTE :** You can test the different tags and elements as you progress through the tutorial on a site like [codepen](http://codepen.io/pen/) in order to see their effects, understand how they work and familiarise yourself with the language. +This article is concerned principally with HTML syntax and some useful tips. + + +```html + + + + + + + + + + My Site + + +

Hello, world!

+ Come look at what this shows/a> +

This is a paragraph.

+

This is another paragraph.

+
    +
  • This is an item in a non-enumerated list (bullet list)
  • +
  • This is another item
  • +
  • And this is the last item on the list
  • +
+ + + + + + + + + + + + + + + + + + + + + My Site + + + + + + + +

Hello, world!

+ +
Come look at what this shows +

This is a paragraph.

+

This is another paragraph.

+
    + +
  • This is an item in a non-enumerated list (bullet list)
  • +
  • This is another item
  • +
  • And this is the last item on the list
  • +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
First Header Second Header
first row, first column first row, second column
second row, first columnsecond row, second column
+ +``` + +## Usage + +HTML is written in files ending with `.html`. + +## To Learn More + +* [wikipedia](https://en.wikipedia.org/wiki/HTML) +* [HTML tutorial](https://developer.mozilla.org/en-US/docs/Web/HTML) +* [W3School](http://www.w3schools.com/html/html_intro.asp) -- cgit v1.2.3 From a00c47f70141ee694eef7dabc54778d3c178607d Mon Sep 17 00:00:00 2001 From: Baurzhan Muftakhidinov Date: Mon, 5 Sep 2016 12:42:02 +0500 Subject: Add missing space. (#2356) --- binary-search.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/binary-search.html.markdown b/binary-search.html.markdown index 92df4875..ce436b44 100644 --- a/binary-search.html.markdown +++ b/binary-search.html.markdown @@ -9,7 +9,7 @@ contributors: ## Why Binary Search? -Searching is one of the prime problems in the domain of Computer Science.Today there are more than 1 trillion searches per year, and we need algorithms that can do that very fastly. Binary search is one of the fundamental algorithms in computer science. In order to explore it, we’ll first build up a theoretical backbone, then use that to implement the algorithm properly. +Searching is one of the prime problems in the domain of Computer Science. Today there are more than 1 trillion searches per year, and we need algorithms that can do that very fastly. Binary search is one of the fundamental algorithms in computer science. In order to explore it, we’ll first build up a theoretical backbone, then use that to implement the algorithm properly. ## Introduction -- cgit v1.2.3 From d75468c6fe58c3152facf0dffd8743a6c2edbec0 Mon Sep 17 00:00:00 2001 From: robochat Date: Mon, 5 Sep 2016 10:34:25 +0200 Subject: adding missing lang entries to headers for 3 tutorials (#2352) --- id-id/markdown.html.markdown | 1 + it-it/rust-it.html.markdown | 1 + pt-br/elixir.html.markdown | 1 + 3 files changed, 3 insertions(+) diff --git a/id-id/markdown.html.markdown b/id-id/markdown.html.markdown index 9a7c18cc..06ad1092 100644 --- a/id-id/markdown.html.markdown +++ b/id-id/markdown.html.markdown @@ -4,6 +4,7 @@ contributors: - ["Dan Turkel", "http://danturkel.com/"] translators: - ["Tasya Aditya Rukmana", "http://github.com/tadityar"] +lang: id-id filename: markdown-id.md --- diff --git a/it-it/rust-it.html.markdown b/it-it/rust-it.html.markdown index dd5005f2..8ef09712 100644 --- a/it-it/rust-it.html.markdown +++ b/it-it/rust-it.html.markdown @@ -2,6 +2,7 @@ language: rust contributors: - ["Carlo Milanesi", "http://github.com/carlomilanesi"] +lang: it-it filename: rust-it.html.markdown --- diff --git a/pt-br/elixir.html.markdown b/pt-br/elixir.html.markdown index b4ca8a52..f8c56101 100644 --- a/pt-br/elixir.html.markdown +++ b/pt-br/elixir.html.markdown @@ -5,6 +5,7 @@ contributors: - ["Dzianis Dashkevich", "https://github.com/dskecse"] translators: - ["Rodrigo Muniz", "http://github.com/muniz95"] +lang: pt-br filename: learnelixir-pt.ex --- -- cgit v1.2.3 From 30e5ceed3174347d675b5eb9a474c960e1542d44 Mon Sep 17 00:00:00 2001 From: Ondrej Linek Date: Mon, 5 Sep 2016 22:19:17 +0200 Subject: add Czech [cs-cz] translation of the Go intro. (#2357) --- cs-cz/go.html.markdown | 431 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 431 insertions(+) create mode 100644 cs-cz/go.html.markdown diff --git a/cs-cz/go.html.markdown b/cs-cz/go.html.markdown new file mode 100644 index 00000000..f814d2da --- /dev/null +++ b/cs-cz/go.html.markdown @@ -0,0 +1,431 @@ +--- +name: Go +category: language +language: Go +filename: learngo.go +contributors: + - ["Sonia Keys", "https://github.com/soniakeys"] + - ["Christopher Bess", "https://github.com/cbess"] + - ["Jesse Johnson", "https://github.com/holocronweaver"] + - ["Quint Guvernator", "https://github.com/qguv"] + - ["Jose Donizetti", "https://github.com/josedonizetti"] + - ["Alexej Friesen", "https://github.com/heyalexej"] + - ["Clayton Walker", "https://github.com/cwalk"] +translators: + - ["Ondra Linek", "https://github.com/defectus/"] + +--- + +Jazyk Go byl vytvořen, jelikož bylo potřeba dokončit práci. Není to poslední +trend ve světě počítačové vědy, ale je to nejrychlejší a nejnovější způsob, +jak řešit realné problémy. + +Go používá známé koncepty imperativních jazyků se statickým typováním. +Rychle se kompiluje a také rychle běží. Přidává snadno pochopitelnou +podporu konkurenčnosti, což umožňuje využít výhody multi-core procesorů a +jazyk také obsahuje utility, které pomáhají se škálovatelným programováním. + +Go má již v základu vynikající knihovnu a je s ním spojená nadšená komunita. + +```go +// Jednořádkový komentář +/* Několika + řádkový komentář */ + +// Každý zdroják začíná deklarací balíčku (package) +// Main je vyhrazené jméno, které označuje spustitelný soubor, +// narozdíl od knihovny +package main + +// Importní deklarace říkají, které knihovny budou použity v tomto souboru. +import ( + "fmt" // Obsahuje formátovací funkce a tisk na konzolu + "io/ioutil" // Vstupně/výstupní funkce + m "math" // Odkaz na knihovnu math (matematické funkce) pod zkratkou m + "net/http" // Podpora http protokolu, klient i server. + "strconv" // Konverze řetězců, např. na čísla a zpět. +) + +// Definice funkce. Funkce main je zvláštní, je to vstupní bod do programu. +// Ať se vám to líbí, nebo ne, Go používá složené závorky +func main() { + // Println vypisuje na stdout. + // Musí být kvalifikováno jménem svého balíčko, ftm. + fmt.Println("Hello world!") + + // Zavoláme další funkci + svetPoHello() +} + +// Funkce mají své parametry v závorkách +// Pokud funkce nemá parametry, tak musíme stejně závorky uvést. +func svetPoHello() { + var x int // Deklarace proměnné. Proměnné musí být před použitím deklarované + x = 3 // Přiřazení hodnoty do proměnné + // Existuje "krátká" deklarace := kde se typ proměnné odvodí, + // proměnná vytvoří a přiřadí se jí hodnota + y := 4 + sum, prod := naucSeNasobit(x, y) // Funkce mohou vracet více hodnot + fmt.Println("sum:", sum, "prod:", prod) // Jednoduchý výstup + naucSeTypy() // < y minut je za námi, je čas učit se víc! +} + +/* <- začátek mnohořádkového komentáře +Funkce mohou mít parametry a (několik) návratových hodnot. +V tomto případě jsou `x`, `y` parametry a `sum`, `prod` jsou návratové hodnoty. +Všiměte si, že `x` a `sum` jsou typu `int`. +*/ +func naucSeNasobit(x, y int) (sum, prod int) { + return x + y, x * y // Vracíme dvě hodnoty +} + +// zabudované typy a literáty. +func naucSeTypy() { + // Krátká deklarace většinou funguje + str := "Learn Go!" // typ řetězec. + + s2 := `"surový" literát řetězce +může obsahovat nové řádky` // Opět typ řetězec. + + // Můžeme použít ne ASCII znaky, Go používá UTF-8. + g := 'Σ' // type runa, což je alias na int32 a ukládá se do něj znak UTF-8 + + f := 3.14195 // float64, je IEEE-754 64-bit číslem s plovoucí čárkou. + c := 3 + 4i // complex128, interně uložené jako dva float64. + + // takhle vypadá var s inicializací + var u uint = 7 // Číslo bez znaménka, jehož velikost záleží na implementaci, + // stejně jako int + var pi float32 = 22. / 7 + + // takto se převádí typy za pomoci krátké syntaxe + n := byte('\n') // byte je jiné jméno pro uint8. + + // Pole mají fixní délku, které se určuje v době kompilace. + var a4 [4]int // Pole 4 intů, všechny nastaveny na 0. + a3 := [...]int{3, 1, 5} // Pole nastaveno na tři hodnoty + // elementy mají hodntu 3, 1 a 5 + + // Slicy mají dynamickou velikost. Pole i slacy mají své výhody, + // ale většinou se používají slicy. + s3 := []int{4, 5, 9} // Podobně jako a3, ale není tu výpustka. + s4 := make([]int, 4) // Alokuj slice 4 intů, všechny nastaveny na 0. + var d2 [][]float64 // Deklarace slicu, nic se nealokuje. + bs := []byte("a slice") // Přetypování na slice + + // Protože jsou dynamické, můžeme ke slicům přidávat za běhu + // Přidat ke slicu můžeme pomocí zabudované funkce append(). + // Prvním parametrem je slice, návratová hodnota je aktualizovaný slice. + s := []int{1, 2, 3} // Výsledkem je slice se 3 elementy. + s = append(s, 4, 5, 6) // Přidány další 3 elementy. Slice má teď velikost 6. + fmt.Println(s) // Slice má hodnoty [1 2 3 4 5 6] + + // Pokud chceme k poli přičíst jiné pole, můžeme předat referenci na slice, + // nebo jeho literát a přidat výpustku, čímž se slicu "rozbalí" a přidá se k + // původnímu slicu. + s = append(s, []int{7, 8, 9}...) // druhým parametrem je literát slicu. + fmt.Println(s) // slice má teď hodnoty [1 2 3 4 5 6 7 8 9] + + p, q := naucSePraciSPameti() // Deklarujeme p a q jako typ pointer na int. + fmt.Println(*p, *q) // * dereferencuje pointer. Tím se vypíší dva inty. + + // Mapy jsou dynamické rostoucí asociativní pole, jako hashmapa, nebo slovník + // (dictionary) v jiných jazycích + m := map[string]int{"tri": 3, "ctyri": 4} + m["jedna"] = 1 + + // Napoužité proměnné jsou v Go chybou. + // Použijte podtržítko, abychom proměnno "použili". + _, _, _, _, _, _, _, _, _, _ = str, s2, g, f, u, pi, n, a3, s4, bs + // Výpis promenné se počítá jako použití. + fmt.Println(s, c, a4, s3, d2, m) + + naucSeVetveníProgramu() // Zpátky do běhu. +} + +// narozdíl od jiných jazyků, v Go je možné mít pojmenované návratové hodnoty. +// Tak můžeme vracet hodnoty z mnoha míst funkce, aniž bychom uváděli hodnoty v +// return. +func naucSePojmenovaneNavraty(x, y int) (z int) { + z = x * y + return // z je zde implicitní, jelikož bylo pojmenováno. +} + +// Go má garbage collector. Používá pointery, ale neumožňuje jejich aritmetiku. +// Můžete tedy udělat chybu použitím nil odkazu, ale ne jeho posunutím. +func naucSePraciSPameti() (p, q *int) { + // Pojmenované parametry p a q mají typ odkaz na int. + p = new(int) // Zabudované funkce new alokuje paměť. + // Alokované místo pro int má hodnotu 0 a p už není nil. + s := make([]int, 20) // Alokujeme paměť pro 20 intů. + s[3] = 7 // Jednu z nich nastavíme. + r := -2 // Deklarujeme další lokální proměnnou. + return &s[3], &r // a vezmeme si jejich odkaz pomocí &. +} + +func narocnyVypocet() float64 { + return m.Exp(10) +} + +func naucSeVetveníProgramu() { + // Výraz if vyžaduje složené závorky, ale podmínka nemusí být v závorkách. + if true { + fmt.Println("říkal jsme ti to") + } + // Formátování je standardizované pomocí utility "go fmt". + if false { + // posměšek. + } else { + // úšklebek. + } + // Použij switch, když chceš zřetězit if. + x := 42.0 + switch x { + case 0: + case 1: + case 42: + // jednotlivé case nepropadávají. není potřeba "break" + case 43: + // nedosažitelné, jelikož už bylo ošetřeno. + default: + // implicitní větev je nepovinná. + } + // Stejně jako if, for (smyčka) nepoužívá závorky. + // Proměnné definované ve for jsou lokální vůči smyčce. + for x := 0; x < 3; x++ { // ++ je výrazem. + fmt.Println("iterace", x) + } + // zde je x == 42. + + // For je jediná smyčka v Go, ale má několik tvarů. + for { // Nekonečná smyčka + break // Dělám si legraci + continue // Sem se nedostaneme + } + + // Můžete použít klíčové slovo range pro iteraci nad mapami, poli, slicy, + // řetězci a kanály. + // range vrací jednu (kanál) nebo dvě hodnoty (pole, slice, řetězec a mapa). + for key, value := range map[string]int{"jedna": 1, "dva": 2, "tri": 3} { + // pro každý pár (klíč a hodnota) je vypiš + fmt.Printf("klíč=%s, hodnota=%d\n", key, value) + } + + // stejně jako for, := v podmínce if přiřazuje hodnotu + // nejříve nastavíme y a pak otestujeme, jestli je y větší než x. + if y := narocnyVypocet(); y > x { + x = y + } + // Funkční literáty jsou tzv. uzávěry (closure) + xBig := func() bool { + return x > 10000 // odkazuje na x deklarované ve příkladu použití switch + } + x = 99999 + fmt.Println("xBig:", xBig()) // true + x = 1.3e3 // To udělá z x == 1300 + fmt.Println("xBig:", xBig()) // teď už false. + + // Dále je možné funkční literáty definovat a volat na místě jako parametr + // funkce, dokavaď: + // a) funkční literát je okamžitě volán pomocí (), + // b) výsledek se shoduje s očekávaným typem. + fmt.Println("Sečte + vynásobí dvě čísla: ", + func(a, b int) int { + return (a + b) * 2 + }(10, 2)) // Voláno s parametry 10 a 2 + // => Sečti a vynásob dvě čísla. 24 + + // Když to potřebujete, tak to milujete + goto miluji +miluji: + + naučteSeFunkčníFactory() // funkce vracející funkce je zábava(3)(3) + naučteSeDefer() // malá zajížďka k důležitému klíčovému slovu. + naučteSeInterfacy() // Přichází dobré věci! +} + +func naučteSeFunkčníFactory() { + // Následující dvě varianty jsou stejné, ale ta druhá je praktičtější + fmt.Println(větaFactory("létní")("Hezký", "den!")) + + d := větaFactory("letní") + fmt.Println(d("Hezký", "den!")) + fmt.Println(d("Líný", "odpoledne!")) +} + +// Dekorátory jsou běžné v jiných jazycích. To samé můžete udělat v Go +// pomocí parameterizovatelných funkčních literátů. +func větaFactory(můjŘetězec string) func(před, po string) string { + return func(před, po string) string { + return fmt.Sprintf("%s %s %s", před, můjŘetězec, po) // nový řetězec + } +} + +func naučteSeDefer() (ok bool) { + // Odloží (defer) příkazy na okamžik těsně před opuštěním funkce. + // tedy poslední se provede první + defer fmt.Println("odložené příkazy jsou zpravovaná v LIFO pořadí.") + defer fmt.Println("\nProto je tato řádka vytištěna první") + // Defer se běžně používá k zavírání souborů a tím se zajistí, že soubor + // bude po ukončení funkce zavřen. + return true +} + +// definuje typ interfacu s jednou metodou String() +type Stringer interface { + String() string +} + +// Definuje pár jako strukturu se dvěma poli typu int x a y. +type pár struct { + x, y int +} + +// Definuje method pár. Pár tedy implementuje interface Stringer. +func (p pár) String() string { // p je tu nazýváno "Receiver" - přijímač + // Sprintf je další veřejná funkce z balíčku fmt. + // Pomocí tečky přistupujeme k polím proměnné p + return fmt.Sprintf("(%d, %d)", p.x, p.y) +} + +func naučteSeInterfacy() { + // Složené závorky jsou "strukturální literáty. Vyhodnotí a inicializuje + // strukturu. Syntaxe := deklaruje a inicializuje strukturu. + p := pár{3, 4} + fmt.Println(p.String()) // Volá metodu String na p typu pár. + var i Stringer // Deklaruje i jako proměnné typu Stringer. + i = p // Toto je možné, jelikož oba implementují Stringer + // zavolá metodu String(( typu Stringer a vytiskne to samé jako předchozí. + fmt.Println(i.String()) + + // Funkce ve balíčku fmt volají metodu String, když zjišťují, jak se má typ + // vytisknout. + fmt.Println(p) // Vytiskne to samé, jelikož Println volá String(). + fmt.Println(i) // Ten samý výstup. + + naučSeVariabilníParametry("super", "učit se", "tady!") +} + +// Funcke mohou mít proměnlivé množství parametrů. +func naučSeVariabilníParametry(mojeŘetězce ...interface{}) { + // Iterujeme přes všechny parametry + // Potržítku tu slouží k ignorování indexu v poli. + for _, param := range mojeŘetězce { + fmt.Println("parameter:", param) + } + + // Použít variadický parametr jako variadický parametr, nikoliv pole. + fmt.Println("parametery:", fmt.Sprintln(mojeŘetězce...)) + + naučSeOšetřovatChyby() +} + +func naučSeOšetřovatChyby() { + // ", ok" je metodou na zjištění, jestli něco fungovalo, nebo ne. + m := map[int]string{3: "tri", 4: "ctyri"} + if x, ok := m[1]; !ok { // ok bude false, jelikož 1 není v mapě. + fmt.Println("není tu jedna") + } else { + fmt.Print(x) // x by bylo tou hodnotou, pokud by bylo v mapě. + } + // hodnota error není jen znamením OK, ale může říct více o chybě. + if _, err := strconv.Atoi("ne-int"); err != nil { // _ hodnotu zahodíme + // vytiskne 'strconv.ParseInt: parsing "non-int": invalid syntax' + fmt.Println(err) + } + // Znovu si povíme o interfacech, zatím se podíváme na + naučSeKonkurenčnost() +} + +// c je kanál, způsob, jak bezpečně komunikovat v konkurenčním prostředí. +func zvyš(i int, c chan int) { + c <- i + 1 // <- znamená "pošli" a posílá data do kanálu na levé straně. +} + +// Použijeme funkci zvyš a konkurečně budeme zvyšovat čísla. +func naučSeKonkurenčnost() { + // funkci make jsme již použili na slicy. make alokuje a inicializuje slidy, + // mapy a kanály. + c := make(chan int) + // nastartuj tři konkurenční go-rutiny. Čísla se budou zvyšovat + // pravděpodobně paralelně pokud je počítač takto nakonfigurován. + // Všechny tři zapisují do toho samého kanálu. + go zvyš(0, c) // go je výraz pro start nové go-rutiny. + go zvyš(10, c) + go zvyš(-805, c) + // Přečteme si tři výsledky a vytiskeneme je.. + // Nemůžeme říct, v jakém pořadí výsledky přijdou! + fmt.Println(<-c, <-c, <-c) // pokud je kanál na pravo, jedná se o "přijmi". + + cs := make(chan string) // Další kanál, tentokrát pro řetězce. + ccs := make(chan chan string) // Kanál kanálu řetězců. + go func() { c <- 84 }() // Start nové go-rutiny na posílání hodnot. + go func() { cs <- "wordy" }() // To samé s cs. + // Select má syntaxi jako switch, ale vztahuje se k operacím nad kanály. + // Náhodně vybere jeden case, který je připraven na komunikaci. + select { + case i := <-c: // Přijatá hodnota může být přiřazena proměnné. + fmt.Printf("je to typ %T", i) + case <-cs: // nebo může být zahozena + fmt.Println("je to řetězec") + case <-ccs: // prázdný kanál, nepřipraven ke komunikaci. + fmt.Println("to se nestane.") + } + // V tomto okamžiku máme hodnotu buď z kanálu c nabo cs. Jedna nebo druhá + // nastartovaná go-rutina skončila a další zůstane blokovaná. + + naučSeProgramovatWeb() // Go to umí. A vy to chcete taky. +} + +// jen jedna funkce z balíčku http spustí web server. +func naučSeProgramovatWeb() { + + // První parametr ListenAndServe je TCP adresa, kde poslouchat. + // Druhý parametr je handler, implementující interace http.Handler. + go func() { + err := http.ListenAndServe(":8080", pár{}) + fmt.Println(err) // neignoruj chyby + }() + + requestServer() +} + +// Umožní typ pár stát se http tím, že implementuje její jedinou metodu +// ServeHTTP. +func (p pár) ServeHTTP(w http.ResponseWriter, r *http.Request) { + // Servíruj data metodou http.ResponseWriter + w.Write([]byte("Naučil ses Go za y minut!")) +} + +func requestServer() { + resp, err := http.Get("http://localhost:8080") + fmt.Println(err) + defer resp.Body.Close() + body, err := ioutil.ReadAll(resp.Body) + fmt.Printf("\nWebserver řekl: `%s`", string(body)) +} +``` + +## Kam dále + +Vše hlavní o Go se nachází na [oficiálních stránkách go](http://golang.org/). +Tam najdete tutoriály, interaktivní konzolu a mnoho materiálu ke čtení. +Kromě úvodu, [dokumenty](https://golang.org/doc/) tam obsahují jak psát čistý kód v Go +popis balíčků (package), dokumentaci příkazové řádky a historii releasů. + +Také doporučujeme přečíst si definici jazyka. Je čtivá a překvapivě krátká. Tedy alespoň proti +jiným současným jazyků. + +Pokud si chcete pohrát s Go, tak navštivte [hřiště Go](https://play.golang.org/p/r46YvCu-XX). +Můžete tam spouštět programy s prohlížeče. Také můžete [https://play.golang.org](https://play.golang.org) použít jako +[REPL](https://en.wikipedia.org/wiki/Read-eval-print_loop), kde si v rychlosti vyzkoušíte věci, bez instalace Go. + +Na vašem knižním seznamu, by neměly chybět [zdrojáky stadardní knihovny](http://golang.org/src/pkg/). +Důkladně popisuje a dokumentuje Go, styl zápisu Go a Go idiomy. Pokud kliknete na [dokumentaci](http://golang.org/pkg/) +tak se podíváte na dokumentaci. + +Dalším dobrým zdrojem informací je [Go v ukázkách](https://gobyexample.com/). + +Go mobile přidává podporu pro Android a iOS. Můžete s ním psát nativní mobilní aplikace nebo knihovny, které půjdou +spustit přes Javu (pro Android), nebo Objective-C (pro iOS). Navštivte [web Go Mobile](https://github.com/golang/go/wiki/Mobile) +pro více informací. -- cgit v1.2.3 From ffba631fdd0413bbcde75d2d3791f679c7029d8e Mon Sep 17 00:00:00 2001 From: ven Date: Mon, 5 Sep 2016 22:19:48 +0200 Subject: Update go.html.markdown --- cs-cz/go.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cs-cz/go.html.markdown b/cs-cz/go.html.markdown index f814d2da..36217414 100644 --- a/cs-cz/go.html.markdown +++ b/cs-cz/go.html.markdown @@ -2,7 +2,8 @@ name: Go category: language language: Go -filename: learngo.go +filename: learngo-cs.go +lang: cs-cz contributors: - ["Sonia Keys", "https://github.com/soniakeys"] - ["Christopher Bess", "https://github.com/cbess"] @@ -13,7 +14,6 @@ contributors: - ["Clayton Walker", "https://github.com/cwalk"] translators: - ["Ondra Linek", "https://github.com/defectus/"] - --- Jazyk Go byl vytvořen, jelikož bylo potřeba dokončit práci. Není to poslední -- cgit v1.2.3 From b59e6fa07d1cd13951f9bbd54f9aaf31e0367943 Mon Sep 17 00:00:00 2001 From: Martin Pacheco Date: Tue, 6 Sep 2016 05:13:39 -0300 Subject: add new resource link (#2307) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The link is a PDF elaborated by teachers of the course "Programación 3" (Algorithms and Data Structures) with examples about calculating the order of an algorithm and other topics in the context of asymptotic notation. This material is publicly listed here: https://eva.fing.edu.uy/pluginfile.php/95278/mod_resource/content/0/Apuntes%20sobre%20An%C3%A1lisis%20de%20Algoritmos.pdf but I uploaded it to Scribd because I know that the link could eventually change since it's hosted in a moodle platform and now and then the teachers change the location of the files. --- es-es/asymptotic-notation-es.html.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/es-es/asymptotic-notation-es.html.markdown b/es-es/asymptotic-notation-es.html.markdown index f3fe1614..3507429c 100644 --- a/es-es/asymptotic-notation-es.html.markdown +++ b/es-es/asymptotic-notation-es.html.markdown @@ -168,3 +168,4 @@ definiciones y ejemplos. * [MIT](http://web.mit.edu/16.070/www/lecture/big_o.pdf) * [KhanAcademy](https://www.khanacademy.org/computing/computer-science/algorithms/asymptotic-notation/a/asymptotic-notation) +* [Apuntes Facultad de Ingeniería](https://www.scribd.com/document/317979564/Apuntes-Sobre-Analisis-de-Algoritmos) -- cgit v1.2.3 From a35179982940297bd857ceddfdc792c3ff2a73d0 Mon Sep 17 00:00:00 2001 From: Matthias Kern Date: Tue, 6 Sep 2016 10:25:45 +0200 Subject: [tmux] Updating for version 2.1 (#1733) * Update mouse option and remove old window-status-content options for tmux 2.1 compability * Add contribution and update timestamp --- tmux.html.markdown | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/tmux.html.markdown b/tmux.html.markdown index ae73d912..e39d78fc 100644 --- a/tmux.html.markdown +++ b/tmux.html.markdown @@ -3,6 +3,7 @@ category: tool tool: tmux contributors: - ["mdln", "https://github.com/mdln"] + - ["matthiaskern", "https://github.com/matthiaskern"] filename: LearnTmux.txt --- @@ -116,7 +117,7 @@ like how .vimrc or init.el are used. ``` # Example tmux.conf -# 2014.10 +# 2015.12 ### General @@ -129,7 +130,7 @@ set -g history-limit 2048 set -g base-index 1 # Mouse -set-option -g mouse-select-pane on +set-option -g -q mouse on # Force reload of config file unbind r @@ -204,8 +205,6 @@ setw -g window-status-bg black setw -g window-status-current-fg green setw -g window-status-bell-attr default setw -g window-status-bell-fg red -setw -g window-status-content-attr default -setw -g window-status-content-fg yellow setw -g window-status-activity-attr default setw -g window-status-activity-fg yellow @@ -246,6 +245,4 @@ set -g status-right "#[fg=green] | #[fg=white]#(tmux-mem-cpu-load)#[fg=green] | [Display CPU/MEM % in statusbar](https://stackoverflow.com/questions/11558907/is-there-a-better-way-to-display-cpu-usage-in-tmux) -[tmuxinator - Manage complex tmux sessions](https://github.com/tmuxinator/tmuxinator) - - +[tmuxinator - Manage complex tmux sessions](https://github.com/tmuxinator/tmuxinator) -- cgit v1.2.3 From 91c1f6b83212f6a0403ace29dde0c24021d7ebd2 Mon Sep 17 00:00:00 2001 From: ven Date: Tue, 6 Sep 2016 10:26:04 +0200 Subject: #1733 --- tmux.html.markdown | 1 - 1 file changed, 1 deletion(-) diff --git a/tmux.html.markdown b/tmux.html.markdown index e39d78fc..1214a5ba 100644 --- a/tmux.html.markdown +++ b/tmux.html.markdown @@ -3,7 +3,6 @@ category: tool tool: tmux contributors: - ["mdln", "https://github.com/mdln"] - - ["matthiaskern", "https://github.com/matthiaskern"] filename: LearnTmux.txt --- -- cgit v1.2.3 From 191019111b9c9c377ea0f4db6db845ced07fb546 Mon Sep 17 00:00:00 2001 From: IamRafy Date: Tue, 6 Sep 2016 13:56:22 +0530 Subject: Meteor Js (#1711) * Livescript is Updated * Revert "Livescript is Updated" This reverts commit 9f609e23e647abc3088fbae51551b9486531df0e. * Meteor js --- Meteor.html.markdown | 567 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 567 insertions(+) create mode 100644 Meteor.html.markdown diff --git a/Meteor.html.markdown b/Meteor.html.markdown new file mode 100644 index 00000000..d47d302b --- /dev/null +++ b/Meteor.html.markdown @@ -0,0 +1,567 @@ +--- +language: Meteor.js +Filename: Meteor.html.markdown +contributors: + - ["Mohammed Rafy", "https://github.com/IamRafy/"] + +--- + + + +Meteor is an ultra-simple environment for building modern websites. What once took weeks, even with the best tools, now takes hours with Meteor. + +The web was originally designed to work in the same way that mainframes worked in the 70s. The application server rendered a screen and sent it over the network to a dumb terminal. Whenever the user did anything, that server rerendered a whole new screen. This model served the Web well for over a decade. It gave rise to LAMP, Rails, Django, PHP. + +But the best teams, with the biggest budgets and the longest schedules, now build applications in JavaScript that run on the client. These apps have stellar interfaces. They don't reload pages. They are reactive: changes from any client immediately appear on everyone's screen. + +They've built them the hard way. Meteor makes it an order of magnitude simpler, and a lot more fun. You can build a complete application in a weekend, or a sufficiently caffeinated hackathon. No longer do you need to provision server resources, or deploy API endpoints in the cloud, or manage a database, or wrangle an ORM layer, or swap back and forth between JavaScript and Ruby, or broadcast data invalidations to clients. +Meteor Supports OS X, Windows, and Linux. // https://github.com/meteor/meteor/wiki/Supported-Platforms +On Windows? https://install.meteor.com/windows +On OS X or Linux? Install the latest official Meteor release from your terminal: +$ curl https://install.meteor.com/ | sh +The Windows installer supports Windows 7, Windows 8.1, Windows Server 2008, and Windows Server 2012. The command line installer supports Mac OS X 10.7 (Lion) and above, and Linux on x86 and x86_64 architectures. + +Once you've installed Meteor, create a project: +meteor create myapp +Run it locally: + +cd myapp +meteor +# Meteor server running on: http://localhost:3000/ + +Then, open a new terminal tab and unleash it on the world (on a free server we provide): + +meteor deploy myapp.meteor.com + +Principles of Meteor + +* Data on the Wire. Meteor doesn't send HTML over the network. The server sends data and lets the client render it. + +* One Language. Meteor lets you write both the client and the server parts of your application in JavaScript. + +* Database Everywhere. You can use the same methods to access your database from the client or the server. + +* Latency Compensation. On the client, Meteor prefetches data and simulates models to make it look like server method calls return instantly. + +* Full Stack Reactivity. In Meteor, realtime is the default. All layers, from database to template, update themselves automatically when necessary. + +* Embrace the Ecosystem. Meteor is open source and integrates with existing open source tools and frameworks. + +* Simplicity Equals Productivity. The best way to make something seem simple is to have it actually be simple. Meteor's main functionality has clean, classically beautiful APIs. + +Developer Resources +------------------- + +If anything in Meteor catches your interest, we hope you'll get involved with the project! + +TUTORIAL +Get started fast with the official Meteor tutorial! https://www.meteor.com/install + +STACK OVERFLOW +The best place to ask (and answer!) technical questions is on Stack Overflow. Be sure to add the meteor tag to your question. +http://stackoverflow.com/questions/tagged/meteor + +FORUMS +Visit the Meteor discussion forumsto announce projects, get help, talk about the community, or discuss changes to core. +https://forums.meteor.com/ + +GITHUB +The core code is on GitHub. If you're able to write code or file issues, we'd love to have your help. Please read Contributing to Meteor for how to get started. https://github.com/meteor/meteor + +THE METEOR MANUAL +In-depth articles about the core components of Meteor can be found on the Meteor Manual. The first article is about Tracker, our transparent reactivity framework. More articles (covering topics like Blaze, Unibuild, and DDP) are coming soon! http://manual.meteor.com/ + +What is Meteor? +--------------- + +Meteor is two things: + +A library of packages: pre-written, self-contained modules that you might need in your app. + +There are about a dozen core Meteor packages that most any app will use. Two examples: webapp, which handles incoming HTTP connections, and templating, which lets you make HTML templates that automatically update live as data changes. Then there are optional packages like email, which lets your app send emails, or the Meteor Accounts series (accounts-password, accounts-facebook, accounts-ui, and others) which provide a full-featured user account system that you can drop right into your app. In addition to these "core" packages, there are thousands of community-written packages in Atmosphere, one of which might do just what you need. + +A command-line tool called meteor. + +meteor is a build tool analogous to make, rake, or the non-visual parts of Visual Studio. It gathers up all of the source files and assets in your application, carries out any necessary build steps (such as compiling CoffeeScript, minifying CSS, building npm modules, or generating source maps), fetches the packages used by your app, and outputs a standalone, ready-to-run application bundle. In development mode it can do all of this interactively, so that whenever you change a file you immediately see the changes in your browser. It's super easy to use out of the box, but it's also extensible: you can add support for new languages and compilers by adding build plugin packages to your app. + +The key idea in the Meteor package system is that everything should work identically in the browser and on the server (wherever it makes sense, of course: browsers can't send email and servers can't capture mouse events). Our whole ecosystem has been built from the ground up to support this. + +Structuring your application +---------------------------- + +A Meteor application is a mix of client-side JavaScript that runs inside a web browser or PhoneGap mobile app, server-side JavaScript that runs on the Meteor server inside a Node.js container, and all the supporting HTML templates, CSS rules, and static assets. Meteor automates the packaging and transmission of these different components, and it is quite flexible about how you choose to structure those components in your file tree. + +Special Directories +------------------- + +By default, any JavaScript files in your Meteor folder are bundled and sent to the client and the server. However, the names of the files and directories inside your project can affect their load order, where they are loaded, and some other characteristics. Here is a list of file and directory names that are treated specially by Meteor: + +client + +Any directory named client is not loaded on the server. Similar to wrapping your code in if (Meteor.isClient) { ... }. All files loaded on the client are automatically concatenated and minified when in production mode. In development mode, JavaScript and CSS files are not minified, to make debugging easier. (CSS files are still combined into a single file for consistency between production and development, because changing the CSS file's URL affects how URLs in it are processed.) + +HTML files in a Meteor application are treated quite a bit differently from a server-side framework. Meteor scans all the HTML files in your directory for three top-level elements: , , and