File size: 2,518 Bytes
385153a
 
 
 
 
 
 
 
 
 
 
 
 
 
0664a8c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
385153a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0664a8c
 
 
 
 
 
385153a
 
 
 
 
 
0664a8c
 
 
 
 
 
 
 
 
 
 
385153a
 
0664a8c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<!-- livebook:{"app_settings":{"access_type":"public","auto_shutdown_ms":3600000,"output_type":"rich","show_source":true,"slug":"livebook-smart-cells-list","zero_downtime":true}} -->

# List of Livebook Smart Cells on Github

```elixir
Mix.install([
  {:kino, "~> 0.12"},
  {:req, "~> 0.4"},
  {:req_github_paginate, github: "acalejos/req_github_paginate"}
])
```

## Section

```elixir
defmodule Kino.Spinner do
  def new() do
    Kino.HTML.new("""
    <div class="loader"></div>

    <style>
      .loader {
        border: 16px solid #f3f3f3; /* Light grey */
        border-top: 16px solid #3498db; /* Blue */
        border-radius: 50%;
        width: 30px;
        height: 30px;
        animation: spin 2s linear infinite;
      }

      @keyframes spin {
        0% { transform: rotate(0deg); }
        100% { transform: rotate(360deg); }
      }
    </style>
    """)
  end
end
```

```elixir
defmodule GitHubAPI do
  def headers(),
    do: %{
      "Accept" => "application/vnd.github+json",
      "Authorization" => "Bearer #{System.fetch_env!("LB_GITHUB_TOKEN")}",
      "X-GitHub-Api-Version" => "2022-11-28"
    }

  def params(),
    do: [
      q: "use Kino.SmartCell in:file language:elixir",
      per_page: 100,
      page: 1
    ]

  def new() do
    Req.new(base_url: "https://api.github.com") |> ReqGitHubPaginate.attach()
  end

  def _get_all(request, params) do
    resp =
      Req.get!(
        request,
        url: "/search/code",
        params: params,
        headers: headers()
      )

    if Keyword.has_key?(resp.headers["link"], :next) do
      {_, params} = Map.pop(resp.headers["link"][:next], "url")
      resp.body["items"] ++ _get_all(request, params)
    else
      resp.body["items"]
    end
  end

  def get_all(request) do
    _get_all(request, params())
  end
end
```

```elixir
frame = Kino.Frame.new() |> Kino.render()

Kino.Frame.append(frame, Kino.Spinner.new())
```

```elixir
items = GitHubAPI.new() |> GitHubAPI.get_all()
nil
```

```elixir
table =
  for repo <- items, repo["repository"]["owner"]["login"] != "livebook-dev" do
    %{
      "Name" => repo["repository"]["name"],
      "Description" => repo["repository"]["description"],
      "URL" => repo["repository"]["html_url"]
    }
  end
  |> Kino.DataTable.new(name: "Smart cells")

Kino.Frame.render(frame, table)
```

<!-- livebook:{"offset":2330,"stamp":{"token":"XCP.M4F9Mu9JmVN3zo1H252A6D_XZK0YF0q6oNOcG5Ddz3jQuIiKPSiqgM0qdcv3ETVMC5DzgJA0o9GSnps38eVzGwJNhy27ZAr3o9Junmz98dkNvYcBQAiJ","version":2}} -->