Skip to content

Instantly share code, notes, and snippets.

View slashdotdash's full-sized avatar

Ben Smith slashdotdash

View GitHub Profile
@slashdotdash
slashdotdash / app.js
Created November 16, 2023 17:01 — forked from cblavier/app.js
Responsive Phoenix LiveView
const Hooks = { ViewportResizeHooks}
const connectLiveSocket = () => {
const csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute('content')
const liveSocket = new LiveSocket('/my_app/live', Socket, {
params: {
_csrf_token: csrfToken,
viewport: {
width: window.innerWidth,
height: window.innerHeight
@slashdotdash
slashdotdash / big-o.md
Created January 11, 2022 09:46 — forked from PJUllrich/big-o.md
Big-O Time Complexities for Elixir Data Structures

Big-O Time Complexities for Elixir data structures

Map [1]

Operation Time Complexity
Access O(log n)
Search O(log n)
Insertion O(n) for < 32 elements, O(log n) for >= 32 elements [2]
Deletion O(n) for < 32 elements, O(log n) for >= 32 elements
defmodule EventStore.CategoryStreamLinker do
@moduledoc """
Links streams from aggregate instances to their respective category streams.
example: events from stream_uuid of `contractors_contract-07c52787-da0c-444f-9783-5d380f7093f9` will be
linked to stream_uuid of `contractors_contract`.
"""
use Commanded.Event.Handler,
application: My.App,
@slashdotdash
slashdotdash / default_behaviour.ex
Created September 8, 2020 10:40 — forked from christhekeele/default_behaviour.ex
Behaviours with Defaults for Elixir
defmodule Default.Behaviour do
@moduledoc """
Creates a behaviour that carries its own default implementation.
When used into a behaviour module, when that module in turn is used, all functions
defined on it are given to the using module.
This allows you to have concrete implementations of the behaviour's default functionality
for testing, unlike cramming them all into a __using__ macro.
# Elixir v1.0
defmodule Rules do
defmacro __using__(_) do
quote do
import unquote(__MODULE__)
@before_compile unquote(__MODULE__)
@rules []
end
end
@slashdotdash
slashdotdash / task1.exs
Created July 6, 2018 12:09 — forked from moklett/task1.exs
Elixir Task - Crash Handling
# This demonstrates that, when using async/await, a crash in the task will crash the caller
defmodule Tasker do
def good(message) do
IO.puts message
end
def bad(message) do
IO.puts message
raise "I'm BAD!"
end
# Aggregates are just collections of command functions, which emit events,
# and event handlers, which mutate state.
# In order to hold state, they should be also structs.
# There is no new() function because aggregates aren't supposed to appear
# out of the blue, they are always the result of a command.
# In this case, %OpenAccount{}.
defmodule Bank.Account do
defstruct [:account_number, :balance]
@slashdotdash
slashdotdash / Vagrantfile
Created February 10, 2016 16:23 — forked from ndemonner/Vagrantfile
Sample Vagrantfile for easy Elixir-based development
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.network "private_network", ip: "192.168.33.10"
config.vm.provision "shell", inline: <<-SHELL
wget https://packages.erlang-solutions.com/erlang-solutions_1.0_all.deb && sudo dpkg -i erlang-solutions_1.0_all.deb
sudo apt-get update
sudo apt-get install -y nodejs
/**
* ## Merging mixin views in backbone.js ##
*
* really just more a test for tumblr gistr
*/
/**
* Merge the mixin (a Backbone.View) into another Backbone.View. Automatically merge events, defaults, and call the parent initializer.
**/
function mergeMixin(view, mixin) {