Skip to content

Instantly share code, notes, and snippets.

@craigp
craigp / watcher.sh
Created July 8, 2016 21:01 — forked from josevalim/watcher.sh
A 1LOC bash script for re-running tests whenever a lib/ or test/ file changes keeping the same VM instance
# You will need fswatch installed (available in homebrew and friends)
# The command below will run tests and wait until fswatch writes something.
# The --stale flag will only run stale entries, it requires Elixir v1.3.
fswatch lib/ test/ | MIX_ENV=test mix do test --stale, run --no-halt -e "IO.gets(:stdio, ''); IO.puts 'Restarting...'; :init.restart()"
@craigp
craigp / README.md
Created September 21, 2016 06:32 — forked from joakimk/README.md
CircleCI elixir build example

This runs a build for a small elixir (phoenix) project in about 40 seconds by caching as much of the compiled files as possible.

We've been using this for months in multiple projects without any issues. Please ping be if there is any issues with this script and I'll update it.

It should be generic enough to work on any elixir app using mix.

If you have a elixir_buildpack.config, then enable that section in the build script to keep versions in sync!

2016-08-09: Updated to newer Erlang and Elixir and fixed curl command.

@craigp
craigp / new_phoenix_dot_iex.exs
Created October 26, 2016 19:08 — forked from bchase/new_phoenix_dot_iex.exs
Officially tired of aliasing `Repo` and importing `Ecto.Query` by hand every IEx session
#!/usr/bin/env elixir
ecto_import = "import Ecto.Query, only: [from: 2]"
mixexs =
Path.join(["mix.exs"])
|> File.read!
namespace =
Regex.run(~r{defmodule\s+(\w+)\.}, mixexs)
@craigp
craigp / iccat.sh
Created March 8, 2017 16:06 — forked from heapwolf/iccat.sh
Download and show image in terminal (iterm2 only)
#!/bin/bash
function print_image() {
printf "\033]"
printf "1337;File="
echo -n "$1" | base64 -D | wc -c | awk '{printf "size=%d",$1}'
printf ";inline=1:"
echo -n "$1"
printf "\a\n"
}
@craigp
craigp / deprecation.md
Created May 23, 2017 14:38 — forked from KronicDeth/deprecation.md
HowTo make deprecation warnings in Elixir

TIL how to make deprecation warnings:

Compiling 2 files (.ex)
warning: `Retort.Resources.timeout/2` is deprecated; call `Retort.Resources.Timeout.get_or_default/2` instead.
  lib/retort/resources.ex:197: Retort.Resources.timeout/2

Replace function

@craigp
craigp / twitter_stream.ex
Created June 15, 2017 18:22 — forked from mgwidmann/twitter_stream.ex
Infinite Streams with Elixir
# Elixir has lazily evaluated enumerable objects that allow you
# to work with enumerable objects like lists either only as needed
# or infinitely.
# Start up iex to play around
$ iex
# Typical enumeration is done eagerly where the result is computed ASAP
iex> Enum.map(1..10, fn i -> i * 2 end)
[2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
@craigp
craigp / migrate.sh
Created June 16, 2017 06:34 — forked from gaynetdinov/migrate.sh
How to run Ecto migrations from an exrm release
$./bin/my_app rpc Elixir.Application app_dir "[my_app, <<\"/priv/repo/migrations\">>]."
<<"/home/dashboard/uss/lib/my_app-0.0.1/priv/repo/migrations">>
./bin/my_app rpc Elixir.Ecto.Migrator run "['Elixir.MyApp.Repo', <<\"/home/dashboard/uss/lib/my_app-0.0.1/priv/repo/migrations\">>, up, [{all, true}]]."
# => []
@craigp
craigp / .iex.exs
Created August 4, 2017 13:34 — forked from fertapric/.iex.exs
Prompt Mix env on IEX (with colors)
env = case System.get_env("MIX_ENV") || "dev" do
"prod" -> IO.ANSI.red() <> "prod" <> IO.ANSI.reset()
"dev" -> IO.ANSI.green() <> "dev" <> IO.ANSI.reset()
"test" -> IO.ANSI.green() <> "test" <> IO.ANSI.reset()
mix_env -> IO.ANSI.yellow() <> mix_env <> IO.ANSI.reset()
end
IEx.configure(
default_prompt: "%prefix(#{env},%counter)>",
alive_prompt: "%prefix(#{env},%node,%counter)>"
@craigp
craigp / transcode
Created May 26, 2018 18:07 — forked from datashaman/transcode
Convert audio to 320kbps CBR .mp3, convert video to x264 .mp4
#!/usr/bin/env bash
#
# Usage:
# transcode filename [filename...]
#
# File type is determined using:
#
# file --mime-type filename
#
# Audio files:
@craigp
craigp / pre_push
Created July 30, 2018 10:02 — forked from sascha-wolf/pre_push
Elixir pre-push hook for git - ensures files are formatted correctly and credo is satisfied
#!/bin/bash
ask() {
# https://djm.me/ask
local prompt default reply
while true; do
if [ "${2:-}" = "Y" ]; then
prompt="Y/n"