Skip to content

Instantly share code, notes, and snippets.

View benvp's full-sized avatar
🤌

Benjamin von Polheim benvp

🤌
View GitHub Profile
@benvp
benvp / _paddle_script.html.eex
Last active April 18, 2024 12:52
Integrate Elixir/Phoenix with paddle.com -> See https://twitter.com/benvp_/status/1617624545791205379
<script src="https://cdn.paddle.com/paddle/paddle.js"></script>
<%= if vendor_id = Application.get_env(:my_app, :paddle)[:vendor_id] do %>
<%= if Application.get_env(:my_app, :paddle)[:sandbox] do %>
<script type="text/javascript">
Paddle.Environment.set("sandbox");
Paddle.Setup({ vendor: <%= vendor_id %> });
</script>
<% else %>
<script type="text/javascript">
@benvp
benvp / recompile-elixir-ls
Last active November 9, 2023 14:21
recompile elixirls
#!/bin/zsh
#
# Little script to recompile ElixirLS with the current elixir version.
default_version=0.14.5
version=$1 || $default_version
elixir_ls_dir=/tmp/elixir_ls
set -e
@benvp
benvp / KeyBuffer.ts
Created November 16, 2022 12:56
LiveView Shortcuts
/**
* Allows for recording a sequence of keys pressed
* and matching against that sequence.
*
* Taken from the livebook repo and adapted a little bit.
*/
export class KeyBuffer {
private resetTimeout: number;
private buffer: string[] = [];
private resetTimeoutId: number | null = null;
@benvp
benvp / notion.ex
Created December 23, 2021 05:34
Notion HTTP client
defmodule Benvp.Notion.Client.HTTP do
alias Benvp.Notion.Schema
alias Benvp.Notion.Parser
@base_url "https://api.notion.com/v1"
@notion_version "2021-08-16"
def get_page(id) do
case get(@base_url <> "/pages/#{id}") do
{:ok, %Finch.Response{status: 200} = res} ->
<script>
function autocomplete() {
return {
// ...
select() {
this.$refs[`item-${this.focus}`]?.click();
this.focusPrev();
},
<script>
function autocomplete() {
return {
// ...
scrollTo(idx) {
this.$refs[`item-${idx}`]?.scrollIntoView(false);
},
focusNext() {
const nextIndex = this.focus + 1;
<script>
function autocomplete() {
return {
// ...
focus: 0,
setFocus(f) {
this.focus = f;
},
// ...
def handle_event("submit", params, socket), do: {:noreply, socket}
def handle_event("select", %{"id" => id}, socket) do
item = Items.get_item(id)
selected = Enum.uniq_by([item] ++ socket.assigns.selected, & &1.id)
suggestions = filter_selected(socket.assigns.suggestions, selected)
socket =
assign(socket,
selected: selected,
suggestions: suggestions
)
def handle_event("suggest", %{"search" => search}, socket) do
suggestions = Items.list_items() |> suggest(search)
{:noreply, assign(socket, suggestions: suggestions)}
end
defp suggest(items, search) do
Enum.filter(items, fn i ->
i.name
|> String.downcase()