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
def from_list(list) do | |
{_, matrix} = do_from_list(list, [], %{}) | |
matrix | |
end | |
defp do_from_list(list, indices, matrix) do | |
Enum.reduce(list, {0, matrix}, fn | |
sublist, {idx, matrix} when is_list(sublist) -> | |
{sublist_idx, map} = do_from_list(sublist, [idx | indices], matrix) | |
{idx + 1, map} |
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
function sanitizeErrors(errs) { | |
var msg = errs.message; | |
var result = {}; | |
for (var key in msg) { | |
result[key] = key.replace('_', ' ') + ' ' + msg[key][0]; | |
} | |
return result; | |
} |
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 EvercamMedia.Validation.Archive do | |
import String, only: [equivalent?: 2] | |
def validate_params(params) do | |
with :ok <- validate(:title, params["title"]), | |
:ok <- validate(:from_date, params["from_date"]), | |
:ok <- validate(:to_date, params["to_date"]), | |
:ok <- validate(:requested_by, params["requested_by"]), | |
:ok <- validate_boolean(:embed_time, params["embed_time"]), | |
:ok <- validate_boolean(:public, params["public"]), |
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
# params = Enum.reject(params, fn {_key, value} -> value == "" end) |> Enum.into(%{}) |
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
defp generate_exid(title) do | |
clip_exid = | |
title | |
|> String.replace_trailing(" ", "") | |
|> String.downcase | |
|> String.slice(0..5) | |
chars = (?a..?z |> Enum.into([]) |> Enum.map(&to_string([&1]))) ++ (1..9 |> Enum.to_list) | |
random_string = Enum.map(0..3, fn(_) -> Enum.random(chars) end) |> Enum.join("") | |
"#{clip_exid}-#{random_string}" |
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
clip_exid = title.downcase.gsub(' ','') | |
chars = [('a'..'z'), (0..9)].flat_map { |i| i.to_a } | |
random_string = (0...3).map { chars[rand(chars.length)] }.join | |
clip_exid = "#{clip_exid[0..5]}-#{random_string}" |
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
stock_list = [["Mint", "unavailable", "UK 4"], ["Nude", "unavailable", "UK 4"], | |
["Mint", "unavailable", "UK 6"], ["Nude", "unavailable", "UK 6"], | |
["Mint", "unavailable", "UK 8"], ["Nude", "low_stock", "UK 8"], | |
["Mint", "unavailable", "UK 10"], ["Nude", "unavailable", "UK 10"], | |
["Mint", "unavailable", "UK 12"], ["Nude", "low_stock", "UK 12"], | |
["Mint", "unavailable", "UK 14"], ["Nude", "low_stock", "UK 14"], | |
["Mint", "unavailable", "UK 16"], ["Nude", "low_stock", "UK 16"], | |
["Mint", "unavailable", "UK 18"], ["Nude", "available", "UK 18"]] | |
into |
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
params[:id].downcase! | |
camera = get_cam(params[:id]) | |
if params[:from].present? and params[:to].present? and params[:from].to_i > params[:to].to_i | |
raise(BadRequestError, "From can't be higher than to") | |
end | |
from = Time.at(params[:from].to_i).to_s || 0 | |
to = Time.at(params[:to].to_i).to_s | |
to = Time.now.to_s if params[:to].blank? | |
limit = params[:limit] || DEFAULT_LIMIT | |
page = params[:page] || 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
defmodule EvercamMedia.Validation.CloudRecording do | |
def validate_params(params) do | |
with :ok <- validate(:frequency, params["frequency"]), | |
:ok <- validate(:storage_duration, params["storage_duration"]), | |
:ok <- validate(:status, params["status"]), | |
:ok <- validate(:schedule, params["schedule"]), | |
do: :ok | |
end | |
defp validate(key, value) when value in [nil, ""], do: invalid(key) |
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 Password do | |
def generate(mac_address) do | |
mac_address |> check |> do_generate | |
end | |
@regex_for_mac ~r/^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/ | |
defp check(mac) do | |
if Regex.match?(@regex_for_mac, mac) do | |
{:ok, mac} | |
else |