Skip to content

Instantly share code, notes, and snippets.

// 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 May 29, 2024 10:44
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.