Skip to content

Instantly share code, notes, and snippets.

View aaronlevin's full-sized avatar

Aaron Levin aaronlevin

View GitHub Profile
@aaronlevin
aaronlevin / gist:3217751
Created July 31, 2012 15:18
(potentially bad) Example of decorator defined as class method
class Density(object):
def __init__(self, data, bw=None):
""" class definitions
"""
self.maxmin['maxima'] = []
self.maxmin['minima'] = []
def new_values_for_maxmin_validator(method):
"""This is the decorator
@aaronlevin
aaronlevin / canigetawitness.scala
Created September 12, 2013 19:25
A question came up during a talk I gave about how to provide a witness for the below `Functor` implementation. This is one (terrible) way to do it and should highlight how implicits can be used to provide the witness. There are definitely better ways to do this.
sealed trait Option2[+A]
case object None2 extends Option2[Nothing]
case class Some2[A](value: A) extends Option2[A]
trait Functor[F[_]] {
def map[A,B](f: A => B): F[A] => F[B]
}
@aaronlevin
aaronlevin / whyscala.md
Last active January 4, 2016 04:19
LiftWeb++

xxx typeOf[B] = org.weirdcanada.distro.data.ArtistData
xxx calling: object bState extends RequestVar[B](implicitly[HasEmpty[B]].empty)
xxx B: ArtistData(,,,,Band,,,alberta,canada)

(next iteration)

xxx typeOf[B]: org.weirdcanada.distro.data.PublisherData
xxx calling: object bState extends RequestVar[B](implicitly[HasEmpty[B]].empty)
xxx B: ArtistData(,,,,Band,,,alberta,canada)

@aaronlevin
aaronlevin / reasonable.hs
Last active June 8, 2017 14:55
Reasonably Priced Monads in Haskell
-- | simple/basic Scala -> Haskell translation of Runar's presentation
-- | (https://dl.dropboxusercontent.com/u/4588997/ReasonablyPriced.pdf)
-- | trying to use minimal extensions and magic.
-- | (earlier I had a version using MultiParamTypeClasses for Runar's
-- | Inject class, but scraped it opting for simplicity)
-- | my question: what do we lose by moving towards simplicity?
-- | Future work: use DataKinds, TypeOperators, and potentially TypeFamilies
-- | to maintain and automate the folding of types in Coproduct.
{-# LANGUAGE Rank2Types, DeriveFunctor #-}
@aaronlevin
aaronlevin / applicative-profiling.hs
Last active August 29, 2015 14:05
Applicatives for Profiling, Profit, and Fun
import Control.Applicative((<*>), Applicative, pure)
import Control.Monad.IO.Class (liftIO, MonadIO)
import Control.Monad.RWS.Strict (RWST, runRWST, tell)
import Control.Monad.State (get, modify)
import Data.List.NonEmpty (NonEmpty((:|)), (<|), nonEmpty)
import qualified Data.List.NonEmpty as NE
import Data.Maybe (fromMaybe)
import System.Clock (Clock (Monotonic), getTime, nsec)
data Profiler m a = Profiler { item :: m a
@aaronlevin
aaronlevin / common_util.sh
Last active December 10, 2018 05:14
Example scaffolding and helpers for bash scripts
#!/bin/bash
###############################################################################
# Helpers #
###############################################################################
# `is_set` accepts a function and checks if a variable is set.
# The function it accepts should generate a string for an error
# message
is_set() {

Keybase proof

I hereby claim:

  • I am aaronlevin on github.
  • I am aaronlevin (https://keybase.io/aaronlevin) on keybase.
  • I have a public key whose fingerprint is 361D 2CBF 9220 F7AE 23C6 BC06 7469 9ED5 2D47 D396

To claim this, I am signing this object:

@aaronlevin
aaronlevin / build.sh
Last active August 29, 2015 14:10
baby's first javascript fail
#!/bin/bash
browserify main.hs -o bundle.js
@aaronlevin
aaronlevin / mp3s.html
Created December 8, 2014 16:11
audio markup for weird canada posts december 8
<!-- TV FREAKS MP3s -->
<audio controls="controls" class="audioTrack" preload="none">
<source src="https://s3.amazonaws.com/wc-tracks/Weird_Canada-TV_Freaks-Leeches.ogg" type='audio/ogg; codecs="vorbis"' />
<source src="https://s3.amazonaws.com/wc-tracks/Weird_Canada-TV_Freaks-Leeches.mp3" type='audio/mpeg; codecs="mp3"' />
</audio>
<p class="audioTrack"><a href="https://s3.amazonaws.com/wc-tracks/Weird_Canada-TV_Freaks-Leeches.mp3" target="_blank">TV Freaks - Leeches</a></p>
<audio controls="controls" class="audioTrack" preload="none">
<source src="https://s3.amazonaws.com/wc-tracks/Weird_Canada-TV_Freaks-Lose_It.ogg" type='audio/ogg; codecs="vorbis"' />
@aaronlevin
aaronlevin / free-type-level-crud.hs
Last active August 29, 2015 14:11
Free Type-Level CRUD
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeFamilies #-}
module Main where
import Control.Monad.Free (Free (Free, Pure))