Skip to content

Instantly share code, notes, and snippets.

@addrummond
addrummond / Trireme.md
Created August 27, 2025 16:07
Trireme.md
Write a function using the React JavaScript framework to navigate a trireme using the stars.
import React, { useState } from 'react';

// Example star directions
const STAR_DIRECTIONS = [
  { name: 'North Star (Polaris)', heading: 'North' },
@addrummond
addrummond / wordsearch.py
Last active August 20, 2025 08:59
wordsearch.py
class Solution:
def exist(self, board: List[List[str]], word: str) -> bool:
for x in range(len(board[0])):
for y in range(len(board)):
# doing the equality check here means that we omit one layer of
# recursive function calls, which speeds things up considerably
if board[y][x] == word[0] and self.__continuesFrom(board, word, 0, x, y):
return True
return False
@addrummond
addrummond / gist:aabab67d3f4bac382dad430c60158dfe
Last active August 19, 2025 15:01
Mars rover interview task

Mars Rover

Write a program that takes in commands and moves one or more robots around Mars.

  • The world should be modelled as a grid with size m x n
  • Your program should read the input, update the robots, and print out the final states of the robots
  • Each robot has a position (x, y), and an orientation (N, E, S, W)
  • Each robot can move forward one space (F), rotate left by 90 degrees (L), or rotate

If I add a boolean auto_onboard_via_dpt column to the cohort_companies table, how can I ensure that at most one row has a true value for this column for a given company id?

To ensure that at most one row in the cohort_companies table has auto_onboard_via_dpt = true for a given company_id, you want to enforce a partial unique index (sometimes called a filtered unique index) at the database level.

Assuming you are using PostgreSQL (the most common DB for Elixir/Phoenix projects), you can do this with the following SQL:

CREATE UNIQUE INDEX unique_auto_onboard_via_dpt_per_company
ON cohort_companies (company_id)
WHERE auto_onboard_via_dpt IS TRUE;

Problem Statement

Multiverse wants to enhance their Mars Rover system with the following capabilities:

Part 1: Obstacle Detection

The Mars surface has obstacles that rovers must navigate around. Extend the system to:

  1. Add obstacle support: Modify the grid to include obstacle positions
  2. Collision detection: When a rover tries to move into an obstacle, it should stop at its current position (not move forward) but continue processing remaining commands
  3. Update input format: Obstacles should be specified after the grid dimensions
defmodule HtmlLintNative do
use Rustler, otp_app: :platform, crate: "platform_plugs_htmllintnative"
def add(_a, _b), do: error()
def lint(_html_string), do: error()
defp error(), do: :erlang.nif_error(:nif_not_loaded)
end
#[rustler::nif]
fn lint(env: Env, input: String) -> Result<Term, Error> {
let parse_errors = lint_html::lint(input);
return convert_errors(env, parse_errors);
}
fn convert_errors(env: Env, parse_errors: Vec<(u64, String)>) -> Result<Term, Error> {
if parse_errors.len() == 0 {
return Ok(ok().to_term(env));
} else {
@addrummond
addrummond / html_lint.ex
Last active March 17, 2021 09:10
Example HTML lint plug code
defmodule HtmlLintPlug do
require Logger
def init(opts), do: opts
def call(conn, _opts) do
Plug.Conn.register_before_send(conn, &lint/1)
end
defmodule Error do