Skip to content

Instantly share code, notes, and snippets.

View nyaray's full-sized avatar
💭
Keeping it real, like floats and doubles

Emilio Nyaray nyaray

💭
Keeping it real, like floats and doubles
View GitHub Profile
@nyaray
nyaray / AlamofireRequests.swift
Last active December 21, 2022 23:48
Good ideas
// definitions
typealias RequestOptions = (HTTPMethod, Set<HeaderOption>, String, String, Encodable?)
protocol RequestOptionsConvertible {
func asRequestOptions() throws -> RequestOptions
}
// "rigging"
enum PaymentMappings: RequestOptionsConvertible {
case .listAvailablePaymentMethods(PaymentMethodsRequest)
@nyaray
nyaray / tryfsharp.fs
Created November 1, 2019 13:40
Explaining parts of F#
let mergeStrings a b c = // string -> (string -> (string -> string))
a + b + c
let test = mergeStrings "foo" "bar"
printfn "%A" (test "kalle")
printfn "%A" ("foo", 2)
//[<CLIMutable>]
type Dep = {
getIt : string -> string
kind : string
@nyaray
nyaray / lazy_profiling.ex
Created August 6, 2019 16:30
paste these functions into a module where you want to profile runtimes
# call this before the code under inspection
defp clock_start(x) do
now = :erlang.timestamp()
Process.put(:"$clock_start", now)
Process.put(:"$clock_step_start", now)
Process.put(:"$clock_steps", [])
x
end
@nyaray
nyaray / rle.ex
Created August 3, 2019 17:00
Run-length encoding
defmodule RLE do
defp run_length_encode(terms, encoding) do
terms = Enum.map(terms, &encoding[&1])
Enum.reduce(tl(terms), [{hd(terms), 1}], fn
c, [{c, count} | rest] -> [{c, count + 1} | rest]
c, [{c_prime, count} | rest] -> [{c, 1}, {c_prime, count} | rest]
end)
|> Enum.map(fn {c, count} -> "#{c}#{inspect(count)}" end)
|> Enum.reverse()
@nyaray
nyaray / unwat.exs
Last active July 20, 2019 16:05
A simple demo of a confusing error
# works, yay \o/
a1 = {<<1::1>>, <<0::1>>}
a2 = {"", ""}
reducer = fn {bw, accent}, {bw_acc, accent_acc} -> {{<<bw_acc::bitstring, bw::bits-1>>}, {<<accent_acc::bitstring, accent::bits-1>>}} end
reducer.(a1, a2)
@nyaray
nyaray / mix.tft_rpi3.exs
Created July 7, 2019 14:44
tft_rpi3 mix files
defmodule TftRpi3.MixProject do
use Mix.Project
@app :tft_rpi3
@version Path.join(__DIR__, "VERSION")
|> File.read!()
|> String.trim()
def project do
[
@nyaray
nyaray / speccheck.exs
Last active June 6, 2019 10:00
Specification checking thing for verifying interactions with mocks.
defmodule SpecCheck do
defmodule MockInteractionException do
@moduledoc """
A structured representation of one of:
- unmet expectation
- missing interactions
- unexpected interactions
"""
defexception message: "Interaction with mock did not match expectation.",
description: nil,
@nyaray
nyaray / notes.md
Last active May 30, 2019 17:30
Scenic tutorial thoughts

General ergonomics tips

Some tips:

  • USE DEFERRED SPECS

My first component

TODO:

@nyaray
nyaray / tips.md
Last active May 2, 2019 17:01
Destination Stockholm

Welcome!

There are quite a few things to check out as well as green areas.

On a sunny day

  • Take a tour of the archipelago (or just hop on a commuter boat)
    • specific spots that are worth checking out coming soon!
  • Check out one of the skybars to get a nice view of the city
@nyaray
nyaray / fp_sweetness.md
Created April 2, 2019 20:33
Observations

"Functions as named case-expressions"

  defp derive_chunk_fallback(chunk_tag, chunk_type) do
    case {chunk_tag, chunk_type} do
      {"", :start} ->
        :missing

      {"", :append} ->
 :no_chunk