Skip to content

Instantly share code, notes, and snippets.

View hovsater's full-sized avatar
🤟

Kevin Hovsäter hovsater

🤟
View GitHub Profile
View vim.dterc
alias w 'save'
alias wq 'save; quit'
alias q 'quit'
alias q! 'quit -f'
set statusline-left ' %i%S%f%s%m%s%r%s%M'
def-mode -u vi-normal
bind -T vi-normal j down
bind -T vi-normal k up
View cursed_ruby.rb
def score(rolls) = score_helper(0, 1, rolls.reverse)
def score_helper(sum, frame, remaining)
case remaining
in 10, 10, x if frame == 10 && x <= 10 then sum + 20 + x
in 10, x, y if frame == 10 && x + y <= 10 then sum + 10 + x + y
in x, y, z if frame == 10 && x + y == 10 && z <= 10 then sum + x + y + z
in x, y if frame == 10 && x + y < 10 then sum + x + y
in 10, x, y, *rest then score_helper(sum + 10 + x + y, frame + 1, [x, y, *rest])
in x, y, z, *rest if x + y == 10 && z <= 10 then score_helper(sum + 10 + z, frame + 1, [z, *rest])
in x, y, *rest if x + y <= 10 then score_helper(sum + x + y, frame + 1, rest)
View BowlingScore.fs
let score game =
let rec aux sum frame =
function
| 10 :: 10 :: [ x ] when frame = 10 && x <= 10 -> Some(sum + 20 + x)
| 10 :: x :: [ y ] when frame = 10 && x + y <= 10 -> Some(sum + 10 + x + y)
| x :: y :: [ z ] when frame = 10 && x + y = 10 && z <= 10 -> Some(sum + 10 + z)
| x :: [ y ] when frame = 10 && x + y < 10 -> Some(sum + x + y)
| 10 :: x :: y :: rest -> aux (sum + 10 + x + y) (frame + 1) (x :: y :: rest)
| x :: y :: z :: rest when x + y = 10 && z <= 10 -> aux (sum + 10 + z) (frame + 1) (z :: rest)
View test.rb
class Test
FOO = 1
BAR = 'bar'
def call
end
end
@hovsater
hovsater / day_01.clj
Created July 27, 2023 21:40
Solution to Advent of Code year 2022, day 1.
View day_01.clj
(ns advent-of-code-year-2022.day-01
"Advent of Code - Solution to year 2022, day 1."
(:require
[clojure.string :as str]))
(def sample-input
"1000
2000
3000
@hovsater
hovsater / day01.odin
Last active July 19, 2023 15:14
Solution to part 1 of Advent of Code 2018 (See https://adventofcode.com/2018/day/1)
View day01.odin
package main
import "core:io"
import "core:strings"
import "core:testing"
freq :: proc(stream: io.Stream) -> (res: int) {
base :: 10
sign := 1
num: int
View hang.go
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
s := bufio.NewScanner(os.Stdin)
@hovsater
hovsater / change-theme.sh
Last active June 6, 2023 18:41
Change Zed theme automatically based on macOS appearance
View change-theme.sh
#!/usr/bin/env sh
set -e
dark_theme="Andromeda"
light_theme="Solarized Light"
while true; do
if defaults read -g AppleInterfaceStyle &>/dev/null; then
if [ $(< $HOME/.current-theme) = "dark" ]; then
continue;
@hovsater
hovsater / gist:a0b1c26ead82e49bb9f07d23a1ba5f8c
Created April 29, 2023 17:21
Poor Man's version of finding dead code (specifically Ruby constants)
View gist:a0b1c26ead82e49bb9f07d23a1ba5f8c
grep -REho --include \*.rb '\b[A-Z_]+\b\s*=' . | tr -d '=' | cut -d' ' -f1 | sort | uniq -u | xargs -I{} bash -c 'if [[ $(grep -Rhow --include \*.rb "{}" . | wc -l) -eq 1 ]] ; then echo {} ; fi'
@hovsater
hovsater / Day05.elm
Created April 22, 2023 06:57
Advent of Code 2022 - Day 5 (using `elm/parser`)
View Day05.elm
module Year2022.Day05 exposing (..)
import Aoc.Problem exposing (Answer(..), Input, Solution)
import Array exposing (Array)
import List.Extra as List
import Parser exposing ((|.), (|=), Parser, Step(..), andThen, chompIf, chompWhile, getChompedString, int, keyword, loop, map, oneOf, succeed, symbol)
type alias Crate =
String