Spaces:
Running
Running
<!-- 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}} --> | |