Skip to content

Instantly share code, notes, and snippets.

View damonvjanis's full-sized avatar

Damon Janis damonvjanis

  • GridPoint
  • St. George, UT
View GitHub Profile
@damonvjanis
damonvjanis / oban_test_example.ex
Created October 12, 2023 20:18
Oban batching slow test example
# my_app.ex
defmodule MyApp do
alias MyApp.Jobs.TestJob
def test_work(use_batch?) do
1..100
|> Enum.map(fn i -> %{job_number: i} end)
|> then(fn args_list ->
if use_batch? do
TestJob.new_batch(args_list, batch_callback_args: %{batch: :my_batch})
@damonvjanis
damonvjanis / throw_benchmark.exs
Last active October 21, 2021 13:14
Profiles a function that throws vs one that returns
Mix.install([:benchee])
defmodule Profile do
def function_that_throws(input) do
throw(input)
catch
value -> value
end
def function_that_returns(input) do
#!/bin/bash
set -e
# Navigate to app directory
cd /home/<YOUR_USERNAME>/my_app
# Find the current release and the second newest release
current_release=$(ls ../releases | sort -nr | head -n 1)
previous_release=$(ls ../releases | sort -nr | tail -n +2 | head -n 1)
...
config :my_app, MyAppWeb.Endpoint,
url: [host: "<YOUR_DOMAIN.COM>", port: 443],
cache_static_manifest: "priv/static/cache_manifest.json",
server: true,
force_ssl: [hsts: true],
http: [port: 4000, transport_options: [socket_opts: [:inet6]]],
https: [
port: 4040,
import Config
# Set ports based on environment variables in the release
http_port = System.get_env("HTTP_PORT")
https_port = System.get_env("HTTPS_PORT")
if http_port && https_port do
config :my_app, MyAppWeb.Endpoint,
http: [port: String.to_integer(http_port)],
https: [port: String.to_integer(https_port)]
[Unit]
Description=My App
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=1
User=<YOUR_USERNAME>
#!/bin/bash
set -e
# Update to latest version of code
cd /home/<YOUR_USERNAME>/my_app
git fetch
git reset --hard origin/main
mix deps.get --only prod
# Optional CI steps
defmodule MyAppWeb.Endpoint do
# All the stuff we just added
@session_options ...
socket ...
def www_redirect(conn, _options) do
if String.starts_with?(conn.host, "www.#{host()}") do
conn
|> Phoenix.Controller.redirect(external: "https://#{host()}")
import Config
config :my_app, MyApp.Repo,
username: "postgres",
password: "<the random password you generated>",
database: "my_app",
hostname: "localhost",
pool_size: 10
config :my_app, MyAppWeb.Endpoint,
defmodule MyAppWeb.Endpoint do
use Phoenix.Endpoint, otp_app: :my_app
use SiteEncrypt.Phoenix
@impl Phoenix.Endpoint
def init(_key, config) do
{:ok, SiteEncrypt.Phoenix.configure_https(config)}
end
@impl SiteEncrypt