Skip to content

Instantly share code, notes, and snippets.

@craigp
craigp / label.ex
Last active January 21, 2016 12:06
defmodule Gmail.Label do
@moduledoc"""
Labels are used to categorize messages and threads within the user's mailbox.
"""
alias __MODULE__
import Gmail.Base
@doc """
@craigp
craigp / loader.ex
Last active January 26, 2016 11:48
defmodule Room.Loader do
use GenEvent
require Logger
def start_link(_args) do
{:ok, pid} = GenEvent.start_link(name: :room_events)
GenEvent.add_handler(:room_events, __MODULE__, [])
{:ok, pid}
end
@craigp
craigp / map.ex
Last active January 26, 2016 13:13
Enum.reduce(data, %SomeStruct{}, fn({key, value}, some_struct) ->
%{some_struct | (key |> Macro.underscore |> String.to_atom) => value}
end)
@craigp
craigp / elixir_projects.md
Last active February 12, 2016 06:13
Elixir projects
test "updates a label", %{
label: label,
label_name: label_name,
access_token_rec: access_token_rec,
expected_result: expected_result,
bypass: bypass,
label_id: label_id
} do
Bypass.expect bypass, fn conn ->
{:ok, body, _} = Plug.Conn.read_body(conn)
@craigp
craigp / gist:9276fb009d45670013a6
Last active February 29, 2016 13:54
Configuring tsc for typescript in vim (from https://github.com/benekastah/neomake/issues/244)

@HerringtonDarkholme I had forgotten about this issue. I had resolved it by doing exactly as you suggested, reading the docs ;)

For anyone else with this question, here is an example of a custom setup:

let g:neomake_typescript_tsc_maker = {
      \ 'args': [
      \ '-m', 'commonjs', '--noEmit', '--target', 'ES5', '--experimentalDecorators'
      \ ],
 \ 'errorformat':
@craigp
craigp / tmux_ubuntu14.04.sh
Created June 3, 2016 14:01 — forked from VladSem/tmux_ubuntu14.04.sh
install tmux 2.0 on Ubuntu 14.04
sudo apt-get update
sudo apt-get install -y python-software-properties software-properties-common
sudo add-apt-repository -y ppa:pi-rho/dev
sudo apt-get update
sudo apt-get install -y tmux=2.0-1~ppa1~t
@craigp
craigp / my_app.ex
Created June 9, 2016 09:43 — forked from alanpeabody/my_app.ex
Websockets in Elixir with Cowboy and Plug
defmodule MyApp do
use Application
def start(_type, _args) do
import Supervisor.Spec, warn: false
children = [
Plug.Adapters.Cowboy.child_spec(:http, MyApp.Router, [], [
dispatch: dispatch
])
@craigp
craigp / my_app.ex
Created June 9, 2016 09:43 — forked from alanpeabody/my_app.ex
Websockets in Elixir with Cowboy and Plug
defmodule MyApp do
use Application
def start(_type, _args) do
import Supervisor.Spec, warn: false
children = [
Plug.Adapters.Cowboy.child_spec(:http, MyApp.Router, [], [
dispatch: dispatch
])
@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()"