Skip to content

Instantly share code, notes, and snippets.

Computer Information:
Manufacturer: Unknown
Model: Unknown
Form Factor: Desktop
No Touch Input Detected
Processor Information:
CPU Vendor: GenuineIntel
CPU Brand: Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz
CPU Family: 0x6
defmodule Sutro.ServiceMode.Controller do
@moduledoc """
A Controller process that waits for various service mode messages to come in.
It also includes various helper methods for sending messages to the correct process.
"""
require Logger
require ServiceModeConstants
alias Sutro.ServiceMode.{ServiceSession, ServiceSessionManager}
defmodule Spiral do
def order(matrix) do
bounds = %{
xmin: 0,
xmax: matrix |> hd() |> length(),
ymin: 0,
ymax: length(matrix)
}
matrix |> next({0, 0}, {1, 0}, bounds, []) |> Enum.reverse()
@Jwsonic
Jwsonic / courses.exs
Created September 26, 2019 19:02
Courses Algo Problem
defmodule Dag do
defstruct edges: %{}
def from_list(list) do
Enum.reduce(list, %Dag{}, fn [to, from], dag -> insert(dag, from, to) end)
end
def insert(%Dag{edges: edges}, from, to) do
nodes = Map.get(edges, from, [])
updated_edges = Map.put(edges, from, [to | nodes])
@Jwsonic
Jwsonic / word_search.exs
Created July 11, 2019 20:49
Word search
defmodule Dictionary do
@moduledoc """
A Trie based approach to the dictionary.
https://en.wikipedia.org/wiki/Trie
"""
defstruct words: %{}
@terminatior "."
defmodule ListNode do
@moduledoc """
Define a Node type for our linked list.
"""
@enforce_keys [:data, :next]
defstruct data: 0,
next: nil
end
defimpl String.Chars, for: ListNode do
defmodule Digits do
@operators ["+", "-", "*"]
def calculate(num, target) do
# 1) Turn num into a list of characters
# 2) Build all possible equations
# 3) Filter out the ones that don't evaluate to the target
# 4) Clean up results for printing
num
@Jwsonic
Jwsonic / m+n.py
Created May 2, 2019 23:57
Python3 m+n solution
#!/usr/bin/env python3
import unittest
def zero(matrix):
if len(matrix) == 0:
return matrix
rows = set()
cols = set()
module type ApiClient = {let getFile: unit => string;};
module FakeApiClient: ApiClient = {
let getFile = () => "cat.jpg";
};
let unwrapUnsafely = data =>
switch (data) {
| Some(v) => v
| None => raise(Invalid_argument("unwrapUnsafely called on None"))
@Jwsonic
Jwsonic / best_practices.md
Last active May 31, 2017 01:02
List of Golang resources for Eyegroove