Skip to content

Instantly share code, notes, and snippets.

View hoangbits's full-sized avatar
🌍
Working from home

Le Gia Hoang hoangbits

🌍
Working from home
View GitHub Profile
@kieraneglin
kieraneglin / example_live_test.exs
Last active November 11, 2024 19:15
Pow sessions with LiveView (including tests)
defmodule MyAppWeb.ExampleLiveTest do
# `LiveviewCase` is a custom test helper - pretty much the same as ConnCase but with
# import Phoenix.LiveViewTest
# import MyApp.Support.AuthHelpers
use MyAppWeb.LiveviewCase, async: false
import MyApp.Factory
alias MyApp.Repo
alias MyAppWeb.ExampleLive
@nfantone
nfantone / use-validation-schema.js
Last active May 29, 2024 01:55
Use `yup` with `react-final-form`
import { setIn } from 'final-form';
import { useMemo } from 'react';
/**
* Sets the `innerError.message` in an `errors` object at the key
* defined by `innerError.path`.
* @param {Object} errors The object to set the error in.
* @param {{ path: string, message: string }} innerError A `yup` field error.
* @returns {Object} The result of setting the new error message onto `errors`.
*/
@chevinbrown
chevinbrown / layout.leex
Last active January 28, 2024 08:24
Quick toast messages from flash with LiveView
<%= if assigns[:flash] && !assigns[:skip_flash] do %>
<%= render_flash(@flash) %>
<% end %>
...
@KevinBatdorf
KevinBatdorf / add-alpine-js-to-tailwind-ui.js
Last active October 23, 2024 09:21
Auto copy the Alpine code from Tailwind UI's copy button
// ==UserScript==
// @name Add AlpineJs to Tailwind UI
// @namespace http://tampermonkey.net/
// @version 3.0
// @description Add Alpine JS code to Tailwind Ui copy/paste
// @author https://gist.github.com/KevinBatdorf/8bd5f808fff6a59e100dfa08a7431822
// @match https://tailwindui.com/components/*
// @grant none
// ==/UserScript==
@timhughes
timhughes / fastapi_websocket_redis_pubsub.py
Last active August 10, 2024 12:07
FastAPI Websocket Bidirectional Redis PubSub
"""
Usage:
Make sure that redis is running on localhost (or adjust the url)
Install uvicorn or some other asgi server https://asgi.readthedocs.io/en/latest/implementations.html
pip install -u uvicorn
Install dependencies
@bradtraversy
bradtraversy / mongodb_cheat_sheet.md
Last active November 15, 2024 10:00
MongoDB Cheat Sheet

MongoDB Cheat Sheet

Show All Databases

show dbs

Show Current Database

@carterbryden
carterbryden / AddPostgresTriggerAndFunctionForAllTables.exs
Last active August 30, 2024 19:17
Elixir Phoenix Postgresql migration to add triggers for pubsub to run on every CRUD operation on every table. If a new table is added, it'll automatically add a trigger to that table too.
defmodule MyApp.Repo.Migrations.AddPostgresTriggerAndFunctionForAllTables do
use Ecto.Migration
def up do
# Create a function that broadcasts row changes
execute "
CREATE OR REPLACE FUNCTION broadcast_changes()
RETURNS trigger AS $$
DECLARE
current_row RECORD;
@ibarchenkov
ibarchenkov / ecto_postgresql_migration.ex
Last active April 27, 2023 06:41
Ecto migration helpers for PostgreSQL.
defmodule MyApp.Migration do
@moduledoc """
Additional helpers for PostgreSQL.
"""
import Ecto.Migration, only: [execute: 2]
defmacro __using__(_) do
quote do
use Ecto.Migration