This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Arrays; | |
| import java.util.List; | |
| import java.util.stream.Collectors; | |
| class Main { | |
| public static void main(String[] args) { | |
| List<Integer> list = Arrays.asList(3, 4, 6, 12, 20); | |
| List<Integer> ket_qua = list.stream() | |
| .filter(num -> { | |
| System.out.println(String.format("Gia tri cua num: %s", num)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Arrays; | |
| import java.util.List; | |
| class Main { | |
| public static void main(String[] args) { | |
| // Creating a list of Integers | |
| List<Integer> list = Arrays.asList(3, 4, 6, 12, 20); | |
| list.stream() | |
| .filter(num -> true) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // *********** START DE QUY ************** | |
| // | |
| // tuong tuong co nhieu ham add | |
| // | |
| // function add(number){ | |
| // if(number <= 0) { | |
| // return 0; | |
| // } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let age = 12 | |
| let value = `age` | |
| let value = `${age}` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| irb(main):005:0> (1..5).include?(5) #=> true | |
| => true | |
| irb(main):006:0> (1...5).include?(5) #=> false | |
| => false | |
| irb(main):007:0> 1.upto(5).include?(5) | |
| => true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # =begin | |
| # Mã vạch (ISBN-10) là 1 chuỗi gồm 9 chữ số (0-9) và 1 ký tự kiểm tra (ký tự này có thể là 1 chữ | |
| # số hoặc chữ X). Trường hợp ký tự kiểm tra là X thì nó có giá trị bằng 10. | |
| # Các ký tự có thể nối với nhau bằng dấu gạch nối '-', hoặc không có gạch nối. | |
| # VD: 3-598-21508-8, 3-598-21507-X, 3598215088 | |
| # Kiểm tra tính hợp lệ của mã vạch bằng công thức: | |
| # (x1 * 10 + x2 * 9 + x3 * 8 + x4 * 7 + x5 * 6 + x6 * 5 + x7 * 4 + x8 * 3 + x9 * 2 + x10 * 1) mod 11 == 0 | |
| # Bằng 0 thì hợp lệ. Trong đó x1->x10 lần lượt là các số từ trái sang phải (không bao gồm gạch nối) | |
| # VD mã vạch 3-598-21508-8 hợp lệ vì | |
| # (3 * 10 + 5 * 9 + 9 * 8 + 8 * 7 + 2 * 6 + 1 * 5 + 5 * 4 + 0 * 3 + 8 * 2 + 8 * 1) mod 11 == 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| irb(main):015:0> ["1",2,3,4,5].select {|val| val.is_a? Numeric } | |
| => [2, 3, 4, 5] | |
| irb(main):016:0> ["X","-",3,4,5].select {|val| val.is_a? Numeric or val == "X"} | |
| => ["X", 3, 4, 5] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| dfdfdfd |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # inside an ecto Schema, adding this: | |
| defimpl Jason.Encoder, for: [__MODULE__] do | |
| def encode(struct, opts) do | |
| Enum.reduce(Map.from_struct(struct), %{}, fn | |
| ({k, %Ecto.Association.NotLoaded{}}, acc) -> acc | |
| ({k, v}, acc) -> Map.reject(acc, fn {k, v} -> k === :__meta__ end) |> Map.put(k, v) | |
| end) | |
| |> Jason.Encode.map(opts) | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // To install these snippets, select "User Snippets" under "File > | |
| // Preferences" ("Code > Preferences" on macOS), and then select | |
| // elixir.json. Paste the snippets below into that file. If you already | |
| // have snippets in that file, you'll need to put all the snippets in one | |
| // top-level JavaScript object, so remove the outer braces in the code | |
| // below. | |
| // | |
| // JSON doesn't allow comments, so you must remove these comment lines! :-) | |
| // |