Skip to content

Instantly share code, notes, and snippets.

View doomspork's full-sized avatar
👋
How's it going?

Sean Callan doomspork

👋
How's it going?
View GitHub Profile
defmodule Contributors do
@client %Tentacat.Client{auth: ""}
def commit(user, repo), do: Tentacat.Commits.list(user, repo, @client)
def analysis(commits) do
commits
|> Enum.filter(&is_map/1)
|> Enum.reduce(%{}, &users_first_commit/2)
|> Enum.sort(fn {_, date1}, {_, date2} -> date1 < date2 end)
defmodule Example do
def reverse(list, acc \\ [])
def reverse([], acc) do
acc
end
def reverse([head|tail], acc) do
reverse(tail, [head | acc])
end
defmodule Example do
def split(list, chunk_size) do
do_split(list, chunk_size, [[]])
end
defp do_split([], _chunk_size, acc) do
acc
end
defp do_split([item|rest], chunk_size, [cur|acc]) do
#!/bin/bash
wget https://packages.erlang-solutions.com/erlang-solutions_1.0_all.deb && \
sudo dpkg -i erlang-solutions_1.0_all.deb && \
sudo apt-get update && \
sudo apt-get -y install esl-erlang && \
sudo apt-get -y install elixir
@doomspork
doomspork / Gemfile
Created March 5, 2013 20:29
Example Rake task for downloading and unzipping a file. Usage: rake 'pull[remote_file, local_file]'
#!/usr/bin/env rake
Dir.glob('*.rake').each { |r| import r }
defmodule Concoct do
@alphabet "abcdefghijklmnopqrstuvwxyx"
@reserved ~w(init module_info)a
defmacro __using__(mod, _opts \\ []) do
wrappers = mod.module_info
|> Keyword.get(:exports)
|> Enum.filter(&Concoct.reserved_fun/1)
|> Enum.map(&Concoct.wrap_erl_fun/1)
1) test does not create resource and renders errors when data is invalid (AssignBug.ThingControllerTest)
test/controllers/thing_controller_test.exs:24
** (ArgumentError) assign @owners not available in eex template.
Please make sure all proper assigns have been set. If this
is a child template, ensure assigns are given explicitly by
the parent template as they are not automatically forwarded.
Available assigns: [:changeset, :conn, :view_module, :view_template]
defmodule Example.User do
@derive [Poison.Encoder]
defstruct [:name, :age]
end
iex> json = ~s({"name": "uto", "age": "old"})
"{\"name\": \"uto\", \"age\": \"old\"}"
iex> Poison.decode!(json, as: Example.User)
%Example.User{age: "old", name: "uto"}
class SandPaper
class NoValueForRequiredField < Exception; end
class UnsupportedBooleanValue < Exception; end
TYPE_CONVERTERS = [ :boolean, :string, :integer, :float]
TYPE_CONVERTERS.each do |type|
define_method type, ->(name, options = {}) {
options[:xpath] ||= "//#{name.to_s}"
@grain[name] = options.merge type: type
@doomspork
doomspork / Gemfile
Created March 1, 2013 03:59
Sample non-managed currency implementation with unit test
source :rubygems
gem 'sinatra'
gem 'trollop'
gem 'faraday'