This file contains hidden or 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 Matcher do | |
defmacro match_any?(pattern, collection) do | |
quote do | |
Enum.any?(unquote(collection), fn item -> | |
case item do | |
unquote(pattern) -> true | |
_ -> false | |
end | |
end) | |
end |
This file contains hidden or 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 Breadpacket do | |
use GenServer | |
def start_link(%{packet_state: state, packet_name: name}) do | |
GenServer.start_link(__MODULE__, state, name: name) | |
end | |
def init(state) do | |
{:ok, state} |
This file contains hidden or 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 LookupExample do | |
def lookup(ip) do | |
ip | |
|> Geolix.lookup | |
|> parse_lookup | |
end | |
def parse_lookup(%{city: %{name: city_name}, country: %{iso_code: iso_code}, postal: %{code: postal_code}}) do | |
{city_name, iso_code, postal_code} |
This file contains hidden or 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 Bmgr.Transaction.SearchQuery do | |
import Ecto.Query | |
alias Bmgr.{Transaction} | |
@filters [:account, :status] | |
def build(filter_params) do | |
do_filter(Transaction, @filters, filter_params) | |
end |
This file contains hidden or 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
# Redis Cheatsheet | |
# All the commands you need to know | |
redis-server /path/redis.conf # start redis with the related configuration file | |
redis-cli # opens a redis prompt | |
# Strings. |
This file contains hidden or 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
use std::thread; | |
use std::time as timing; | |
use time; | |
use std::fs; | |
use std::io; | |
use std::io::BufRead; | |
static DB_PATH: &str = "./file.db"; |
This file contains hidden or 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 MultisortDecimalTest do | |
use ExUnit.Case | |
@data [ | |
%{multiplier: Decimal.from_float(1.0), points: Decimal.from_float(400.0)}, | |
%{multiplier: Decimal.from_float(1.0), points: Decimal.from_float(500.0)}, | |
%{multiplier: Decimal.from_float(0.9), points: Decimal.from_float(600.0)}, | |
%{multiplier: Decimal.from_float(0.9), points: Decimal.from_float(700.0)} | |
] |
This file contains hidden or 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
alias Ecto.Changeset | |
defmodule Poly1 do | |
use Ecto.Schema | |
embedded_schema do | |
field(:key1, :string) | |
end |
This file contains hidden or 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
x = nil | |
# Q: What is x? | |
# Q: What type is it? | |
# Q: What does it represent? |
This file contains hidden or 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
iex(1)> cells = SparseCells.build([cell_1: ["a", "b"], cell_2: [1, 2], cell_3: ["w", "x", "y", "z"]]) | |
%SparseCells{ | |
key_sizes: [cell_1: 2, cell_2: 2, cell_3: 4], | |
map: %{ | |
{:cell_1, 0} => "a", | |
{:cell_1, 1} => "b", | |
{:cell_2, 0} => 1, | |
{:cell_2, 1} => 2, | |
{:cell_3, 0} => "w", | |
{:cell_3, 1} => "x", |