Skip to content

Instantly share code, notes, and snippets.

View lhns's full-sized avatar

Pierre Kisters lhns

View GitHub Profile
@kubukoz
kubukoz / .scalafmt.conf
Last active November 5, 2024 11:16
How to disable significant indentation in Scala
runner.dialect = scala3
runner.dialectOverride.allowSignificantIndentation = false
# allows `if x then y`
runner.dialectOverride.allowQuietSyntax = true
#!/bin/sh
set -e -o pipefail
database="$1"
stat "$database"
[ -s "$database" ]
cp "$database" "${database}.bak"
sqlite3 "$database" -cmd ".mode insert" -cmd ".output dump_all.sql" -cmd ".dump" ".exit"
cat dump_all.sql | grep -v TRANSACTION | grep -v ROLLBACK | grep -v COMMIT >dump_all_notrans.sql
rm "$database"
sqlite3 "$database" ".read dump_all_notrans.sql"
/*
* Copyright 2020 Daniel Spiewak
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@comp500
comp500 / fabricserversidemods.md
Last active September 3, 2024 03:23
Useful Fabric server side mods
sealed trait Path
case class Field(name: String, child: Option[Path]) extends Path {
override def toString: String = child match {
case None => name
case Some(path) => s"$name.$path"
}
}
@johnynek
johnynek / dotty_list.scala
Last active September 7, 2024 15:14
Implementation of linked list using dotty features (opaque type, union types, extension methods, type lambda).
// unfortunately
// opaque type Fix[F[_]] = F[Fix[F]]
// won't work (no recursion in opaque type), but this implementation is safe, but scary due to asInstanceOf
object FixImpl {
type Fix[F[_]]
inline def fix[F[_]](f: F[Fix[F]]): Fix[F] = f.asInstanceOf[Fix[F]]
inline def unfix[F[_]](f: Fix[F]): F[Fix[F]] = f.asInstanceOf[F[Fix[F]]]
}
import $ivy.`io.circe::circe-parser:0.11.1`
import io.circe._, io.circe.parser._, io.circe.syntax._
for {
input <- parse(repl.clipboard.read).right
toAdd <- parse("""{"new_field": "added programatically"}""").right
} repl.clipboard.write(input.deepMerge(toAdd).toString)
@jdegoes
jdegoes / fpmax.scala
Created July 13, 2018 03:18
FP to the Max — Code Examples
package fpmax
import scala.util.Try
import scala.io.StdIn.readLine
object App0 {
def main: Unit = {
println("What is your name?")
val name = readLine()
object game {
case class Lens[S, A](set: A => S => S, get: S => A) { self =>
def >>> [B](that: Lens[A, B]): Lens[S, B] =
Lens[S, B](
set = (b: B) => (s: S) => self.set(that.set(b)(self.get(s)))(s),
get = (s: S) => that.get(self.get(s))
)
}
case class Prism[S, A](set: A => S, get: S => Option[A]) { self =>
@lhns
lhns / universalScript.scala
Last active December 1, 2022 14:24
Cross platform scripts (scala script)
def universalScript(shellCommands: String,
cmdCommands: String,
shebang: Boolean): String = {
Seq(
if (shebang) "#!/usr/bin/env sh" else "",
"@ 2>/dev/null # 2>nul & echo off & goto BOF\r",
":",
shellCommands.replaceAll("\r?\n", "\n"),
"exit",
Seq(