Skip to content

Instantly share code, notes, and snippets.

@harmon25
harmon25 / single_file_lv.exs
Created November 20, 2022 19:58
Single File LiveView - js navigate bug
Application.put_env(:phoenix, :json_library, Jason)
Application.put_env(:sample, SamplePhoenix.Endpoint,
http: [ip: {127, 0, 0, 1}, port: 5001],
server: true,
live_view: [signing_salt: "aaaaaaaa"],
secret_key_base: String.duplicate("a", 64)
)
Mix.install([
@harmon25
harmon25 / observable_genserver.ex
Last active October 9, 2020 19:54 — forked from methyl/observable_genserver.ex
Observable GenServer
defmodule ObservableGenServer do
defmacro __using__(opts) do
quote do
defmodule Server do
use GenServer
def start_link(n) do
GenServer.start_link(__MODULE__, n)
end
@harmon25
harmon25 / SocketContext.js
Created May 11, 2020 14:13
phoenix socket react context
import React, {createContext, useContext, useEffect, useRef, useState} from "react"
import { Socket } from "phoenix";
const SocketContext = createContext({socket: null, connected: false})
const useSocketCtx = ()=> useContext(SocketContext)
// this is what you would use in child components to get access to the socket
export const useSocket = ()=> {
const {socket} = useSocketCtx()
@harmon25
harmon25 / cli.js
Created May 10, 2020 14:38
cli.js for rendering a react component
// do this first so we can locate deps
require("@babel/polyfill");
require("@babel/register")({ cwd: __dirname });
// This interface allows you to use console.log statements in server.js (which otherwise
// interfere with the readline interface that elixir-nodejs uses)
//
// node assets/cli
// output:
// { error: null,
@harmon25
harmon25 / qt514-env.sh
Created March 29, 2020 19:16
Tweaked `qt514-env.sh` from [PPA](https://launchpad.net/~beineri) to more gracefully handle an empty `LD_LIBRARY_PATH` without adding `:`
#!/bin/bash
QT_BASE_DIR=/opt/qt514
export QTDIR=$QT_BASE_DIR
# add qt base to path
export PATH=$QT_BASE_DIR/bin:$PATH
# check arch
if [[ $(uname -m) == "x86_64" ]]; then