Skip to content

Instantly share code, notes, and snippets.

defmodule ZipList do
defstruct previous: [], current: nil, remaining: []
def from_list(list, index \\ 0)
def from_list([], _), do: {:error, :empty_list}
def from_list(list, index) when length(list) < index, do: {:error, :index_out_of_bounds}
def from_list(list, index) when is_list(list) do
previous = list |> Enum.take(index) |> Enum.reverse
[current | remaining] = Enum.drop list, index
ziplist = %__MODULE__{previous: previous, current: current, remaining: remaining}
@rob-brown
rob-brown / Actor.swift
Last active March 8, 2018 14:15
Elixir-inspired concurrency primitives
//
// Actor.Swift
//
// Copyright (c) 2017 Robert Brown
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
@rob-brown
rob-brown / SecretMessage.exs
Last active June 7, 2021 14:48
Encode secret messages into text using zero-width spaces
defmodule SecretMessage do
@zero "\u200C"
@one "\u200D"
def encode(text, secret) when byte_size(text) > byte_size(secret) do
secret
|> obfuscate
|> Stream.concat(Stream.repeatedly fn -> "" end)
|> Stream.zip(String.codepoints text)
import Foundation
import Actor
import MessageRouter
public final class Core<State, Event, Command> {
public typealias CommandProcessor = (Core<State, Event, Command>, Command) -> Void
public typealias EventHandler = (State, Event) -> CoreUpdate<State, Command>
public let stateChanged = MessageRouter<State>()
@rob-brown
rob-brown / derived-stats.csv
Last active September 14, 2020 02:43
Amiibo Personality Research
Personality Total Wins Total Loses Total KOs Total Falls Total Damage Given Total Damage Received Total Match Wins Total Games Win Rate KOs per Game Falls per Game Damage Given per Game Damage Received per Game Damage Given per KO KOs per Fall
Offensive 35 10 124 83 18,524 14,856 7 45 77.8% 2.756 1.844 411.64 330.13 149.39 1.49
Lightning Fast 31 12 116 81 17,116 14,349 6 43 72.1% 2.698 1.884 398.05 333.70 147.55 1.43
Technician 25 26 120 120 19,038 18,943 3 51 49.0% 2.353 2.353 373.29 371.43 158.65 1.00
Daredevil 27 26 125 124 20,083 20,122 3 53 50.9% 2.358 2.340 378.92 379.66 160.66 1.01
Lively 30 19 125 102 19,715 16,985 5 49 61.2% 2.551 2.082 402.35 346.63 157.72 1.23
Entertainer 20 26 103 112 16,931 17,670 3 46 43.5% 2.239 2.435 368.07 384.13 164.38 0.92
Unflappable 15 30 93 114 15,780 18,145 1 45 33.3% 2.067 2.533 350.67 403.22 169.68 0.82
Sly 1 35 37 107 7,516 15,793 0 36 2.8% 1.028 2.972 208.78 438.69 203.14 0.35
@rob-brown
rob-brown / amiibo_ssbu.tcl
Last active February 19, 2022 01:20
HexFiend Amiibo Binary Templates
little_endian
# HexFiend Reference: https://github.com/HexFiend/HexFiend/blob/master/templates/Reference.md
proc parse_system {} {
goto 0
section "System" {
hex 1 "BCC1 (UID3 ^ UID4 ^ UID5 ^ UID6)"
hex 1 "Internal (Always 0x48)"
@rob-brown
rob-brown / pokemon-trainer-ratings.csv
Last active April 14, 2021 02:21
Pokémon Trainer SSBU Stats
Placement Figure Win Rate Rating
1 Ivysaur 73.0% 29.06
2 PT Ivysaur 72.0% 28.89
3 Charizard 69.0% 27.67
4 Squirtle 69.0% 26.81
5 PT Squirtle 58.0% 26.59
6 PT Charizard 61.0% 26.38
@rob-brown
rob-brown / access.log
Created February 17, 2022 22:56
Log file for parsing coding challenge
This file has been truncated, but you can view the full file.
1523756544 3 239.163.2.230 1845784 66.166.213.116 80 TCP_HIT/200 1846031 GET http://interview.tubi.tv/04C0BF/v2/sources/content-owners/any-enter-films/275211/v0401185814-1389k.mp4+740005.ts - 0 486 "-" "TubiExoPlayer/2.12.9 (Linux;Android 6.0) ExoPlayerLib/2.4.2" 49343 "-"
1523756611 58 113.240.47.127 3364824 66.166.213.116 80 TCP_HIT/200 3365071 GET http://interview.tubi.tv/04C0BF/v2/sources/content-owners/any-enter-films/326260/v20169101326-1256x544-3063k.mp4+3713710.ts - 0 616 "-" "Mozilla/5.0 (Linux; Android 5.1.1; AFTT Build/LVY48F; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/55.0.2883.91 Mobile Safari/537.36" 49343 "-"
1523756639 3 36.194.144.76 2227424 66.166.213.116 80 TCP_HIT/200 2227671 GET http://interview.tubi.tv/04C0BF/v2/sources/content-owners/paint-from-rights/398629/v201711170053-2061k.mp4+4582327.ts - 0 604 "-" "Mozilla/5.0 (Linux; Android 5.1.1; AFTM Build/LVY48F; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/55.0.2883.91 Mobile Safari/537.36" 49343 "-"
1523
@rob-brown
rob-brown / links_awakening.tcl
Created October 18, 2022 02:47
HexFiend Amiibo Binary Template
@rob-brown
rob-brown / personality.ex
Last active April 10, 2023 18:12
Elixir code to compute SSBU amiibo personalities. Some code omitted to focus on the core algorithm.
defmodule Personality do
@doc """
Parses the attributes from the amiibo and returns the
personality name.
"""
def parse_amiibo(amiibo = %Amiibo{}) do
amiibo
|> Attributes.parse()
|> calculate_personality()
end