Docker getting started

一、认识Docker


ife day4: 背景边框列表链接

背景


ife day4: 背景边框列表链接

背景


ife day3: CSS基础

CSS规则


Elixir - Today I Learned

1. Elixir with macro <- and =


ife day2: HTML基本标签

1、HTML是什么,HTML5是什么


ife day1: Why?

我为什么学习前端


hook程序崩溃

##参数类型错误导致hook程序崩溃


分析block函数签名

##block结构


Elixir(1)

##Interactive mode


Learn You Some Erlang(6)

##Concurrency

  1. start new process, spawn/1

    G = fun(X) -> timer:sleep(X), io:format(“~p~n”, [X]) end. [spawn(fun(X) -> G(X) end) || X <= list:seq(1,10)].

  2. send message

    self() ! self() ! double

  3. receive message

    receive Pattern1 when Guard1 -> Expr1; Partern2 when Guard2 -> Expr2; _ -> Expr3 end.


Learn You Some Erlang(5)

Recursion

  • Fac

    fac(0) -> 1; fac(N) when N > 0 -> N*fac(N-1).

    tail_fac(N) -> tail_fac(N, 1). tail_fac(0, Fac) -> Fac; tail_fac(N, Fac) when N>0 -> tail_fac(N-1, N*Fac).

  • Len len([]) -> 0; len([_|T]) -> 1 + len(T).

    tail_len(L) -> tail_len(L,0). tail_len([], Acc) -> Acc; tail_len([_|T], Acc) -> tail_len(T,Acc+1).

Higher Order Functions

pass functions from outside a module

fun Module:Function/Arity

map(_, []) -> [];
map(F, [H|T]) -> [F(H)|map(F,T)].
incr(X) -> X + 1.
decr(X) -> X - 1.

1> c(hhfuns).
{ok, hhfuns}
2> L = [1,2,3,4,5].
[1,2,3,4,5]
3> hhfuns:increment(L).
[2,3,4,5,6]
4> hhfuns:decrement(L).
[0,1,2,3,4]
5> hhfuns:map(fun hhfuns:incr/1, L).
[2,3,4,5,6]
6> hhfuns:map(fun hhfuns:decr/1, L).
[0,1,2,3,4]

Learn You Some Erlang(4)

Bit Syntax!

Bit syntax encloses binary data between « and », splits it in readable segments, and each segment is separated by a comma.

1> Color = 16#F09A29.
15768105
2> Pixel = <<Color:24>>.
<<240,154,41>>
3> Pixels = <<213,45,132,64,76,32,76,0,0,234,32,15>>.
<<213,45,132,64,76,32,76,0,0,234,32,15>>
4> <<Pix1,Pix2,Pix3,Pix4>> = Pixels.
** exception error: no match of right hand side value 
5> <<Pix1:24, Pix2:24, Pix3:24, Pix4:24>> = Pixels.
<<213,45,132,64,76,32,76,0,0,234,32,15>>
6> <<R:8, G:8, B:8>> = <<Pix1:24>>.
<<213,45,132>>
7> R.
213

Modules

  • What are modules

Modules are a bunch of functions regrouped in a single file, under a single name. Additionally, all functions in Erlang must be defined in modules. Function defined in a module needs to be called with the form Module:Function(Arguments).

  • Module Declaration

    -module(Name). -export([Function1/Arity, Function2/Arity, …, FunctionN/Arity]). -Name(Attribute). #-compile([debug_info, export_all]).

  • Compiling the code

    $ erlc flags file.erl

Syntax in functions

  • Pattern Matching

    greet(male, Name) -> io:format(“Hello, Mr. ~s!”, [Name]); greet(female, Name) -> io:format(“Hello, Mrs. ~s!”, [Name]); greet(_, Name) -> io:format(“Hello, ~s!”, [Name]).

  • Guards

    right_age(X) when X >= 16, X =< 104 -> true; right_age(_) -> false.

    is_atom/1 is_binary/1 is_bitstring/1 is_boolean/1 is_builtin/3 is_float/1 is_function/1 is_function/2 is_integer/1 is_list/1 is_number/1 is_pid/1 is_port/1 is_record/2 is_record/3 is_reference/1 is_tuple/1

  • If

    %% note, this one would be better as a pattern match in function heads! %% I’m doing it this way for the sake of the example. help_me(Animal) -> Talk = if Animal == cat -> “meow”; Animal == beef -> “mooo”; Animal == dog -> “bark”; Animal == tree -> “bark”; true -> “fgdadfgna” end, {Animal, “says “ ++ Talk ++ “!”}.

  • Case

    beach(Temperature) -> case Temperature of {celsius, N} when N >= 20, N =< 45 -> ‘favorable’; {kelvin, N} when N >= 293, N =< 318 -> ‘scientifically favorable’; {fahrenheit, N} when N >= 68, N =< 113 -> ‘favorable in the US’; _ -> ‘avoid beach’ end.


Learn You Some Erlang(3)

Lists

Lists can contain anything! [Element1, Element2, ..., ElementN]

1> [1, 2, 3, {numbers,[4,5,6]}, 5.34, atom].
[1,2,3,{numbers,[4,5,6]},5.34,atom]

2> [97, 98, 99].
"abc"

[New] ++ [OldList]

BIFS

hd([1,2,3,4]).
tl([1,2,3,4]).
length(List).

pattern matching:

[Head|Tail].

Learn You Some Erlang(2)

Tuples

A tuple is a way to organize data. It’s a way to group togeter many terms when you known how many there are.

{Element1, Element2, ..., ElementN}

通常使用tagged tuple, 例如:

Temperature = {celsius, 23.213}.
Point = {point, {1, 2}}.

取值

{celsius, T} = Temperature.
{point, {X, _}} = Point.