Skip to content

Instantly share code, notes, and snippets.

max@sordid ~/work/FS2005 % ls -l
total 23952
-rwxr-xr-x+ 1 max staff 12258304 Mar 7 15:31 FSharp.Compiler.Service.dll
-rw-r--r--+ 1 max staff 157 Mar 7 15:31 test.fsx
max@sordid ~/work/FS2005 % cat test.fsx
#r "FSharp.Compiler.Service.dll"
open Microsoft.FSharp.Compiler.SimpleSourceCodeServices
let scs = SimpleSourceCodeServices()
printfn "Hello, world! %A" scs
max@sordid ~/work/FS2005 % fsharpc --standalone -I:. -o test.exe test.fsx
@maxaf
maxaf / tagged_actor_refs.scala
Created December 18, 2012 20:20
Tagged types help ease ActorRef confusion.
// Mock Akka in the absence of artifacts. Don't pay attention to this
// part. Oh, and I'm stuck in Akka 1.3.x land, so some of this may
// look "retro" to you.
trait ActorRef {
def !(msg: Any) {}
}
trait Actor {
def self: ActorRef = new ActorRef {}
@maxaf
maxaf / innocuous.scala
Created July 10, 2012 15:00
scalac LOL
object Foo {
def foo(x: Int, y: Int = 10) = x*y
lazy val y = foo(x = 20)
}
// innocuous.scala:3: error: variable definition needs type because 'y' is used as a named argument in its body.
// Error occurred in an application involving default arguments.
//
@maxaf
maxaf / blue_in_the_face.scala
Created December 26, 2011 08:13
Strange/unexpected unsafePerformIO behavior
import scalaz._
import Scalaz._
import scalaz.effects._
val a = println("a here").pure[IO]
val b = println("b here").pure[IO]
val c = a.flatMap(_ => b.flatMap(_ => println("c here").pure[IO]))
c.unsafePerformIO // prints 3 lines as expected
c.unsafePerformIO // expect 0 lines to be printed, but...
c.unsafePerformIO // and again...
c.unsafePerformIO // again...
@maxaf
maxaf / gist:1417961
Created December 1, 2011 16:25 — forked from anonymous/gist:1406238
THIS IS FUD. GET BACK TO WORK NOW.
Originally:
https://gist.github.com/7565976a89d5da1511ce
Hi Donald (and Martin),
Thanks for pinging me; it's nice to know Typesafe is keeping tabs on this, and I
appreciate the tone. This is a Yegge-long response, but given that you and
Martin are the two people best-situated to do anything about this, I'd rather
err on the side of giving you too much to think about. I realize I'm being very
critical of something in which you've invested a great deal (both financially
#!/usr/bin/env perl
use strict;
use HTTP::Proxy qw/:log/;
use Time::HiRes qw/time/;
use HTTP::Proxy::BodyFilter::save;
my $DIR = '/home/max/Music/Pandora';
$DIR =~ s/\/+$//;
die "no dir $DIR" unless -d $DIR;
@maxaf
maxaf / UglyHacks.scala
Created July 8, 2011 12:24
come smell my desperation
object UglyHacks {
implicit def screwEncapsulation(o: AnyRef) = new {
private def field(fieldName: String) = {
val field = o.getClass.getDeclaredField(fieldName)
field.setAccessible(true)
field
}
def shoeHorn(fieldName: String, fieldValue: Any) = field(fieldName).set(o, fieldValue)
scala> def isEven(i: Int): Boolean = { println("checking %d".format(i)); i % 2 == 0 }
isEven: (i: Int)Boolean
scala> val pf: PartialFunction[Int, Boolean] = { case i if isEven(i) => { println("%d is even".format(i)); true } }
pf: PartialFunction[Int,Boolean] = <function1>
scala> pf.isDefinedAt(0)
checking 0
res0: Boolean = true
1. Dump contents of http://www.w3.org/2003/05/soap-envelope/ to soap12.xsd
and put that somewhere alongside the other schemas.
2. Run scalaxb, you'll end up with a soap12.scala & company.
3. See sample code. Call envXml and get back XML representation of envelope,
header, and body all in one.
trait X
case class A(i: Int) extends X
case class B(i: Int) extends X
implicit def int2a(i: Int): A = A(i)
implicit def int2b(i: Int): B = B(i)
implicit def int2x(i: Int)(implicit multiplier: Int): X =
if (System.currentTimeMillis % 100 == 0) A(i * multiplier) else B(i * multiplier)