Skip to content

Instantly share code, notes, and snippets.

@shajra
shajra / ReadV.scala
Last active March 27, 2016 22:28
I've found this useful for accessing nested data with accumulated error reporting.
package shajra.extn.scalaz
import scalaz.
{ \/, Arrow, Applicative, Foldable, Functor, IsomorphismApplicative,
IsomorphismFunctor, IsomorphismMonoid, IsomorphismPlus,
IsomorphismSemigroup, Kleisli, Maybe, Monoid, NonEmptyList, Plus,
ProChoice, Semigroup, Validation }
import scalaz.Isomorphism.
{ <=>, <~>, <~~>, IsoBifunctorTemplate, IsoFunctorTemplate, IsoSet }
@shajra
shajra / ContentNegotiate.scala
Last active January 30, 2021 20:35
Very unpolished (and likely to change) stab at content negotiation in HTTP4S
package shajra.extn.http4s.core
import org.http4s.
{ Charset, CharsetRange, ContentCoding, EntityEncoder, HasQValue, Header,
HeaderKey, Headers, LanguageTag, MediaRange, MediaType, QValue }
import org.http4s.headers.
{ Accept, `Accept-Encoding`, `Accept-Charset`, `Accept-Language`,
`Content-Encoding`, `Content-Type` }
import org.http4s.util.CaseInsensitiveString
@shajra
shajra / nix-install-multiuser.log
Last active May 14, 2016 03:27
This install script (second file) used to work months ago, but now it gives me an error (first file)
The user `nixbld1' is already a member of `nixbld'.
The user `nixbld2' is already a member of `nixbld'.
The user `nixbld3' is already a member of `nixbld'.
The user `nixbld4' is already a member of `nixbld'.
The user `nixbld5' is already a member of `nixbld'.
The user `nixbld6' is already a member of `nixbld'.
The user `nixbld7' is already a member of `nixbld'.
The user `nixbld8' is already a member of `nixbld'.
The user `nixbld9' is already a member of `nixbld'.
The user `nixbld10' is already a member of `nixbld'.
{-# LANGUAGE NoImplicitPrelude #-}
import qualified Prelude as P
main :: P.IO ()
main = P.putStrLn "Test suite not yet implemented"
a :: P.Maybe P.Bool
package com.work.learn
package typeclass
trait Functor[F[_]] {
def map[A, B](fa: F[A])(f: A => B): F[B]
}
object Functor {
def pipeline_update:
{
"name": .name,
"template": "c12e-ci",
"label_template": (.name + "-${COUNT}"),
"enable_pipeline_locking": false,
"materials": [
{
"type": "git",
"attributes": {
package shajra.learn
import shajra.learn.typeclass.Functor
import shajra.learn.typeclass.Functor.Syntax._
trait Mu[F[_]] {
def fold[X](k: F[X] => X): X
trait Translate[A, B] {
def apply(a: A): B
}
trait TranslateSyntax {
implicit class TranslateOps[A](a: A) {
def translate[B](implicit tr: Translate[A, B]): B = tr(a)
}
}
@shajra
shajra / ReadV.hs
Created July 20, 2016 06:05
trying to see how haskell-lens can help; pointers welcome
{-# LANGUAGE
FlexibleInstances
, GeneralizedNewtypeDeriving
, NoImplicitPrelude
, OverloadedStrings
, RankNTypes
#-}
module C12E.Validation.ReadV where
@shajra
shajra / readfile
Last active September 25, 2018 14:22
Real-world exception handling in Haskell that seems like overkill for this simple example
#!/usr/bin/env stack
-- stack --install-ghc runghc --package safe-exceptions --package lens --package mtl
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE ConstraintKinds #-}
{-# OPTIONS_GHC -Wall -Werror #-}
import Control.Exception (IOException)