Skip to content

Instantly share code, notes, and snippets.

View loicknuchel's full-sized avatar
👨‍💻
Explore your database => https://azimutt.app

Loïc Knuchel loicknuchel

👨‍💻
Explore your database => https://azimutt.app
View GitHub Profile
@loicknuchel
loicknuchel / pg_catalog_schema.js
Last active July 13, 2022 20:50
Generate AML from PostgreSQL documentation
// to execute in the console of https://www.postgresql.org/docs/current/catalog-pg-class.html
// and paste the copied result into https://azimutt.app ;)
function generateTableAml() {
const url = window.location.href
const table_schema = 'pg_catalog'
const table_name = document.querySelector('h2.title .structname').textContent
const table_description = document.querySelector('p').textContent
const column_rows = Array.from(document.querySelector('.table-contents').querySelectorAll('tbody tr'))
const columns = column_rows.map(r => {
return {
@loicknuchel
loicknuchel / tailwind-class-check.js
Created February 4, 2022 23:39
Check if tailwind classes are correctly generated
/*
Using tailwind 3 CLI when generating dynamic classes can sometimes be quite painful as you never know which classes may be missing.
Not anymore with this script!
It gets your stylesheets, then all your classes in HTML and print classes that are present in HTML but not in stylesheets.
*/
function identifyMissingClasses() {
getStyles().then(styles => {
const classes = getClassCounts(document.getElementsByTagName('html')[0])
const matches = matchClassesInStyles(styles, classes)
const misses = filterMissingClasses(matches)
@loicknuchel
loicknuchel / DemoSpec.scala
Last active November 11, 2020 14:50
SQL DSL: use shapeless to require correct Put instances
import cats.effect.{ContextShift, IO}
import doobie.syntax.connectionio._
import doobie.syntax.string._
import doobie.util.Put
import doobie.util.fragment.Fragment
import doobie.util.fragment.Fragment.const0
import doobie.util.transactor.Transactor
import org.scalatest.BeforeAndAfterEach
import org.scalatest.funspec.AnyFunSpec
import org.scalatest.matchers.should.Matchers
@loicknuchel
loicknuchel / logs_compiler_stackoverflow
Last active April 2, 2019 06:58
compiler stack overflow
When building: https://github.com/loicknuchel/gospeak
If I do `sbt clean`, `sbt compile`, `sbt test` it works
But when I do `sbt clean test` it does not :(
Any idea how to troubleshoot ?
➜ gospeak git:(master) sbt clean test
[info] Loading global plugins from /home/lkn/.sbt/1.0/plugins
[info] Loading settings for project gospeak-build from plugins.sbt ...
[info] Loading project definition from /home/lkn/workspace/perso/gospeak/project
[info] Loading settings for project global from build.sbt ...
@loicknuchel
loicknuchel / Migrator.scala
Created November 8, 2018 12:43
Case class migration
trait Migrator[A, B] {
def migrate(a: A): B
}
object Migrator {
def apply[A, B](implicit m: Migrator[A, B]): Migrator[A, B] = m
implicit def product[A, B, AR <: HList, BR <: HList, Common <: HList, Added <: HList, Unaligned <: HList]
(implicit
@loicknuchel
loicknuchel / CaseClassBoilerplate.scala
Created October 1, 2018 08:03
Try to remove boilerplate code created by many similar case classes
import java.sql.Timestamp
import java.time.Instant
import slick.basic.DatabaseConfig
import slick.jdbc.JdbcProfile
import slick.lifted.ProvenShape
import scala.concurrent.ExecutionContext.Implicits.global
import scala.util.{Failure, Success, Try}
@loicknuchel
loicknuchel / Result.txt
Last active September 18, 2018 14:05
Error with scalacheck on shrinking classes with assert
Testing started at 15:02 ...
Id.apply(7982e330-7daf-4cbd-a299-67af73ad24de)
Generated: Test(Id(7982e330-7daf-4cbd-a299-67af73ad24de),,464053996)
Id.apply(7982e330-7daf-4cbd)
TestFailedException was thrown during property evaluation.
Message: TestSpec.this.Id.isValid(Id.this.value) was false Invalid Id: 7982e330-7daf-4cbd
Location: (TestSpec.scala:16)
Occurred when passed generated values (
@loicknuchel
loicknuchel / ImplicitClassResolutionFail.scala
Last active October 16, 2017 12:51
How implicit class resolution works ?
import org.scalatest.{FunSpec, Matchers}
object Implicits {
implicit class SeqEitherExtension[E, A](val elt: Seq[Either[E, A]]) extends AnyVal {
def partition: (Seq[E], Seq[A]) = {
val (left, right) = elt.partition(_.isLeft)
(left.collect { case Left(e) => e }, right.collect { case Right(a) => a })
}
}
import scala.util.{Failure, Success, Try}
object ValidationMonad {
sealed abstract class Validation[+A] {
def isValid: Boolean
def get: A
def getOrElse[B >: A](default: => B): B
def map[B](f: A => B): Validation[B]
def flatMap[B](f: A => Validation[B]): Validation[B]
}