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
Short but not appreciated enough | |
defp validate_params(params) do | |
cond do | |
!validate?(params["frequency"]) -> | |
{:invalid, "The parameter 'frequency' isn't valid."} | |
!validate?(params["storage_duration"]) -> | |
{:invalid, "The parameter 'storage_duration' isn't valid."} | |
!cr_status?(params["status"]) -> | |
{:invalid, "The parameter 'status' isn't valid."} |
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 validate_params(params) do | |
cond do | |
!validate?(params["frequency"]) -> | |
{:invalid, "The parameter 'frequency' isn't valid."} | |
!validate?(params["storage_duration"]) -> | |
{:invalid, "The parameter 'storage_duration' isn't valid."} | |
!cr_status?(params["status"]) -> | |
{:invalid, "The parameter 'status' isn't valid."} | |
true -> | |
{:ok} |
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 validate_params(params) do | |
with :ok <- validate?("frequency", params["frequency"]), | |
:ok <- validate?("storage_duration", params["storage_duration"]), | |
:ok <- validate?("status", params["status"]), | |
do: :ok | |
end | |
def validate?("status", "on"), do: :ok | |
def validate?("status", "off"), do: :ok | |
def validate?("status", "on-scheduled"), do: :ok |
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 |
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
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
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
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
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
# params = Enum.reject(params, fn {_key, value} -> value == "" end) |> Enum.into(%{}) |