Skip to content

Instantly share code, notes, and snippets.

View guersam's full-sized avatar

Jisoo Park guersam

  • Seoul, South Korea
View GitHub Profile
@guersam
guersam / ResourceAcquisitionTimeoutExample.scala
Created March 15, 2023 03:06
`ZIO#interruptible` can override a fiber's interruptibility inherited from its parent
//> using scala "3.2.2"
//> using dep "dev.zio::zio:2.0.10"
import zio.*
object ResourceAcquisitionTimeoutExample extends ZIOAppDefault {
val run =
ZIO.debug("Running...") *>
ZIO.acquireRelease(
ZIO.debug("Acquired")
@guersam
guersam / ThrottleShapeSpec.scala
Created March 1, 2023 12:45
ZStream#throttleShape test
//> using scala "3.2.2"
//> using dep "dev.zio::zio:2.0.9"
//> using dep "dev.zio::zio-test:2.0.9"
import zio.*
import zio.stream.*
import zio.test.*
import java.time.temporal.ChronoUnit
object ThrottleShapeSpec extends ZIOSpecDefault {
@guersam
guersam / ZIOSeleniumExample.scala
Last active November 8, 2022 05:40
ScalaCLI + ZIO + Selenium Example
//> using scala "3.2.1"
//> using lib "dev.zio::zio:2.0.3"
import zio.*
case class AppConfig(root: String)
object AppConfig:
val layer: ZLayer[Any, Nothing, AppConfig] =
@guersam
guersam / monkey-patch-vega-scenegraph.js
Last active July 26, 2022 06:41
Vite plugin for dependency monkey patching
import { createLogger } from 'vite';
export function monkeyPatchVegaScenegraph() {
const name = 'monkey-patch-vega-scenegraph';
const logger = createLogger('info', { prefix: `[${name}]` });
const logOptions = {timestamp: true};
const replaceCriteria = /touchmove\(evt\) \{\s*this\.fire/m;
@guersam
guersam / install-obsidian.sh
Last active November 23, 2021 02:54 — forked from shaybensasson/install-obsidian.sh
Installing Obsidian (an advanced markdown editor) on Ubuntu
#!/usr/bin/env bash
# see https://forum.obsidian.md/t/gnome-desktop-installer/499
set -euo pipefail
icon_url="https://cdn.discordapp.com/icons/686053708261228577/1361e62fed2fee55c7885103c864e2a8.png"
#dl_url=${1:-}
dl_url=$( curl -s https://api.github.com/repos/obsidianmd/obsidian-releases/releases/latest \
| grep "browser_download_url.*AppImage" | tail -n 1 | cut -d '"' -f 4 )

Keybase proof

I hereby claim:

  • I am guersam on github.
  • I am guersam (https://keybase.io/guersam) on keybase.
  • I have a public key ASCpi4lE8RcuK-hUUr5MFavzikvDnGPrPMjFfpumrW855go

To claim this, I am signing this object:

@guersam
guersam / lascala-http4s_2019-02-26.md
Last active February 26, 2019 12:20
http4s 서버에서 JSON 응답을 돌려주기까지

http4s에서 어떻게 IO#unsafeRunSync 없이 JSON 응답을 반환할 수 있는지 문의가 들어와서 보충설명 드립니다:

https://github.com/guersam/kcd2019/blob/v0.1.0/src/main/scala/com/guersam/kcd2019/web/ApiRoutes.scala#L28-L33

슬라이드에서 잠깐 보여드렸던 것처럼 http4s 서버는 Request[F] => F[Response[F]] 형태의 순수 함수입니다. 미들웨어나 루트 합성을 위해 KleisliOptionT같은 데이터 타입들이 추가로 쓰이기는 하지만 결국 Request에서 Response로 가는 순수 함수이고, 중간에 데이터베이스 연결 같은 이펙트가 발생할 수 있기 때문에 Request => Response 대신 Request => F[Response]와 같은 형태를 띄고 있다고 생각하시면 돼요. 아래같은 모듈이라고 생각하셔도 되겠네요.

trait HttpServer[F[_]] {
  def handleRequest(req: Request): F[Response]
}
@guersam
guersam / nthColumnLabel.scala
Last active February 16, 2019 14:48
Better functional implementation of excel-style column name generation in Scala https://blog.jooq.org/2015/12/08/3-reasons-why-you-shouldnt-replace-your-for-loops-by-stream-foreach/
// Using new collection library in Scala 2.13
def nthColumnLabel(n: Int): String =
Iterator
.unfold(n) {
case 0 => None
case m =>
val m2 = m - 1
Some((m2 % 26 + 'A').toChar, m2 / 26)
}
.mkString
@guersam
guersam / naiveuridecode.scala
Created October 30, 2018 01:07
Naively decode an arbitrary URI encoded string
#!/usr/bin/env amm
import $ivy.`org.typelevel::cats-core:1.4.0`
import cats.implicits._
import java.net.{URLEncoder, URLDecoder}
import scala.util.{Try, Success}
val charsets = List("utf-8", "x-windows-949")
@guersam
guersam / KoreanJasoDecomposer.scala
Last active October 18, 2018 08:11
한글 유니코드 자소 분리
object KoreanJasoDecomposer {
/**
* 한글 음절
*
* @param onset 초성
* @param nucleus 중성
* @param coda 종성
*/
case class Syllable(