Skip to content

Instantly share code, notes, and snippets.

View nshafer's full-sized avatar

Nathan Shafer nshafer

View GitHub Profile
@nshafer
nshafer / upload_live.ex
Created June 17, 2024 14:53
Process uploaded file
def handle_event("import", _params, socket) do
results =
consume_uploaded_entries(socket, :import, fn %{path: path}, _entry ->
temp_dir = Briefly.create!(type: :directory)
csv_file = Path.join(temp_dir, "import.csv")
# Attempt to create a new hard link to the file
case File.ln(path, csv_file) do
:ok ->
{:ok, csv_file}
@nshafer
nshafer / form_modal_live.ex
Created November 16, 2023 21:51
FormModalLive
defmodule Default1710Web.FormModalLive do
use Default1710Web, :live_view
def render(assigns) do
~H"""
<.live_component module={Default1710Web.InnerForm} id="form" />
<button phx-click="open_modal">Open Modal</button>
<.modal :if={@show_modal} id="modal" show on_cancel={JS.push("close_modal")}>
@nshafer
nshafer / adlist.json
Created October 9, 2023 17:43
Pihole lists
[
{
"id": 1,
"address": "https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts",
"enabled": 1,
"date_added": 1589393137,
"date_modified": 1678635720,
"comment": "Migrated from /etc/pihole/adlists.list",
"date_updated": 1696765562,
"number": 137890,
@nshafer
nshafer / gist:8e12aa557cc91c6b16a6057e83e4741e
Created September 1, 2022 15:29
New allowed wordle words 8/29
aapas
abaht
abeat
abeer
abeng
abeys
abius
abjad
abjud
abnet
@nshafer
nshafer / custom_workon.sh
Last active July 14, 2022 16:27
Extend the virtualenvwrapper's `workon` command with other non-python project directories
#!/bin/bash
# Extend the `workon` command to include just random directories to CD into without activating
# a virtualenv.
#
# Source into .bashrc or .bash_profile
#
# source ~/custom_workon.sh
declare -A projects
@nshafer
nshafer / admin.py
Created August 30, 2019 21:32
Session Admin for debugging
from django.contrib.sessions.models import Session
class SessionAdmin(admin.ModelAdmin):
list_display = ('session_key', 'decoded_session_data', 'expire_date')
readonly_fields = ('decoded_session_data',)
exclude = ('session_data',)
ordering = ('expire_date',)
search_fields = ('session_key',)
def decoded_session_data(self, obj):