Skip to content

Instantly share code, notes, and snippets.

@mithereal
mithereal / n2lbr.ex
Created November 11, 2022 01:03
php n2lbr implemented in elixir
defmodule n2lbr do
@doc """
Replace newlines with <br />.
## Examples
iex> Nl2br('abc\ndef')
"abc<br/>def"
"""
@mithereal
mithereal / .iex.exs
Last active May 5, 2022 16:41
My customized iex console
alias :observer, as: O
alias :debugger, as: D
local_time = fn ->
{_date, {hour, minute, _second}} = :calendar.local_time()
hour =
case(hour > 12) do
true -> hour - 12
false -> hour
@mithereal
mithereal / api_web.ex
Created March 14, 2021 20:01
phoenix liveview helpers
defmodule ApiWeb do
@moduledoc """
The entrypoint for defining your web interface, such
as controllers, views, channels and so on.
This can be used in your application as:
use ApiWeb, :controller
use ApiWeb, :view
@mithereal
mithereal / .Metrics.AudioConversionsLive.ex
Created February 27, 2020 17:02
liveview that is failing
defmodule ApiWeb.Metrics.AudioConversionsLive do
use Phoenix.LiveView
use ApiWeb.Live.AuthHelper, otp_app: :api
alias Api.Audio.File.Conversions
alias Phoenix.LiveView.Socket
def mount(%{"id" => id}, session, socket) do
socket = maybe_mount_user(socket, session)
defmodule AudioConverter.Conversion.Server do
use GenServer
require Logger
@lock_interval_seconds 10000
defstruct(
filesize: [],
source: nil,
destination: nil
@mithereal
mithereal / gist:464c3d4ed880b522d660ce471274d0b0
Created June 7, 2019 20:27
semantic versioning for elixir apps
---
id: 7
title: "A simple way to automatically set the semantic version of your Elixir app"
date: 2019-06-07T07:47:32Z
layout: default
tags:
- elixir
- Phoenix
- Semver
- Version
@mithereal
mithereal / Makefile
Created March 26, 2019 18:51 — forked from xenogenesi/Makefile
create self signed certificates
DOMAIN ?= mydomain.com
COUNTRY := IT
STATE := IT
COMPANY := Evil Corp.
# credits to: https://gist.github.com/fntlnz/cf14feb5a46b2eda428e000157447309
# usage:
@mithereal
mithereal / phx_run.sh
Last active December 1, 2018 23:56
elixir phoenix init script for restarting from shell with ssl key generation and db reset
#!/bin/bash
## place in the app root ie /
echo "This will reinit the db, create ssl keys and the main website"
PLATFORM_DIRECTORY=$(pwd)
PHOENIX_DIRECTORY="apps/api"
DB_DIRECTORY="apps/db"
type location = {
street_number: string,
route: string,
locality: string,
administrative_area_level_1: string,
country: string,
postal_code: string
}
type marshalled_location = {.
"administrative_area_level_1": string,
"country": string,
"locality": string, "postal_code": string,
"route": string,
"street_number": string
}
type input = {
key: string,