Skip to content

Instantly share code, notes, and snippets.

View lubien's full-sized avatar
💭
Teaching people 🔥🦩 LiveView 🔥🦩

Lubien lubien

💭
Teaching people 🔥🦩 LiveView 🔥🦩
View GitHub Profile
#!/bin/bash
cleanup() {
echo "destroy your machine"
fly m destroy --force
exit 0
}
trap 'cleanup' SIGINT
@lubien
lubien / ecto_sqlite.livemd
Created April 5, 2024 12:18
ecto_sqlite livebook

Untitled notebook

Mix.install([
  {:liveview_playground, "~> 0.1.8"},
  {:phoenix_ecto, "~> 4.5"},
  {:ecto, "~> 3.11"},
  {:ecto_sqlite3, "~> 0.13"}
])
Mix.install([
{:liveview_playground, "~> 0.1.1"}
])
defmodule PageLive do
use LiveviewPlaygroundWeb, :live_view
def mount(_params, _session, socket) do
socket = assign(socket, tab: "home")
{:ok, socket}
defmodule MarkdownConverter do
import Phoenix.Component
def convert(filepath, body, _attrs, opts) do
convert_body(Path.extname(filepath), body, opts)
end
defp convert_body(extname, body, opts) when extname in [".md", ".markdown", ".livemd"] do
html =
Earmark.as_ast!(body, annotations: "%%")
@doc """
Renders an input with label and error messages.
A `Phoenix.HTML.FormField` may be passed as argument,
which is used to retrieve the input name, id, and values.
Otherwise all attributes may be passed explicitly.
## Types
This function accepts all HTML input types, considering that:
async function sendMessage(bot, source, items, formatter, getUrl) {
const successfullySentIds = []
for (const item of items) {
const doSend = async () => {
await bot.telegram.sendMessage(TELEGRAM_CHANNEL, formatter(source, item), {
parse_mode: 'markdown',
})
successfullySentIds.push(item.id)
}
@lubien
lubien / switch-cameras.gd
Created January 13, 2024 06:52
godot 4.2 smooth switch between cameras
extends Node2D
var camera2D: Camera2D
var tween: Tween
func _ready():
camera2D = $Camera2D
func transition_camera2D(from: Camera2D, to: Camera2D, duration: float = 1.0) -> void:
if transitioning: return
fly machine run telegrammessenger/proxy:latest \
-p 4444:443/tcp \
--memory 1024 \
--region gru \
--env SECRET=SECRETGOESHERE \
-a APPNAME
// @ts-check
//
// The line above enables type checking for this file. Various IDEs interpret
// the @ts-check directive. It will give you helpful autocompletion when
// implementing this exercise.
const WEEK_DAYS = 7
/**
* Calculates the total bird count.
// @ts-check
//
// The line above enables type checking for this file. Various IDEs interpret
// the @ts-check directive. It will give you helpful autocompletion when
// implementing this exercise.
/**
* Determines whether or not you need a licence to operate a certain kind of vehicle.
*
* @param {string} kind