diff --git a/awesome-redux.md b/awesome-redux.md index ed1aad02f..3c9287c51 100644 --- a/awesome-redux.md +++ b/awesome-redux.md @@ -45,8 +45,8 @@ re = reduceReducers( re(10, { number: 2 }) //=> 14 ``` -### [redux-batched-updates](https://www.npmjs.com/package/redux-batched-updates) -Batch React updates that occur as a result of Redux dispatches. Uses `react/addons` (v0.12+). Debounces dispatch() calls. +### [redux-logger](https://github.com/evgenyrodionov/redux-logger) +Logs actions to your console. Async ----- diff --git a/elixir.md b/elixir.md index d1ba048a1..93f969b7b 100644 --- a/elixir.md +++ b/elixir.md @@ -56,72 +56,12 @@ left <> right # concat string/binary left =~ right # regexp ``` -### Numbers - -``` -abs(n) -rem(a, b) # remainder (modulo) -div(a, b) # integer division -round(n) -``` - -### Functions - -``` -apply(fn, args) -apply(module, fn, args) -``` - ### Inspecting ```elixir inspect(arg, opts \\ []) ``` -### Tuples - -```elixir -elem(tuple, 1) # like tuple[1] -put_elem(tuple, index, value) -tuple_size(tuple) -``` - -## Maps - -```elixir -import Map - -map = %{a: "Apple"} # atom keys (:a) -map = %{"a" => "Apple"} # string keys ("a") - -map = %{map | a: "Atis"} # key must exist - -map[:a] -map.a # same -``` - -### Updating - -```elixir -put(map, :b, "Banana") -merge(map, %{b: "Banana"}) -update(map, :a, &(&1 + 1)) -update(map, :a, fun a -> a + 1 end) -{old, new} = get_and_update(map, :a, &(&1 || "default")) - - -# Deep functions (_in) -put_in(map, [:b, :c], "Banana") -put_in(map[:b][:c], "Banana") # via macros -get_and_update_in(users, ["john", :age], &{&1, &1 + 1}) -``` - -### Reading - -``` -Map.keys(map) -``` - ## String ```elixir @@ -135,6 +75,15 @@ str |> capitalize() #=> "Hello" str |> match(regex) ``` +## Numbers + +```elixir +abs(n) +rem(a, b) # remainder (modulo) +div(a, b) # integer division +round(n) +``` + ### Float ```elixir @@ -178,33 +127,64 @@ Float.to_string(34.1) #=> "3.4100e+01" Float.to_string(34.1, [decimals: 2, compact: true]) #=> "34.1" ``` -### Map +## Map -```js +```elixir +map = %{name: "hi"} # atom keys (:name) +map = %{"name" => "hi"} # string keys ("name") +``` + +### Updating +```elixir import Map -map = %{id: 1, name: "hi"} -delete(map, :name) #=> "hi" -pop(map, :name) #=> %{id: 1} +map = %{map | name: "yo"} # key must exist put(map, :id, 2) #=> %{id: 2, name: "hi"} -put_new(map, :id, 2) # only if `id` doesn't exist +put_new(map, :id, 2) # only if `id` doesn't exist (`||=`) +put(map, :b, "Banana") +merge(map, %{b: "Banana"}) +update(map, :a, &(&1 + 1)) +update(map, :a, fun a -> a + 1 end) + +{old, new} = get_and_update(map, :a, &(&1 || "default")) +``` + +### Deleting +```elixir +delete(map, :name) #=> "hi" +pop(map, :name) #=> %{id: 1} +``` + +### Reading + +```elixir get(map, :id) #=> 1 keys(map) #=> [:id, :name] values(map) #=> [1, "hi"] to_list(map) #=> [id: 1, name: "hi"] #=> [{:id, 1}, {:name, "hi"}] +``` -merge(map, %{name: "hello"}) +### Deep +```elixir +put_in(map, [:b, :c], "Banana") +put_in(map[:b][:c], "Banana") # via macros +get_and_update_in(users, ["john", :age], &{&1, &1 + 1}) +``` + +### Constructing + +```elixir Map.new([{:b, 1}, {:a, 2}]) Map.new([a: 1, b: 2]) Map.new([:a, :b], fn x -> {x, x} end) #=> %{a: :a, b: :b} ``` -### List +## List Also see [Enum](#enum). @@ -220,7 +200,7 @@ flatten(list) flatten(list, tail) ``` -### Enum +## Enum ```elixir # consider streams instead @@ -242,7 +222,48 @@ any?(list) #=> true concat(list, [:d]) #=> [:d] ``` -There's really way too many things, just see . +## Tuples + +```elixir +tuple = { :a, :b } + +elem(tuple, 1) # like tuple[1] +put_elem(tuple, index, value) +tuple_size(tuple) +``` + +### Keyword lists + +```elixir +list = [{ :name, "John" }, { :age, 15 }] +list.name +``` + +## Functions + +### Lambdas + +```elixir +square = fn n -> n*n end +square.(20) +``` + +### & syntax + +```elixir +square = &(&1 * &1) +square.(20) + +square = &Math.square/1 +``` + +### Running + +```elixir +fun.(args) +apply(fun, args) +apply(module, fun, args) +``` ## Syntax @@ -264,8 +285,8 @@ end ```elixir def join(a, b \\ nil) -def join(a, b) when is_nil(b) do: a end -def join(a, b) do: a <> b; end +def join(a, b) when is_nil(b) do: a +def join(a, b) do: a <> b ``` ## Protocols @@ -326,7 +347,7 @@ for dir <- dirs, file <- File.ls!(dir), # nested comprehension path = Path.join(dir, file), # invoked File.regular?(path) do # condition - IO.puts(file, + IO.puts(file) end ``` @@ -400,3 +421,8 @@ end ``` [Reference](http://elixir-lang.org/docs/stable/elixir/Module.html) + +## References + +- [Learn Elixir in Y minutes](https://learnxinyminutes.com/docs/elixir/) + diff --git a/js-fetch.md b/js-fetch.md new file mode 100644 index 000000000..93b90d7e9 --- /dev/null +++ b/js-fetch.md @@ -0,0 +1,55 @@ +--- +title: fetch() +category: JavaScript +--- + +```js +fetch('/data.json') + .then(response => response.json()) + .catch(err => ...) +``` + +### Response + +```js +fetch('/data.json') +.then(res => { + res.text() // response body + res.json() // parse via JSON + res.status //=> 200 + res.statusText //=> 'OK' + res.redirected //=> false + res.ok //=> true + res.url //=> 'http://site.com/data.json' + res.type //=> 'basic' ('cors' 'default' 'error' 'opaque' 'opaqueredirect') + + res.headers.get('Content-Type') +}) +``` + +### Request options + +```js +fetch('/data.json', { + method: 'post', + body: new FormData(form), // post body + body: JSON.stringify(...), + + headers: { + 'Accept': 'application/json' + } +}) +``` + +## + +## Using with node.js + +```js +var fetch = require('isomorphic-fetch') +``` + +## References + +- +- diff --git a/phoenix-conn.md b/phoenix-conn.md index ec6d154d9..be84ca6f0 100644 --- a/phoenix-conn.md +++ b/phoenix-conn.md @@ -13,8 +13,8 @@ conn.request_path #=> "/posts/1" conn.query_string #=> "utm_source=twitter" conn.port #=> 80 conn.scheme #=> :http -conn.peer #=> {{127, 0, 0, 1}, 12345} -conn.remote_ip #=> {151, 236, 219, 228} +conn.peer #=> { {127, 0, 0, 1}, 12345 } +conn.remote_ip #=> { 151, 236, 219, 228 } conn.req_headers #=> [{"content-type", "text/plain"}] ```