Skip to content

Instantly share code, notes, and snippets.

@paulp
paulp / gist:9081797
Created February 18, 2014 22:29
Classic.
scala> val buf = ListBuffer(1)
buf: scala.collection.mutable.ListBuffer[Int] = ListBuffer(1)
scala> val xs = buf.toIterable match { case xs: List[Int] => xs }
xs: List[Int] = List(1)
scala> buf ++= 1 to 100
res11: buf.type = ListBuffer(1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100)
scala> xs
import Web.Scotty.Trans
import Network.Wai.Middleware.RequestLogger
import Network.Wai.Middleware.Static
import Text.Blaze.Html.Renderer.Text (renderHtml)
import System.Environment
import Database.Persist.Sql (SqlPersistT(..), Connection, runMigration, runSqlPersistM, runSqlConn, unSqlPersistT)
import Database.Persist.Postgresql (withPostgresqlConn)
setup :: ScottyT Text (SqlPersistT (NoLoggingT (ResourceT IO))) () -> IO ()
setup m = do
import scala.util.control.Exception
import scalaz._
import scalaz.Free.FreeC
import scalaz.Scalaz._
object Kasten {
/////////////////////////
// The State stuff
/////////////////////////
@runarorama
runarorama / gist:9422453
Last active August 29, 2015 13:57
Suggestion for the new representation of `IO` in Scalaz.
import scalaz._
import \/._
import Free._
import scalaz.syntax.monad._
import java.util.concurrent.atomic.AtomicReference
import java.util.concurrent.CountDownLatch
object Experiment {
sealed trait OI[A] {
def map[B](f: A => B): OI[B]
@bmjames
bmjames / gist:9669467
Created March 20, 2014 17:37
Comparing Scala's List#map to Haskell's map
-- http://hackage.haskell.org/package/base-4.6.0.1/docs/src/GHC-Base.html#map
map :: (a -> b) -> [a] -> [b]
map _ [] = []
map f (x:xs) = f x : map f xs
@jstrachan
jstrachan / gist:f960917b4861f30a8a45
Last active August 29, 2015 14:02
names your iTerm2 tab after the current working directory, shows the path in the prompt and the git branch
# thanks to this gist for the iTerm2 tab naming stuff: https://gist.github.com/phette23/5270658
# can't remember where I cribbed the rest of this from!
# hacked it a bit to work on OS X
_bold=$(tput bold)
_normal=$(tput sgr0)
__vcs_dir() {
local vcs base_dir sub_dir ref
sub_dir() {
@wrwills
wrwills / OptionGolf.scala
Created October 8, 2010 14:19
applicative_example
import scalaz._
/**
* A simple example of how applicative functors can shorten code
* adapted from chapter 8? of Real World Haskell
*/
object OptionGolf {
@softprops
softprops / murder.sh
Created November 3, 2010 05:39 — forked from defunkt/murder.sh
# sh function to murder all running processes matching a pattern
# thanks 3n: http://twitter.com/3n/status/19113206105
murder () {
ps | grep $1 | grep -v grep | awk '{print $1}' | xargs kill -9
}
@softprops
softprops / browser
Created November 9, 2010 04:14 — forked from defunkt/browser
#!/bin/sh -e
#
# Usage: browser
# pipe html to a browser
# e.g.
# $ echo "<h1>hi mom!</h1>" | browser
# $ ron -5 man/rip.5.ron | browser
if [ -t 0 ]; then
if [ -n "$1" ]; then
// for comprehension
scala> for {
| l <- List(2,5,10)
| m <- List(8,10,11)
| } yield l * m
res17: List[Int] = List(16, 20, 22, 40, 50, 55, 80, 100, 110)
// map a pure function into applicatives
scala> List(8,10,11) <*> (List(2,5,10) map (((_: Int) * (_: Int)).curried))
res18: List[Int] = List(16, 20, 22, 40, 50, 55, 80, 100, 110)