Skip to content

Instantly share code, notes, and snippets.

View ryanwinchester's full-sized avatar
⚗️
Working on open-source and side projects

Ryan Winchester ryanwinchester

⚗️
Working on open-source and side projects
View GitHub Profile
Mix.install([{:bandit, "~> 1.0"}])
defmodule WebServer do
import Plug.Conn
def init(opts), do: opts
def call(conn, _opts) do
case conn.path_info do
[] ->
@ryanwinchester
ryanwinchester / keymap.jsonc
Created April 20, 2024 12:56
Zed keymap working on my vim stuff
[
// -----------------------------------------------------------------------
// Vim keybindings
// -----------------------------------------------------------------------
{
// NORMAL and VISUAL modes
"context": "Editor && (vim_mode == normal || vim_mode == visual) && !VimWaiting && !menu",
"bindings": {
// Tab things. Almost as good as harpoon.
"space 1": ["pane::ActivateItem", 0],
@ryanwinchester
ryanwinchester / 1brc.exs
Last active March 18, 2024 15:11 — forked from ethanniser/1brc.exs
1 billion row challenge in a SINGLE EXPRESSION!
Mix.install([
{:explorer, "~> 0.8.0"}
])
filepath = "./measurements.txt"
defmodule Challenge do
import Explorer.Series
require Explorer.DataFrame, as: DF
@ryanwinchester
ryanwinchester / erlang-elixir.md
Last active March 12, 2024 11:25
Joe Armstrong on Elixir (and Erlang)

The good thing about Elixir (and Erlang) lies in the concurrency - it’s all about creating parallel process and sending messages - and this (as Alan Kay has pointed out on numerous occasions) is the essence of OO programming.

OO programming is all about objects. Objects are things that respond to messages (or should be) - to get an object to do something you send it a message - how it does it is totally irrelevant - think of objects as black boxes, to get them to do something you send them a message, they reply by sending a message back.

How they work is irrelevant - whether the code in the black box is functional or imperative is irrelevant - all that is important is that they do what they are supposed to do.

Unfortunately the first big OO language based on this model (smalltalk) talked about objects and messages but messages in smalltalk were not real messages but disguised synchronous function calls - this mistake was repeated in C++ and Java and the “idea” of OO programming morphed into some weird idea

@ryanwinchester
ryanwinchester / bandit_mask.exs
Last active December 8, 2023 18:44
Benchmark Bandit WebSocket Frame Mask
Mix.install([
{:benchee, "~> 1.2"}
])
# ------------------------------------------------------------------------------
# Original code
# ------------------------------------------------------------------------------
defmodule Original do
# Masking is done @mask_size bits at a time until there is less than that number of bits left.
@ryanwinchester
ryanwinchester / keymap.jsonc
Last active September 21, 2023 15:09
Zed Config
[
{
"context": "Editor",
"bindings": {
// -----------------------------------------------------------------------
// VS Code keybindings
// -----------------------------------------------------------------------
// https://code.visualstudio.com/docs/getstarted/keybindings#_basic-editing
//
// In VS Code this moves either the current line or selection up or down.
@ryanwinchester
ryanwinchester / README.md
Last active May 5, 2023 16:21
Comparing `Enum.join/2` vs `Enum.instersperse/2` + `IO.iodata_to_binary/1`....

Question

I know IO.iodata_to_binary performs well and is used in string building situations where performance matters.

However, I had a question if Enum.intersperse/2 and then IO.iodata_to_binary/1 Is better than just Enum.join/2 + string interpolation.

Here are my results.

Results

@ryanwinchester
ryanwinchester / telnet_client.ex
Created January 9, 2023 16:57
Elixir (clunky) Telnet Client
defmodule TelnetClient do
use GenServer
require Logger
@doc """
Starts a connection to the telnet server.
"""
def start_link({host, port}) do
GenServer.start_link(__MODULE__, {host, port}, name: __MODULE__)
defmodule PriorityQueue do
@moduledoc """
A priority queue in Elixir.
"""
@type priority :: integer() | nil
@type element :: any()
@type t :: %__MODULE__{set: :gb_sets.set({priority(), element()})}
@ryanwinchester
ryanwinchester / bench.ex
Created October 3, 2022 22:52 — forked from moogle19/bench.ex
Masking benchmark
defmodule Bench do
def orig(payload, mask) do
maskstream = <<mask::32>> |> :binary.bin_to_list() |> Stream.cycle()
payload
|> :binary.bin_to_list()
|> Enum.zip(maskstream)
|> Enum.map(fn {x, y} -> Bitwise.bxor(x, y) end)
|> :binary.list_to_bin()
end