Skip to content

Instantly share code, notes, and snippets.

View hovsater's full-sized avatar
🤟

Kevin Hovsäter hovsater

🤟
View GitHub Profile
@hovsater
hovsater / Day02.elm
Last active February 21, 2022 14:36
Solution to Advent of Code 2015 - Day 2 (https://adventofcode.com/2015/day/2)
module Day02 exposing (main)
import Html exposing (Html, div, strong, text)
partOne : Html ()
partOne =
div []
[ strong [] [ text "Part 1: " ]
, puzzleInput
@hovsater
hovsater / Day01.elm
Last active February 21, 2022 14:36
Solution to Advent of Code 2015 - Day 1 (https://adventofcode.com/2015/day/1)
module Main exposing (main)
import Html exposing (Html, div, strong, text)
partOne : Html a
partOne =
div []
[ strong [] [ text "Part 1: " ]
, puzzleInput |> parseInput |> findEndingFloor |> String.fromInt |> text
@hovsater
hovsater / bug.md
Last active October 22, 2021 16:25
Potential bug

Let's imagine a User model with a has many posts relationship. It has an associated scope to ensure we only get relevant posts (i.e., posts not yet deleted).

class User
  has_many :posts, -> { not_deleted }, inverse_of :user
end

class Post
 belongs_to :user, inverse_of: :posts
#!/usr/bin/env bash
# usage: anthonygitpaste 'git', 'log', '--oneline'
set -eo pipefail
if [ $# -eq 0 ]; then
echo "usage: must paste da codez"
exit 1
fi
def caesar([], _n), do: []
def caesar([head | tail], n) do
with lower = ?A,
upper = ?z + 1 do
[rem(head + n - lower, upper - lower) + lower | caesar(tail, n)]
end
end
@hovsater
hovsater / guess.exs
Created May 28, 2021 20:04
Guess the number!
defmodule Guess do
def make_guess(n, low..high), do: make_guess(n, low..high, div(low + high, 2))
defp make_guess(n, _range, guess) when guess == n, do: IO.puts(n)
defp make_guess(n, _low..high, guess) when guess < n do
with low = guess + 1,
guess = div(low + high, 2) do
IO.puts("Is it #{guess}")
make_guess(n, low..high, guess)
#!/usr/bin/env ruby
require 'find'
require 'pathname'
BREWFILE_NAME = Pathname.new(File.expand_path("../Brewfile.all", __FILE__))
begin
brewfile = File.open(BREWFILE_NAME, "w")
home = Pathname.new(ENV['HOME'])
require 'spec_helper'
require 'dry-validation'
module AllowList
NAMES = %w(john jane)
end
class Admin
SCHEMA = Dry::Validation.Params do
configure do
(* Write a function append : int list -> int list -> int list such that
append l1 l2 is the concatenation of l1 and l2. *)
let rec append l1 l2 =
let rec rev acc = function
| [] -> acc
| x::xs -> rev (x::acc) xs
in
let rec aux l = function
[] -> l
@hovsater
hovsater / split.ml
Last active October 14, 2020 12:37
(*
Write a function split : int list -> int list * int list such that split l = (front, back) where
l = back @ List.rev front and the length of back and front is List.length l / 2
or List.length l / 2 + 1
*)
let split l =
let cutpoint = List.length l / 2 in
let rec aux count back = function
[] -> ([], [])
| x::xs -> if count < cutpoint