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
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
@ryanwinchester
ryanwinchester / guide-1.md
Last active September 30, 2022 20:36
Intro to Elixir, and your first Phoenix app (coming soon)! (https://ryanwinchester.ca/posts/intro-to-elixir-for-non-ruby-programmers)

Goals

I come from the land of PHP and JavaScript, with very little Ruby experience. I have seen quite a few posts around the interwebs introducing Elixir from a Rubyist's perspective but I haven't really seen any from a perspective I can relate to. The syntax of Elixir is kind of foreign to most people outside of Ruby-land, so I hope to help push people a little bit over the initial hump with some examples using PHP and JavaScript (ES2015) along with the Elixir examples.

My goal with this post is to help introduce the syntax as well as a shallow introduction to immutability and how we use recursion instead of loops.

If you have Elixir installed, you can paste or type examples into IEx (interactive elixir). Start IEx shell by just typing iex into your terminal.

Syntax and Semantics

@ryanwinchester
ryanwinchester / items_live.ex
Last active May 6, 2022 00:01
Meat Waffle Live View
defmodule AppWeb.ItemsLive do
use AppWeb, :live_view
import Bitwise
@interval_ms 3
@impl true
def mount(_params, _session, socket) do
# Send a `:tick` message to this process at the specified interval.
@ryanwinchester
ryanwinchester / chapter-1-part-1.md
Last active May 2, 2022 15:28
Chapter 1 - Take the Red Pill (this chapter name has not aged well)

CHAPTER 1 – Take the Red Pill (cringe)

The Elixir programming language wraps functional programming with im mutable state and an actor-based approach to concurrency in a tidy, modern syntax. And it runs on the industrial-strength, high-performance, distributed Erlang VM. But what does all that mean?

It means you can stop worrying about many of the difficult things that currently consume your time. You no longer have to think too hard about protecting your data consistency in a multithreaded environment. You worry less

@ryanwinchester
ryanwinchester / twilio_signature.ex
Last active November 8, 2021 15:40
Twilio signature module
defmodule TwilioSignature do
@moduledoc """
Twilio signatures module.
"""
@doc """
Generate the Twilio signature from a request.
See: https://www.twilio.com/docs/usage/security#validating-requests
@ryanwinchester
ryanwinchester / twittermute.txt
Created May 11, 2021 22:36 — forked from IanColdwater/twittermute.txt
Here are some terms to mute on Twitter to clean your timeline up a bit.
Mute these words in your settings here: https://twitter.com/settings/muted_keywords
ActivityTweet
generic_activity_highlights
generic_activity_momentsbreaking
RankedOrganicTweet
suggest_activity
suggest_activity_feed
suggest_activity_highlights
suggest_activity_tweet
[
0,
1,
1,
2,
3,
5,
8,
13,
21,
import Enum;c=String.replace("example string",~r/[\W_]/,"")|>String.split("",trim: true);zip(c,slice(c,1..-1))|>map(fn{a,b}->a<>b end)|>join(" ") end end