This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let suffix n xs = List.toSeq xs |> Seq.skip (xs.Length - n) |> Seq.toList | |
let removeLast n xs = List.toSeq xs |> Seq.rev |> Seq.removeManyAt 0 n |> Seq.rev |> Seq.toList | |
let span fn xs = (List.takeWhile fn xs, List.skipWhile fn xs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
chunq :: Int -> [a] -> [[a]] | |
chunq _ [] = [] | |
chunq n xs = let (first, remaining) = splitAt n xs in first : chunq n remaining | |
transpoze :: [[a]] -> [[a]] | |
transpoze [] = [] | |
transpoze ([] : xss) = transpoze xss | |
transpoze ((x:xs) : xss) = (x : [h | (h:_) <- xss]) : transpoze (xs : [ t | (_:t) <- xss]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Collection { | |
func makeString(_ separator: String) -> String { makeString("", separator, "") } | |
func makeString(_ prefix: String, _ separator: String, _ suffix: String) -> String { | |
if isEmpty { | |
return prefix + suffix | |
} else { | |
return addString("", prefix, separator, suffix) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DROP VIEW IF EXISTS patient_room_view; | |
CREATE VIEW patient_room_view AS | |
SELECT | |
nt.room_number, | |
CASE | |
WHEN coalesce(jsonb_agg(tm.*) FILTER (WHERE tm.job_title = 'RN'), '{}') ->> 0 != '[null]' | |
THEN (coalesce(jsonb_agg(tm.*) FILTER (WHERE tm.job_title = 'RN'), '{}') ->> 0)::jsonb | |
ELSE '{}' | |
END | |
AS nurse, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION list_paginated_messages_by_priority(p text, o int, l int) | |
RETURNS TABLE(id bigint, sender_name text, recipient_name text, message_title text, current_page bigint, page_count bigint) | |
LANGUAGE SQL | |
BEGIN ATOMIC | |
WITH pagination_meta_data AS ( | |
SELECT *, | |
((ROW_NUMBER () OVER (ORDER BY id) - 1) / $3) + 1 AS current_page, | |
CEILING((COUNT(*) OVER ())::decimal / $3::decimal)::bigint AS page_count | |
FROM ( | |
SELECT *, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Suit(String symbol) { | |
Hearts("♡"), Clubs("♣"), Spades("♠"), Diamonds("♢"); | |
} | |
//the above generates... | |
sealed interface Suit permits Hearts, Clubs, Spades, Diamonds { | |
String symbol(); | |
} | |
record Hearts() implements Suit { | |
@Override |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Web Page</title> | |
<link rel="stylesheet" href="styles.css"> | |
<meta name="viewport" content="width=device-width"> | |
</head> | |
<body> | |
<main> | |
<header>header</header> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<E> List<List<E>> chunk(List<E> list, int size) { | |
int length = list.size(); | |
return IntStream.range(0, (length - 1) / size + 1) | |
.mapToObj(i -> list.subList(i *= size, length - size >= i ? i + size : length)) | |
.collect(Collectors.toList()); | |
} | |
<T, U> Map<T, U> zip(List<T> first, List<U> second) { | |
return IntStream.range(0, Math.min(first.size(), second.size())).boxed() | |
.collect(Collectors.toMap(first::get, second::get)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlinx.coroutines.* | |
import java.io.File | |
fun main() = runBlocking { | |
val start = System.nanoTime() | |
val input = File("file_path.txt").readText(Charsets.UTF_8) | |
val sequence = ">.*\n|\n".toRegex().replace(input, "") | |
val replacements = listOf( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
///Scan function that starts with the first element of the Sequence, like fold | |
extension Sequence { | |
func scan(_ combiner: (Element, Element) throws -> Element) rethrows -> [Element] { | |
var iterator = makeIterator() | |
guard let initial = iterator.next() else { | |
return [] | |
} | |
var firstIteration = true | |
var accumulator = initial | |
return try map { element in |
NewerOlder