Spaces:
Running
Running
Add smart cells livebook app
Browse files
public-apps/smart_cells.livemd
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!-- livebook:{"app_settings":{"access_type":"public","auto_shutdown_ms":3600000,"output_type":"rich","show_source":true,"slug":"livebook-smart-cells-list","zero_downtime":true}} -->
|
| 2 |
+
|
| 3 |
+
# List of Livebook Smart Cells on Github
|
| 4 |
+
|
| 5 |
+
```elixir
|
| 6 |
+
Mix.install([
|
| 7 |
+
{:kino, "~> 0.12"},
|
| 8 |
+
{:req, "~> 0.4"},
|
| 9 |
+
{:req_github_paginate, github: "acalejos/req_github_paginate"}
|
| 10 |
+
])
|
| 11 |
+
```
|
| 12 |
+
|
| 13 |
+
## Section
|
| 14 |
+
|
| 15 |
+
```elixir
|
| 16 |
+
defmodule GitHubAPI do
|
| 17 |
+
def headers(),
|
| 18 |
+
do: %{
|
| 19 |
+
"Accept" => "application/vnd.github+json",
|
| 20 |
+
"Authorization" => "Bearer #{System.fetch_env!("LB_GITHUB_TOKEN")}",
|
| 21 |
+
"X-GitHub-Api-Version" => "2022-11-28"
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
def params(),
|
| 25 |
+
do: [
|
| 26 |
+
q: "use Kino.SmartCell in:file language:elixir",
|
| 27 |
+
per_page: 100,
|
| 28 |
+
page: 1
|
| 29 |
+
]
|
| 30 |
+
|
| 31 |
+
def new() do
|
| 32 |
+
Req.new(base_url: "https://api.github.com") |> ReqGitHubPaginate.attach()
|
| 33 |
+
end
|
| 34 |
+
|
| 35 |
+
def _get_all(request, params) do
|
| 36 |
+
resp =
|
| 37 |
+
Req.get!(
|
| 38 |
+
request,
|
| 39 |
+
url: "/search/code",
|
| 40 |
+
params: params,
|
| 41 |
+
headers: headers()
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
if Keyword.has_key?(resp.headers["link"], :next) do
|
| 45 |
+
{_, params} = Map.pop(resp.headers["link"][:next], "url")
|
| 46 |
+
resp.body["items"] ++ _get_all(request, params)
|
| 47 |
+
else
|
| 48 |
+
resp.body["items"]
|
| 49 |
+
end
|
| 50 |
+
end
|
| 51 |
+
|
| 52 |
+
def get_all(request) do
|
| 53 |
+
_get_all(request, params())
|
| 54 |
+
end
|
| 55 |
+
end
|
| 56 |
+
```
|
| 57 |
+
|
| 58 |
+
```elixir
|
| 59 |
+
items = GitHubAPI.new() |> GitHubAPI.get_all()
|
| 60 |
+
nil
|
| 61 |
+
```
|
| 62 |
+
|
| 63 |
+
```elixir
|
| 64 |
+
for repo <- items, repo["repository"]["owner"]["login"] != "livebook-dev" do
|
| 65 |
+
%{
|
| 66 |
+
"Name" => repo["repository"]["name"],
|
| 67 |
+
"Description" => repo["repository"]["description"],
|
| 68 |
+
"URL" => repo["repository"]["html_url"]
|
| 69 |
+
}
|
| 70 |
+
end
|
| 71 |
+
|> Kino.DataTable.new(name: "Smart cells")
|
| 72 |
+
```
|
| 73 |
+
|
| 74 |
+
<!-- livebook:{"offset":1656,"stamp":{"token":"XCP.UQKFeTQkO9H-qhsO_ThypqbD1bal4zBCrCVmJb1odeGBZWy0CRpRuEKYQxsySyhsEHNurHX68ZQO3WXdmGn2IrQl_5LBcCztAgyKBJY11b4Cw1ksj_RS","version":2}} -->
|