Skip to content

Instantly share code, notes, and snippets.

View trestrantham's full-sized avatar

Tres Trantham trestrantham

View GitHub Profile
@trestrantham
trestrantham / sliding_session_timeout.ex
Created July 18, 2023 15:33 — forked from qertoip/sliding_session_timeout.ex
Elixir / Phoenix Sliding Session Timeout Plug
# How to use it:
#
# Plug it at the end of your :browser pipeline in your Phoenix app router.ex
# Make sure it is plugged before your session-based authentication and authorization Plugs.
#
# pipeline :browser do
# plug :accepts, ["html"]
# plug :fetch_session
# plug :fetch_flash
# plug :put_secure_browser_headers

Using Elixir releases and multi-stage Docker files to simplify Phoenix deployment

This repo is my experiment in deploying a basic Phoenix app using the release feature from elixir 1.9 (https://elixir-lang.org/blog/2019/06/24/elixir-v1-9-0-released/) and docker, via a multi-stage Dockerfile (https://docs.docker.com/develop/develop-images/multistage-build/) leveraging bitwalker's docker images for Elixir and Phoenix.

Step 1: Install Elixir 1.9.1 (and Erlang)

The simplest way to manage Elixir versions is to use asdf.

const https = require("https");
const KEY = "your-api-key";
const CURRENCY = "BTC";
const INTERVAL = "1h";
const PRICE = 6500;
let body = "";
let candles;

Keybase proof

I hereby claim:

  • I am trestrantham on github.
  • I am tres (https://keybase.io/tres) on keybase.
  • I have a public key whose fingerprint is CF61 23F0 DB20 C82E 1530 7F15 1CC0 F49A B401 88BA

To claim this, I am signing this object:

#!/usr/bin/env ruby
# -*- mode: ruby; coding: utf-8 -*-
require 'opencv'
require 'benchmark'
require "pry"
include OpenCV
def compare_surf_descriptors(d1, d2, best, length)
@trestrantham
trestrantham / periodic_task.ex
Created January 27, 2016 05:19
Run a task periodically natively in Elixir
defmodule MyApp.Periodically do
use GenServer
def start_link do
GenServer.start_link(__MODULE__, %{})
end
def init(state) do
Process.send_after(self(), :work, 2 * 60 * 60 * 1000) # In 2 hours
{:ok, state}
@trestrantham
trestrantham / gist:c9abeec38e4f86154f65
Last active August 29, 2015 14:15
Phoenix integration testing
defmodule IntegrationTest do
use ExUnit.Case
use TucoTuco.DSL
setup_all do
{:ok, _} = TucoTuco.start_session :test_browser, :test_session, :phantomjs
host = Integration.Endpoint.config(:url)[:host]
port = Integration.Endpoint.config(:http)[:port]
{:ok, manager} = GenEvent.start_link
stream = GenEvent.stream(manager, [mode: :async])
pid1 = spawn_link fn ->
for x <- stream do
IO.puts "pid1 -> sleeping for 1 second then inspecting"
:timer.sleep(1000)
IO.inspect(x)
end
end
defmodule Test do
Module.register_attribute __MODULE__, :config, accumulate: true, persist: false
@before_compile __MODULE__
defmacro __before_compile__(_) do
quote do
Module.put_attribute(__MODULE__, :config, { :foo, "foo" })
end
end
football (master *) → mix deps.get
* Updating excoveralls (git://github.com/parroty/excoveralls.git)
* Updating cesso (git://github.com/meh/cesso.git)
Running dependency resolution
Unlocked: ecto, exprintf, jsex, postgrex
Dependency resolution completed successfully
jsx: v2.0.4
poolboy: v1.2.1
ecto: v0.2.1
exprintf: v0.1.2