Skip to content

Instantly share code, notes, and snippets.

View LostKobrakai's full-sized avatar

Benjamin Milde LostKobrakai

View GitHub Profile
@LostKobrakai
LostKobrakai / demo.exs
Created June 25, 2024 07:34 — forked from kevinschweikert/demo.exs
Phoenix LiveView filter toogle all problem
Mix.install([
{:phoenix_playground, git: "https://github.com/phoenix-playground/phoenix_playground"},
{:ecto, "~> 3.11"},
{:phoenix_ecto, "~> 4.6"}
])
defmodule CoreComponents do
use Phoenix.Component
attr(:id, :any)
// Courtesy of @chrismccord
let pageLoadingDone = new Promise(resolve => {
window.addEventListener("phx:page-loading-stop", _info => {
topbar.hide()
resolve()
}, {once: true})
})
window.addEventListener("phx:page-loading-start", _info => {
if(navigation.navigate){
@LostKobrakai
LostKobrakai / safe.ex
Created May 4, 2022 12:31
Phoenix.HTML.Safe implementation(s)
defimpl Phoenix.HTML.Safe, for: Version do
# Based on `to_string` implementation
# https://github.com/elixir-lang/elixir/blob/v1.13.4/lib/elixir/lib/version.ex#L629
def to_iodata(%Version{} = version) do
[
Integer.to_string(version.major),
Integer.to_string(version.minor),
[Integer.to_string(version.patch), pre(version.pre), build(version.build)]
]
|> Enum.intersperse(".")
@LostKobrakai
LostKobrakai / form_live.ex
Last active October 14, 2024 15:16
Phoenix LiveView form with nested embeds and add/delete buttons
defmodule NestedWeb.FormLive do
use NestedWeb, :live_view
require Logger
defmodule Form do
use Ecto.Schema
import Ecto.Changeset
embedded_schema do
field :name, :string
@LostKobrakai
LostKobrakai / machine.js
Last active April 30, 2021 09:46
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@LostKobrakai
LostKobrakai / machine.js
Last active May 10, 2020 13:17
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
@LostKobrakai
LostKobrakai / _test.exs
Created October 20, 2018 13:06
Ecto cast_assoc partial set
defmodule TestEctoReplace.ContextTest do
use TestEctoReplace.DataCase
alias TestEctoReplace.Context.{Country, Restaurant}
test "assoc" do
##################
# Arrange
country = Repo.insert!(%Country{name: "Germany"})
[_, _, kfc, burger_king, _] =
@LostKobrakai
LostKobrakai / phoenix_instrument.ex
Created August 9, 2018 19:34
asserting on query counts using phoenix+ecto instumentation
defmodule ConnectWeb.PhoenixInstrument do
@moduledoc """
Phoenix instrumentation to assert on the query count of controllers/views in
Phoenix.ConnCase tests.
## Installing
Before using the module there are some things to setup:
* Add `{:ok, _} = ConnectWeb.PhoenixInstrument.start_link()` to `test/test_helper.exs`.
@LostKobrakai
LostKobrakai / test_adapter.ex
Last active December 22, 2017 19:50
Swoosh TestAdapter with support for acceptance tests
defmodule MyApp.Swoosh.TestAdapter do
@moduledoc """
Integration Testable Adapter for Swoosh
## Usage
Add `{:ok, _} = MyApp.Swoosh.TestAdapter.start_link` into your
`test_helper.exs` file.
Merge with ecto metadata in the case templates, which need it.