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
#!/bin/bash
## This script will observe a directory and compress/optimize .png and .jpg files
## Created to optimize incoming images on ubuntu / aws server
## jpegoptim, jpgcompress, pngquant and inotify-tools
## 2016 Jason Clark (mithereal@gmail.com)
DIRECTORY_TO_OBSERVE="/var/www/html/image/cache"
@mithereal
mithereal / Git-precommit-hook-mysqldump
Last active April 14, 2021 00:12 — forked from wilcollins/Git-precommit-hook-mysqldump
Git pre-commit hook for MySQL database backup ( remote mysqldump + Git push )
#!/bin/bash -e
# -e means exit if any command fails
DBHOST=address.to.your.server
DBUSER=username
DBPASS=password # do this in a more secure fashion
DBNAME=DBNAME
GITREPO=/where/is/your/repo
DUMP=$GITREPO/where/you/store/dumps
NEW=$DUMP/schema.sql
OLD=$NEW.old
@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 / 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 / .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 / tile38.service
Created October 12, 2017 16:48
tile38 systemd script
[Unit]
Description=Advanced Geolocation store
After=network.target
Documentation=http://tile38.com/documentation/, man:redis-server(1)
[Service]
Type=forking
ExecStart=/srv/geodb/tile38-server
PIDFile=/var/run/tile38/tile38-server.pid
TimeoutStopSec=0
@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