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 / 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 December 17, 2024 02:57
한글 유니코드 자소 분리
object KoreanJasoDecomposer {
/**
* 한글 음절
*
* @param onset 초성
* @param nucleus 중성
* @param coda 종성
*/
case class Syllable(
@guersam
guersam / check-domain.sc
Created June 20, 2018 04:54
Check domain name availability with whois and notify via slack
#!/usr/bin/env amm
import $ivy.`com.github.gilbertw1::slack-scala-client:0.2.3`
import slack.api.BlockingSlackApiClient
import akka.actor.ActorSystem
import scala.util.Try
def sendSlackNotification(msg: String)(implicit sys: ActorSystem): Unit = {
val token = "<token>" // TODO parameterize
@guersam
guersam / App.scala
Created March 18, 2018 08:44 — forked from notxcain/App.scala
Onion Architecture using Finally Tagless and Liberator
import cats.data.{ EitherT, State }
import cats.implicits._
import cats.{ Monad, ~> }
import io.aecor.liberator.macros.free
import io.aecor.liberator.syntax._
import io.aecor.liberator.{ ProductKK, Term }
@free
trait Api[F[_]] {
def doThing(aThing: String, params: Map[String, String]): F[Either[String, String]]
@guersam
guersam / fs2Cp949Decoder.scala
Last active August 9, 2017 12:06
fs2 cp949 decoder
import java.nio.charset.Charset
import fs2.{Chunk, Pipe, Pull, Pure, Stream}
object Fs2Util {
val cp949Charset: Charset = Charset.forName("cp949")
def cp949Decode[F[_]]: Pipe[F, Byte, String] =
_.chunks.through(cp949DecodeC)
@guersam
guersam / _Main.scala
Created April 27, 2017 08:46
cross-libraries optimization in Scala 2.12
object Main {
val xs = (1 to 10).toList
def simple(): List[Int] =
xs.map { i =>
i + 1
}
}