Skip to content

Instantly share code, notes, and snippets.

@Akii
Akii / StarRating.vue
Created Feb 17, 2020
Probably accessible star rating component for Vue.
View StarRating.vue
<template>
<div>
<span class="visually-hidden" :aria-hidden="!readonly">{{ starLabel(value) }}</span>
<span v-for="i in [1, 2, 3, 4, 5]" :key="i" :aria-hidden="readonly">
<label class="visually-hidden">
{{ starLabel(i) }}
<input
type="radio"
View Stuff.ex
defmodule Stuff do
use Combine
defmodule ContentRangeRequest do
@moduledoc """
Represents the Range header sent by the client
"""
defstruct key: :id, id: nil, offset: 0, limit: 0, order: :asc
end
View Parser.ex
def parse_range(range, max_limit \\ 500) do
range_p =
either(
many1(alphanumeric()) |> ignore(space()) |> string() |> ignore(char(";")),
many1(alphanumeric()) |> ignore(char(";"))
)
limit_p = fn a -> a |> ignore(string("limit ")) |> integer() |> ignore(char(";")) end
offset_p = fn a -> a |> ignore(string("offset ")) |> integer() |> ignore(char(";")) end
@Akii
Akii / downtimes.ex
Created Jan 8, 2020
GenServer for scale
View downtimes.ex
defmodule Elescore.Projection.Downtimes do
use GenServer
def start_link() do
GenServer.start_link(__MODULE__, nil, name: __MODULE__)
end
def init(_arg) do
# We wait a bit for the disruption projection
Process.send_after(self(), :calculate_downtimes, 30_000)
@Akii
Akii / Submit.hs
Created Oct 19, 2019
Must look like magic for some folks
View Submit.hs
executeForm :: FormV2 -> Bool -> PageM [TagTree LBS.ByteString]
executeForm FormV2 {..} doSubmit = do
initRequest
personalPage personal
disabilitiesPage disabilities
outwardMeetingPoints <- executeOutwardConnection outwardTrainRide (isJust returnTrainRide)
returnMeetingPoints <- executeReturnConnection returnTrainRide
meetingPointsPage outwardMeetingPoints returnMeetingPoints
@Akii
Akii / DOMTransformation.hs
Created Oct 19, 2019
TagSoup removing all script tags and adding a base tag
View DOMTransformation.hs
import qualified Data.ByteString.Lazy as LBS
import Text.HTML.TagSoup
import Text.HTML.TagSoup.Tree
addBaseTag :: LBS.ByteString -> [TagTree LBS.ByteString] -> [TagTree LBS.ByteString]
addBaseTag href = transformTree f
where
f (TagBranch "head" attrs subTrees) = [TagBranch "head" attrs (baseTag : subTrees)]
f x = [x]
@Akii
Akii / ConnectionParser.hs
Created Oct 13, 2019
Parsing in Haskell is awesome
View ConnectionParser.hs
-- The goal was to parse a text describing the connection which is used by screen readers:
-- Strecke von Karlsruhe Hbf, Abfahrtszeit 11:59 von Gleis 3 nach Berlin Hauptbahnhof, Ankunftszeit 18:03 auf Gleis 2, mit ICE 370
-- Translated:
-- Connection from Karlsruhe Hbf, Departuretime 11:59 from track 3 to Berlin Hauptbahnhof, Arrivaltime 18:03 on track 2, with ICE 370
data Connection
= Departure
{ departStation :: Text
, departAt :: Text
@Akii
Akii / better_slack.js
Last active Jun 24, 2019
Basically a starting point of hiding channels and blocking users in Slack
View better_slack.js
document.addEventListener("DOMContentLoaded", function() {
let hiddenChannels = ['general']
let blockedUsers = ['Slackbot']
let customCss = `
.p-channel_sidebar__static_list div[role="listitem"]:empty { display: none; }
`
hiddenChannels.concat(blockedUsers).forEach(it => {
customCss += `a[aria-label~="${it}"] { display: none; }\n`
View ibnr_mapping.csv
IBNR Name Übersicht Bahnhöfe Name Haltestellendaten dist f=wrong
8000491 Ahlten (Han) Altenglan 3 f
8007821 Aldingen Üdingen 2 f
8003331 Alheim-Heinebach Kleinsteinbach 6 f
8013471 Allee-Center Leipzig Böhlen(Leipzig) 9 f
8070185 Allermöhe Alveslohe 4 f
8011017 Alte Wöhr Altefähr 2 f
8000446 Anderten-Misburg Ahrensburg 6 f
8012996 Attilastraße Silberstraße 5 f
8010011 Auerbach (b Mosbach) Auerbach(V) ob Bf 5 f
View Body.hs
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE ViewPatterns #-}