Skip to content

Instantly share code, notes, and snippets.

@shajra
shajra / endo.scala
Created March 29, 2014 19:34
could this be cleaner?
def setFromArgs(args: Args): Settings => Settings = {
val input =
args optional "input" map { i =>
{ s: Settings => s copy (inputBasePath=InputBasePath(i)) } endo
} orZero
val dataCenters =
(args list "data-centers" some) filterNot { _.isEmpty } map { dcs =>
{ s: Settings => s copy (dataCenters = dcs map DataCenter.apply) } endo
@shajra
shajra / equational_reasoning.md
Last active August 29, 2015 13:57
I found myself wanting to explain this to a few people I work with; interested in feedback

Reasoning with Functional Programming

the point of this post

We often accept for granted that functional programming (FP) helps us reason about our programs more. This is often attributed to "referential transparency" or "equational reasoning" with only a cursory explanation.

With this post, I'd like to give a slightly more involved illustration for how the referential transparency of functional programming helps us reason

@shajra
shajra / local_func.el
Created May 18, 2014 22:38
What's a recommend refactoring for this Emacs lisp snippet?
; I know this is super naive, but I haven't been in a Lisp for some time, and I
; haven't had to think about how best to deal with a Lisp-1.
;
; Really, all I'm trying to do here is define a local function so it's easier
; to read in the mapcar call.
;
(defun tnks--gnus-ident (idents)
(let
((f (lambda (ident) (list (car ident) nil (cdr ident) nil nil nil))))
import scalaz._
import Scalaz._
import Free._
/** "Pure" interactions with a console. */
sealed trait Console[+A]
case class GetLine[A](k: String => A) extends Console[A]
case class PutLine[A](s: String, a: A) extends Console[A]
object Console {
@shajra
shajra / Setup.hs
Created June 30, 2014 23:06 — forked from hvr/Setup.hs
import Control.Exception
import Control.Monad
import Data.Maybe
import Data.Version
import Distribution.PackageDescription (PackageDescription(..), HookedBuildInfo, GenericPackageDescription(..))
import Distribution.Package (PackageIdentifier(..))
import Distribution.Simple (defaultMainWithHooks, simpleUserHooks, UserHooks(..))
import Distribution.Simple.LocalBuildInfo (LocalBuildInfo(..))
import Distribution.Simple.Setup (BuildFlags(..), ConfigFlags(..))
import Distribution.Simple.Utils (die)
@shajra
shajra / alacarte.scala
Last active May 6, 2019 20:53 — forked from runarorama/gist:a8fab38e473fafa0921d
"datatypes a la carte" pattern in Scala
sealed trait Interact[A]
case class Ask(prompt: String)
extends Interact[String]
case class Tell(msg: String)
extends Interact[Unit]
trait Monad[M[_]] {
def pure[A](a: A): M[A]
@shajra
shajra / objalg.scala
Last active August 29, 2015 14:03 — forked from jdanbrown/gist:4747205
#!/bin/bash
exec ~/src/scala/bin/scala -savecompiled "$0" "$@"
!#
// Example of object algebras, based on the scala example at http://ropas.snu.ac.kr/~bruno/oa/
// type Term = ∀A,O. O[A] -> A
trait Term[O[_]] {
def apply[A](o: O[A]): A
}
@shajra
shajra / free1.scala
Last active August 29, 2015 14:03 — forked from danclien/step1.scala
// Implementing functor manually
import scalaz._, Scalaz._, Free.liftF
sealed trait TestF[+A]
case class Foo[A](o: A) extends TestF[A]
case class Bar[A](h: (Int => A)) extends TestF[A]
case class Baz[A](h: (Int => A)) extends TestF[A]
implicit def testFFunctor[B]: Functor[TestF] = new Functor[TestF] {

BuiltWith Firehose API (DRAFT)

This is a draft proposal for BuiltWith's Firehose web service API. It leans a bit on HTTP and uses some status codes from spec extensions and custom media types. If a user agent only accepts application/json, the API should still work as each representation is still JSON. The only thing a user agent would lose is a clear indication of the contract of the payload, which specifies how to parse it beyond just JSON.

This covers enough to give a feel for the API, but probably isn't yet comprehensive for all the edge cases.

Submitting a Request

Request

@shajra
shajra / nix-store.log
Created September 3, 2014 21:03
Why isn't nix-store working here?
shajra bagel /nix/var/nix/profiles
$ readlink -f /nix/var/nix/profiles/chroot/bin/bash
/nix/store/q5wfq0i6w4p6a7155p4hia6p3n8rk7aq-bash-4.2-p47/bin/bash
shajra bagel /nix/var/nix/profiles
$ nix-store -qR /nix/var/nix/profiles/chroot/bin/bash
error: path ‘/nix/var/nix/profiles/chroot/bin/bash’ is not in the Nix store