Skip to content

Instantly share code, notes, and snippets.

# John PalgutJwsonic

• Sort options
Created Oct 2, 2019
View service_mode_controller.ex
 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}
Created Oct 1, 2019
View spiral.ex
 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()
Created Sep 26, 2019
Courses Algo Problem
View courses.exs
 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])
Created Jul 11, 2019
Word search
View word_search.exs
 defmodule Dictionary do @moduledoc """ A Trie based approach to the dictionary. https://en.wikipedia.org/wiki/Trie """ defstruct words: %{} @terminatior "."
Created May 21, 2019
View reorder_lists.exs
 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
Created May 17, 2019
View string_equations.exs
 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
Created May 2, 2019
Python3 m+n solution
View m+n.py
 #!/usr/bin/env python3 import unittest def zero(matrix): if len(matrix) == 0: return matrix rows = set() cols = set()
Created Apr 10, 2018
View api.re
 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"))
Last active Mar 2, 2017
CC stuff
View pending.js
 const money = t => parseFloat(t.trim().replace(/[^0-9\.]+/g,"")); const pending = \$('#sortTable tr').toArray().reduce((acc, node) => { const trNode = \$(node); if(trNode.find('td.date').text() === 'Pending') { return acc + money(trNode.find('td.amount').text()); } return acc;
Created Feb 19, 2017
View register.liquid

{% form 'create_customer' %}

{{ 'customer.register.title' | t }}

{{ form.errors | default_errors }}
You can’t perform that action at this time.