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
import 'dart:convert'; | |
import 'package:http/http.dart' as http; | |
const url = "https://ingestion.rella.so/i/events"; | |
const HTTP_METHOD = "POST"; | |
const apiKey = "key here"; | |
Future<void> makeRequest(Map<String, dynamic> payload) async { | |
final response = await http.post( | |
url, |
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
case Enum.all?(["name", "email", "password", "organisation_id"], fn(field) -> user_params[field] end) do | |
true -> #.... | |
false -> :error | |
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
def register_user(%{organisation_id: org_id, account_type: type}} = user_params) do | |
case Enum.all?(["name", "email", "password", "organisation_id"], fn(field) -> user_params[field] end) do | |
true -> | |
case Repo.get(Organisation, org_id) do | |
nil -> {:error, :not_found} | |
org -> | |
valid = | |
case type do | |
"basic" -> org.used + 1 > org.capacity | |
"pro" -> org.used + 2 > org.capacity |
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
data LetterGroup = TwoChar | |
| ThreeChar | |
deriving (Show, Eq, Ord) | |
-- PROBLEM 1 | |
-- Call This | |
calcCheckSum :: [ID] -> Int | |
calcCheckSum = foldl (*) 1 . map length . groupSort . concat . map (nub . repeats) | |
twoOrThree :: [LetterGroup] -> [Char] -> [LetterGroup] |
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 Calibrate do | |
def prob1(freqs), do: Enum.reduce(freqs, 0, &Kernel.+/2) | |
def prob2(freqs), do: prob2(freqs, %{last: 0}, freqs) | |
def prob2([], mem, freqs), do: prob2(freqs, mem, freqs) | |
def prob2([h | t], %{last: last} = mem, freqs) do | |
n = last + h | |
case mem[n] do | |
nil -> prob2(t, Map.merge(mem, %{:last => n, n => true}), freqs) | |
true -> n |
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
alias Experimental.GenStage | |
defmodule Go do | |
def go do | |
:ets.new(:logs, [:named_table, :public]) | |
{:ok, producer} = GenStage.from_enumerable(File.stream!("nasa.log"), name: __MODULE__) | |
{:ok, consumer1} = GsConsumer.start_link("1") | |
{:ok, consumer2} = GsConsumer.start_link("2") |
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
alias Experimental.GenStage | |
defmodule Go do | |
def go(file) do | |
{:ok, producer} = GsProducer.start_link(file) | |
{:ok, consumer1} = GsConsumer.start_link | |
{:ok, consumer2} = GsConsumer.start_link | |
{:ok, consumer3} = GsConsumer.start_link | |
{:ok, consumer4} = GsConsumer.start_link |
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 Binary do | |
def strip_vowels(a,b \\ "") | |
def strip_vowels("", acc), do: acc | |
def strip_vowels(<<"a", rest::binary>>, acc), do: strip_vowels(rest, acc) | |
def strip_vowels(<<"e", rest::binary>>, acc), do: strip_vowels(rest, acc) | |
def strip_vowels(<<"i", rest::binary>>, acc), do: strip_vowels(rest, acc) | |
def strip_vowels(<<"o", rest::binary>>, acc), do: strip_vowels(rest, acc) | |
def strip_vowels(<<"u", rest::binary>>, acc), do: strip_vowels(rest, acc) | |
def strip_vowels(<<head::binary-size(1), rest::binary>>, acc), do: strip_vowels(rest, acc <> head) | |
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
def strip_vowels(string, acc = "") | |
return acc if string.length <= 0 | |
case string[0].downcase | |
when "a" | |
strip_vowels(string[1..-1], acc) | |
when "e" | |
strip_vowels(string[1..-1], acc) | |
when "i" | |
strip_vowels(string[1..-1], acc) |
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 Binary do | |
def strip_vowels("", acc), do: acc | |
def strip_vowels(<<head::binary-size(1), rest::binary>>, acc \\ "") do | |
strip_vowels(rest, acc <> check_vowels(head)) | |
end | |
defp check_vowels("a"), do: "" | |
defp check_vowels("e"), do: "" | |
defp check_vowels("i"), do: "" |
NewerOlder