Skip to content

Instantly share code, notes, and snippets.

View Harrisonl's full-sized avatar

Harry Lucas Harrisonl

View GitHub Profile
@Harrisonl
Harrisonl / rella.dart
Created February 1, 2023 11:05
Rella dart
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,
case Enum.all?(["name", "email", "password", "organisation_id"], fn(field) -> user_params[field] end) do
true -> #....
false -> :error
end
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
@Harrisonl
Harrisonl / day2_part1.hs
Created December 5, 2018 23:57
Day2 Part 1
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]
@Harrisonl
Harrisonl / aoc_1.ex
Created December 2, 2018 08:04
adevent of code problem 1.2
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
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")
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
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
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)
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: ""