Skip to content

Instantly share code, notes, and snippets.

View collegeimprovements's full-sized avatar
💭
☀️

Arpit Shah collegeimprovements

💭
☀️
View GitHub Profile
@chrismccord
chrismccord / dev.exs
Created May 8, 2024 20:06
Live Reload LiveView notify
config :wps, WPSWeb.Endpoint,
live_reload: [
notify: [
live_view: [
~r"lib/wps_web/core_components.ex$",
~r"lib/wps_web/(live|components)/.*(ex|heex)$"
]
],
patterns: [
~r"priv/static/(?!uploads/).*(js|css|png|jpeg|jpg|gif|svg)$",
@Valian
Valian / app.html.heex
Created May 2, 2024 17:34
Phoenix LiveView teleport hook
<.flash_group flash={@flash} />
<main>
<%= @inner_content %>
</main>
<%!-- We're doing teleport because navigation is rendered in root layout which is not updated --%>
<%!-- Notice "hidden" class, it's important because we're not really teleporting content, but duplicating it --%>
<div :if={@current_user} id="onboarding-render" phx-hook="teleport" data-teleport-target="onboarding" class="hidden">
<MyApp.Onboarding.onboarding current_user={@current_user} />
@mcrumm
mcrumm / component_under_test.ex
Last active May 29, 2024 21:32
Testing Phoenix.LiveComponent in Isolation
# lib/party_web/components/example_component.ex
defmodule PartyWeb.ExampleComponent do
@moduledoc """
An example LiveComponent under test.
"""
use Phoenix.LiveComponent
def render(assigns) do
~H"""
<div>
defmodule MyApp.Books.Book do
use Ecto.Schema
import Ecto.Query, warn: false
import Ecto.Changeset
import MyApp.ChangesetHelpers
schema "books" do
field :name, :string
field :genres, {:array, :string}, default: []
@mhanberg
mhanberg / ecto-guide-style.ex
Created April 29, 2022 18:04
Factores with Ecto
# example from the ecto guides https://hexdocs.pm/ecto/test-factories.html
defmodule MyApp.Factory do
alias MyApp.Repo
# Factories
def build(:post) do
%MyApp.Post{title: "hello world"}
end
@PJUllrich
PJUllrich / tasks.json
Created December 20, 2021 13:20
VSCode Tasks for running Elixir tests quickly
{
"version": "2.0.0",
"tasks": [
{
"label": "Build",
"type": "shell",
"command": "mix compile",
"problemMatcher": ["$mixCompileError", "$mixCompileWarning"],
"group": {
"kind": "build",
@PJUllrich
PJUllrich / big-o.md
Last active April 28, 2024 14:19
Big-O Time Complexities for Elixir Data Structures

Big-O Time Complexities for Elixir data structures

Map [1]

Operation Time Complexity
Access O(log n)
Search O(log n)
Insertion O(n) for <= 32 elements, O(log n) for > 32 elements [2]
Deletion O(n) for <= 32 elements, O(log n) for > 32 elements
# TODO: Extract into it's own library
defmodule AbsintheSocket do
require Logger
alias Phoenix.Channels.GenSocketClient
@behaviour GenSocketClient
@control_topic "__absinthe__:control"
defdelegate fetch(term, key), to: Map
defdelegate get(term, key, default), to: Map
@joepie91
joepie91 / no-your-cryptocurrency-cannot-work.md
Last active May 20, 2024 10:24
No, your cryptocurrency cannot work

No, your cryptocurrency cannot work

Whenever the topic of Bitcoin's energy usage comes up, there's always a flood of hastily-constructed comments by people claiming that their favourite cryptocurrency isn't like Bitcoin, that their favourite cryptocurrency is energy-efficient and scalable and whatnot.

They're wrong, and are quite possibly trying to scam you. Let's look at why.

What is a cryptocurrency anyway?

There are plenty of intricate and complex articles trying to convince you that cryptocurrencies are the future. They usually heavily use jargon and vague terms, make vague promises, and generally give you a sense that there must be something there, but you always come away from them more confused than you were before.

@gcauchon
gcauchon / !Protocol for external APIs
Last active September 8, 2023 15:47
Using protocol for external APIs
iex(1)> Foo.Correspondence.validate_number("234-555-6789")
{:ok, "Verizon Wireless", "mobile"}