This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.util.control.Exception | |
import scalaz._ | |
import scalaz.Free.FreeC | |
import scalaz.Scalaz._ | |
object Kasten { | |
///////////////////////// | |
// The State stuff | |
///////////////////////// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scalaz._ | |
/** | |
* A simple example of how applicative functors can shorten code | |
* adapted from chapter 8? of Real World Haskell | |
*/ | |
object OptionGolf { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) |
OlderNewer