Skip to content

Instantly share code, notes, and snippets.

John Palgut Jwsonic

Block or report user

Report or block Jwsonic

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
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}
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()
Jwsonic / courses.exs
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)
def insert(%Dag{edges: edges}, from, to) do
nodes = Map.get(edges, from, [])
updated_edges = Map.put(edges, from, [to | nodes])
View word_search.exs
defmodule Dictionary do
@moduledoc """
A Trie based approach to the dictionary.
defstruct words: %{}
@terminatior "."
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
defimpl String.Chars, for: ListNode do
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
Jwsonic /
Created May 2, 2019
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"))
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('').text() === 'Pending') {
return acc + money(trNode.find('td.amount').text());
return acc;
View register.liquid
<div class="page-width">
<div class="grid">
<div class="grid__item medium-up--one-half medium-up--push-one-quarter">
<div class="form-vertical">
{% form 'create_customer' %}
<h1 class="text-center">{{ 'customer.register.title' | t }}</h1>
{{ form.errors | default_errors }}
You can’t perform that action at this time.