View phoenix_to_umbrella
How to convert existing phoenix app to an umbrella app.
https://elixir-lang.slack.com/archives/phoenix/p1472921051000134
chrismccord [10:14 PM]
@alanpeabody yes, it's straightforward
[10:14]
1) mix new my_umbrella --umbrella
View recover_source_code.md

How to recover lost Python source code if it's still resident in-memory

I screwed up using git ("git checkout --" on the wrong file) and managed to delete the code I had just written... but it was still running in a process in a docker container. Here's how I got it back, using https://pypi.python.org/pypi/pyrasite/ and https://pypi.python.org/pypi/uncompyle6

Attach a shell to the docker container

Install GDB (needed by pyrasite)

apt-get update && apt-get install gdb
View autossh.service
[Unit]
Description=Keeps a tunnel to 'remote.example.com' open
After=network.target
[Service]
User=autossh
# -p [PORT]
# -l [user]
# -M 0 --> no monitoring
# -N Just open the connection and do nothing (not interactive)
View flatten.exs
defmodule Flat do
# [ 1 , 2, 3, [ 1, 2]]
def flatten(list) do
flatten(list, [])
end
def flatten([h|t], acc_list) when is_list(h) do
# this may be expensive!
flatten(h ++ t, acc_list)
end
View ticker.ex
# Ticker
defmodule Ticker do
use GenServer
def start_link(%{module: module, function: function, interval: interval} = state)
when is_atom(module) and is_atom(function) and is_integer(interval) and interval > 0 do
GenServer.start_link(__MODULE__, state)
end
def init(state) do
View config.ex
defmodule Config do
@moduledoc """
This module handles fetching values from the config with some additional niceties
"""
@doc """
Fetches a value from the config, or from the environment if {:system, "VAR"}
is provided.
An optional default value can be provided if desired.
View ticker.ex
defmodule Ticker do
require Logger
# public api
def start(recipient_pid, tick_interval, duration \\ :infinity) do
# Process.monitor(pid) # what to do if the process is dead before this?
# start a process whose only responsibility is to wait for the interval
ticker_pid = spawn(__MODULE__, :loop, [recipient_pid, tick_interval, 0])
# and send a tick to the recipient pid and loop back
send(ticker_pid, :send_tick)
schedule_terminate(ticker_pid, duration)
View poolboy_demo.ex
defmodule HttpRequester do
use GenServer
def start_link(_) do
GenServer.start_link(__MODULE__, nil, [])
end
def fetch(server, url) do
# Don't use cast: http://blog.elixirsips.com/2014/07/16/errata-dont-use-cast-in-a-poolboy-transaction/
timeout_ms = 10_000
View vimrc.vim
" settings
colorscheme molokai
let loaded_matchparen=1 " don't automatically highlight the matching parens
let mapleader = ' '
let maplocalleader = ' '
set autowriteall " autosave files
set background=dark
set clipboard=unnamedplus " Yanks go on clipboard
set cmdheight=2
View calc.html
<!doctype html>
<div id='output'>Output: </div>
<input type="text" id="op1" placeholder="Input 1" />
<br>
<input type="text" id="op2" placeholder="Input 2" />
<br>
<button onclick="calculate()">Add</button>