Skip to content

Instantly share code, notes, and snippets.

@shajra
shajra / before_monads.md
Last active August 29, 2015 14:11
Before jumping into monads. . .

Before Jumping into Monads

A lot of people come from popular languages that tout being "object-oriented" and they hear about something called "monads" but haven't found the time to figure them out completely. They look for a simple explanation, but run into one or more of the following problems:

  • too many concepts explained at once
  • vague explanations (including analogies that break)
@shajra
shajra / HttpCommand.scala
Created February 26, 2015 18:28
some snippets about retry abstractions in Scala
package shajra.http.client
import scala.concurrent.duration.Duration
import scalaz.{Functor, NonEmptyList}
private[client] sealed abstract class HttpCommand[C, E, O] {
@shajra
shajra / maxims.md
Last active September 23, 2024 08:34
Maxims for Software Development

Basic Humanity

  • Everyone is safe, respected, and treated with empathy and dignity.
  • Pay is competitive, fair, and relatively transparent.
  • Capitalize on a culture of looking at other jobs in other companies.

Organization

  • Titled leaders deeply respect their implicit influence.
  • Managers of technical workers are always highly technically skilled.
@shajra
shajra / gist:d383179fbf260b4e5978
Last active August 29, 2015 14:27 — forked from nkpart/gist:cc852b43d948a33a04c8
Using ghcid inside of emacs
Pieces you need:
* emacs
* ghcid
ghcid needs to know the height of the terminal, we'll set it explicitly
height = (window-height) - (scroll-margin) - 1
set this height as your term-buffer-maximum-size
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
import Control.Lens
import Data.Maybe
import Data.Monoid
data Constant a b =
Constant a
@shajra
shajra / twitter.scala
Created November 2, 2015 20:02 — forked from bryce-anderson/twitter.scala
slapped together bits of a basic http4s interface to the Twitter streaming API. OAuth not included.
// a simple process1 that splits the frames up based on a "\r\n" sequence of chars
val partitioner = {
import java.util.regex.Pattern
import scalaz.stream.process1
import scalaz.std.string._
val pattern = Pattern.compile("\r\n")
process1.repartition { s: String =>
pattern.split(s, -1)
@shajra
shajra / church.py
Last active December 8, 2015 17:04
Church-encodings in Python
# coding=UTF-8
# Python Goes To Church
# =====================
# What would Python be like if all we had was simple (single argument) lambda
# expressions? We could write some helpful functions like these:
id = lambda a: a
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
import Control.Monad.IO.Class
import Control.Monad.Trans.Class
import Prelude hiding (log)
--------------------------------------------------------------------------------
-- The API for cloud files.
class Monad m => MonadCloud m where
saveFile :: Path -> Bytes -> m ()
@shajra
shajra / Pools.scala
Created February 28, 2016 23:30
using phantom types to keep track of thread pool types carefully
import java.util.concurrent.ExecutorService
import scalaz.Maybe
import scalaz.syntax.maybe._
final case class Pools(cpu: Maybe[Pool[Pool.Cpu]], io: Maybe[Pool[Pool.Io]])
object Pools {
def none: Pools = Pools(Maybe.empty, Maybe.empty)
@shajra
shajra / tagless.scala
Created March 10, 2016 05:47
Example of using a tagless encoding (rough draft)
package shajra.tagless
import argonaut.{ HCursor, DecodeResult, DecodeJson, Parse }
import argonaut.Argonaut.jString
import scalaz._
import scalaz.Isomorphism.<~>
import scalaz.syntax.monad._