Skip to content

Instantly share code, notes, and snippets.

anonymous
anonymous / Haskell
Created October 7, 2013 19:22
Comparison of the straightforward embedding of a basic tenet of category theory in Scala vs Haskell.
yonedaLemma = Iso (flip fmap) ($ id)
@milessabin
milessabin / gist:6397262
Created August 31, 2013 09:47
Case classes to records in shapeless-2.0.0-M1.
scala> import shapeless._, syntax.singleton._, record._
import shapeless._
import syntax.singleton._
import record._
scala> object mkField extends Poly1 { implicit def default[K, V] = at[(K, V)]{ case (k, v) => field[K](v) } }
defined module mkField
scala> case class Person(name: String, age: Int, location: Option[String])
defined class Person
@milessabin
milessabin / gist:6166101
Created August 6, 2013 16:26
Encoding records in #Scala as an HList of values tagged with the singleton types of their keys.
scala> import SingletonTypes._ ; import Record._
import SingletonTypes._
import Record._
scala> val r = "name" ->> "foo" :: "age" ->> 1 :: "lastName" ->> "bar" :: HNil
r: shapeless.::[String with Object{type keyType = String("name")},shapeless.::[Int with Object{type keyType = String("age")},shapeless.::[String with Object{type keyType = String("lastName")},shapeless.HNil]]] = foo :: 1 :: bar :: HNil
@pchiusano
pchiusano / profile.scala
Created August 1, 2013 01:04
Some informal scalaz-stream performance testing code.
package scalaz.stream
import scalaz.concurrent.Task
import scalaz.syntax.traverse._
import scalaz.std.list._
import Process.Process1
import collection.immutable.{IndexedSeq, Vector}
object profile extends App {
@milessabin
milessabin / gist:6015989
Last active December 19, 2015 20:49
Selecting type class instances by singleton types of values.
scala> import shapeless._
import shapeless._
scala> import SingletonTypes._
import SingletonTypes._
scala> :paste
// Entering paste mode (ctrl-D to finish)
trait Show[T] {
@eyston
eyston / controller.js
Created June 24, 2013 17:11
angular typeahead
angular.module('ymusica').controller('AlbumSearch', ['$scope', 'Albums', 'Artists', '$q', function($scope, albums, artists, $q) {
$scope.albums = [];
$scope.artists = [];
var terms = new Rx.Subject();
$scope.searchMusic = terms.onNext.bind(terms);
terms.sample(250)
@ErikAndreas
ErikAndreas / 0background.md
Last active December 18, 2015 16:49
Proof of concept of full stack and tooling for AngularJS i18n gettext-style using Jed, pybabel and po2json. UPDATE: will now be maintained at https://github.com/ErikAndreas/lingua and tooling at https://github.com/ErikAndreas/grunt-lingua

Been looking for a full stack including tools for gettext-style i18n with AngularJS.

  • Gettext-style support in markup (html and javascript) supporting singular, plural and interpolation/sprintf
  • Tooling for extraction of strings to be translated (to .pot) from html and javascript
  • Tooling for generating .json of .po files

Ended up (working proof of concept) with the following:

  • "lingua", an AngularJS module wrapping Jed
  • Some AngularJS bootstrapping
  • pybabel for xgettext style translations extraction (to .pot)
  • po2json for generating .json files (per translation) from .po files
@cartazio
cartazio / HBound.hs
Created June 7, 2013 05:18
Higher order bound http://hpaste.org/73764 hpaste by kmett
{-# LANGUAGE GADTs, Rank2Types, KindSignatures, ScopedTypeVariables, TypeOperators, DataKinds, PolyKinds, MultiParamTypeClasses, FlexibleInstances, TypeFamilies, DoRec, ExtendedDefaultRules #-}
import Control.Applicative
import Control.Category
import Control.Comonad
import Control.Monad.Fix
import Control.Monad (ap)
import Data.Functor.Identity
import Data.Typeable
import Data.Monoid
import Data.Unique
@tonymorris
tonymorris / Rng.scala
Last active December 17, 2015 18:48
How to produce random function values (Rng[B => A])?
sealed trait RngOp[A] {
def map[B](f: A => B): RngOp[B] =
this match {
case NextBits(b, n) => NextBits(b, f compose n)
case SetSeed(b, n) => SetSeed(b, () => f(n()))
}
def lift: Rng[A] =
Cont(map(Done(_)))
}
@aaronwolen
aaronwolen / slides.md
Last active November 11, 2022 23:57
Pandoc template to generate reveal.js slideshows.

% Title % Name % Date

My first slide

List