Skip to content

Instantly share code, notes, and snippets.

View BenFradet's full-sized avatar
💭
Engineering @47deg

Ben Fradet BenFradet

💭
Engineering @47deg
  • Marseille area, France
View GitHub Profile
#[cfg(feature = "ssr")]
pub async fn fetch(search_term: &str) -> Vec<String> {
todo!();
}
#[derive(PartialEq, Properties, Clone)]
pub struct InputProps {
pub on_search: Callback<String>,
}
@BenFradet
BenFradet / macro.rs
Last active February 21, 2024 18:17
named fields macro
#[macro_export]
macro_rules! enum_variants_as_structs {
(
$(#[$meta_enum:meta])*
enum $Name:ident {
// haven't found a way to propagate enum meta's to variants because
// "meta-variable x repeats N times, but y repeats M times"
$($(#[$meta_variant:meta])* $Variant:ident { $($f:ident: $ty:ty),* }),* $(,)?
}
) => {
trait KV[F[_], A] {
def lookup(k: K): EitherT[F, E, V[A]]
}
object KV {
def impl[F[_]: Monad, A: Parseable]: KV[F, A] = ???
def cached[F[_]: Monad, A: Parseable](implicit C: Cache[F, K , V[A]]): KV[F, A] = ???
}
diff --git a/github4s/src/test/scala/github4s/integration/ReposSpec.scala b/github4s/src/test/scala/github4s/integration/ReposSpec.scala
index beeb7be..297990d 100644
--- a/github4s/src/test/scala/github4s/integration/ReposSpec.scala
+++ b/github4s/src/test/scala/github4s/integration/ReposSpec.scala
@@ -16,8 +16,10 @@
package github4s.integration
+import cats.data.EitherT
import cats.effect.IO
run() {
local repo=$1
local branch_name="update/scalafmt-core-${new_version}"
git clone https://github.com/$owner/$repo.git
cd $repo
git checkout -b $branch_name
sed -i "s/${old_version}/${new_version}/g" .scalafmt.conf
sed -i 's/scalafmtCheck;/scalafmtCheckAll;/g' build.sbt
@BenFradet
BenFradet / EntityDecoder.scala
Last active April 10, 2020 20:45
Chaining decoders
import cats.effect.{IO, Sync}
import fs2.Stream
import io.circe.{Decoder, Encoder, Json}
import io.circe.generic.semiauto._
import io.circe.syntax._
import org.http4s.{EntityDecoder, EntityEncoder, Response, Status}
import org.http4s.circe._
sealed trait A
final case class B(error: String) extends A
@BenFradet
BenFradet / db.scala
Last active November 19, 2019 08:08
trait Algebra[F[_]] {
def find(request: Req): F[List[Res]]
}
// this is the real interpreter, it uses https://github.com/tpolecat/doobie but that's an implementation detail
class Interpreter[F[_]: Monad](val xa: Transactor[F])
extends Algebra[F] {
import SQL._
def find(request: Req): F[List[Res]] =
@BenFradet
BenFradet / gsettings.sh
Created October 6, 2019 15:09
Hide gnome-terminal 3.32+ ugly default bar
gsettings set org.gnome.Terminal.Legacy.Settings headerbar false
def splitIssues(
n: NonEmptyList[EnrichmentStageIssue]
): (List[EnrichmentFailure], List[SchemaViolation]) =
n.foldLeft((List.empty[EnrichmentFailure], List.empty[SchemaViolation])) { case ((es, ss), i) =>
i match {
case e: EnrichmentFailure => (e :: es, ss)
case s: SchemaViolation => (es, s :: ss)
}
}
<div class="navbar navbar-default"><ul class="navbar-header"><li class="navbar-brand active">Home</li><li class="navbar-brand active">Hero repo stars</li><li class="navbar-brand active">Top N repos stars</li><li class="navbar-brand active">Quaterly opened PRs</li><li class="navbar-brand active">Monthly opened PRs</li></ul></div>