Skip to content

Instantly share code, notes, and snippets.

View codecakes's full-sized avatar
💭
I may be slow to respond.

codecakes codecakes

💭
I may be slow to respond.
View GitHub Profile
@codecakes
codecakes / designing_ha_systems.md
Created April 5, 2024 15:11
How to design Horizontally scalable distributed systems?

HA principles: CAP done right

  • Design in isolation (Partition)
    • 2 business modules must communicate over message pattern. They are not considered business modules if one requires the other, in which case they don’t need to communicate over messages if a business process has to die, all interconnected business modules must die
    • process are stateless
    • fault tolerant implies scalability implies concurrency and concurrent business processes
  • Availability
    • its better to die on fault and restart, then drag and build up the pile of error
  • when a process dies, fault detection and communicating fault is important
@PJUllrich
PJUllrich / big-o.md
Last active June 28, 2024 20:25
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
@kerr-bighealth
kerr-bighealth / config.tf
Created January 28, 2020 20:08
iam-user module
terraform {
required_version = ">=0.12, <0.13"
}
def answer(map, git_gud=True):
"""Find the shortest path in a binary 2D map where a wall can be removed.
The algorithm uses a modified Dijstra's algorithm to find the shortest path
from the start vertex (0,0) to the end vertex (w-1,h-1) in a 2D binary map.
A single wall can be removed from the map to make the shortest path, if
necessary. The first wall in any path can be ignored easily, but if a wall
is necessary to be removed for a valid solution to exist the simple
algorithm does not remember the minimum path that does not pass through a
wall to arrive at the mandatory wall vertex. Therefore we modify the
@comalex
comalex / mock.md
Last active February 12, 2020 07:41
Mock python cheatsheet

Python unittest.mock Cheat Sheet

Basic usage

mock.Mock()
mock.MagicMock()

Asserts

assert_called_with: This method asserts that the last call was made with the given parameters

@mtrunkat
mtrunkat / docker-mongo-repair
Last active March 19, 2024 06:28
Run "mongo --repair" in Docker container that cannot start because of MongoDB error
#!/bin/bash
# See https://github.com/docker-library/mongo/pull/63
docker run --rm --volumes-from my-mongo-server mongo unlink "/data/db/mongod.lock"
docker run --rm --volumes-from my-mongo-server mongo --repair
@emilsoman
emilsoman / phoenix_to_umbrella
Last active July 13, 2024 21:50
How to move an existing phoenix app under an umbrella app
How to convert existing phoenix app to an umbrella app.
https://elixir-lang.slack.com/archives/phoenix/p1472921051000134
chrismccord [10:14 PM]
@alanpeabody yes, it's straightforward
[10:14]
1) mix new my_umbrella --umbrella
@codecakes
codecakes / url_param.js
Created August 6, 2016 21:08
Simple Url Parameter extraction from DOM
"use strict";
let paramRegex = /([a-zA-Z0-9]+\=[a-zA-Z0-9]+)/ig;
location.search.match(paramRegex);
@remarkablemark
remarkablemark / Dockerfile
Last active June 18, 2024 04:42
Install node and npm with nvm using Docker.
# set the base image to Debian
# https://hub.docker.com/_/debian/
FROM debian:latest
# replace shell with bash so we can source files
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
# update the repository sources list
# and install dependencies
RUN apt-get update \
@narrowtux
narrowtux / model.ex
Last active February 16, 2023 08:39
Recursive models with ecto
defmodule Model do
schema "models" do
field :foo, :string
has_many :children, Model, foreign_key: :parent_id
belongs_to :parent, Model, foreign_key: :parent_id
end
@doc """
Recursively loads parents into the given struct until it hits nil
"""