This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This module represents a behaviour and when used picks from the Application configuration which implementation will be used | |
defmodule Clock do | |
@callback now() :: Integer.t | |
defmacro __using__([]) do | |
module = Application.get_env(:my_app, :Clock) | |
quote do | |
alias unquote(module), as: Clock | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# for an offset range of -26 to + 26 | |
# 114 characters | |
[n,p]=IO.gets("")|>String.split",";IO.puts for c<-to_char_list(p),do: c<97&&c||97+rem c-71-String.to_integer(n),26 | |
# for any offset range | |
# 122 characters | |
[n,p]=IO.gets("")|>String.split",";IO.puts for c<-to_char_list(p),do: c<97&&c||97+rem c-71-rem(String.to_integer(n),26),26 | |
# with @MPAherns use of a binary generator in the list comprehension | |
# 103 characters |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A convenient script for Elixir golfing. | |
# Provide your code and some test cases. Then run this file, e.g. "elixir golf.exs". | |
# Outputs your character length and test results. | |
# Text input, text output and return values are all handled. | |
# | |
# By Henrik Nyh (http://henrik.nyh.se) under the MIT license. | |
ExUnit.start | |
defmodule Golf.Example do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Verifying that +gvaughn is my blockchain ID. https://onename.com/gvaughn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Mapper do | |
@x_mapping [bar: [:baar], constant: [:constant], foo: [:fooo], stuffiness: [:stuff, :stuffiness], thing_other: [:thing, :other], thing_sub: [:thing, :sub]] | |
def for_x(source_data) do | |
mapper_for(@x_mapping).(source_data) | |
end | |
defp mapper_for(mapping) do | |
&Enum.map(&1, fn input -> Map.new(mapping, fn {dest, src} -> {dest, get_in(input, src)} end) end) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
p=fn 0,_->;i,p->spawn fn->w=" on the wall.";b=&" #{&1} bottle#{&1==1&&""||"s"} of Elixir" | |
IO.puts [inspect(self),b.(i),w,b.(i),".\n",i==1&&"Go get some more,"<>b.(99)||"Take one down pass it around,"<>b.(i-1),w,10] | |
p.(i-1,p)end end;p.(99,p);:timer.sleep 999 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!bash -e | |
TOKEN= # slack token is generate from: https://api.slack.com/web | |
CHANNEL= # name of channels or group | |
MESSAGE= # message | |
NICK= # bot name | |
IS_PRIVATE= # 1 or 0 | |
if [ $IS_PRIVATE -eq 1 ]; then | |
API_TYPE=groups |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule DeeplyNested do | |
def get_nat_ip(input) do | |
steps = [first_map_with_key("accessConfigs"), | |
first_map_with_key("natIP") | |
] | |
get_in(input, steps) | |
end | |
defp first_map_with_key(key) do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Stack do | |
@moduledoc """ | |
Implement a stack using a linked list to back it. The stack should support | |
peek, push, pop, count | |
do it in whatever language you want | |
""" | |
defstruct llist: [] | |
def peek(%Stack{llist: [head | _]}), do: head | |
def peek(%Stack{}), do: nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule YourAppName.Search do | |
# ... | |
@doc """ | |
Queries listings. | |
""" | |
def query_listings(query, current_user) do | |
default_scope = from l in Listing, where: l.draft == false or l.user_id == ^current_user.id, order_by: [desc: l.updated_at], limit: 50 | |
id = _try_integer(query) |