Skip to content

Instantly share code, notes, and snippets.

View tpolecat's full-sized avatar
🔥
Dijkstra would not have liked this.

Rob Norris tpolecat

🔥
Dijkstra would not have liked this.
View GitHub Profile
import scala.annotation.tailrec
object Crap extends App {
val BASE = 16
val DIGITS = "0123456789ABCDEF"
// Original
def encode0(number: BigInt): String = {
require(number > 0, "number must not be negative")
trait FrontendRoutes extends ScalatraServlet with ScalateSupport {
val db: Database
get("/") {
contentType = "text/html"
ssp("/index")
}
get("/matches") {
db withSession {
val q3 = for {
cookie:c rnorris$ cat > foo.scala
class Foo(bar: Object) {
val milk = bar
def water = milk
def braun = bar
}
cookie:c rnorris$ scalac foo.scala
lambda = Lpr + 6.288750 * sin(Mpr)
+ 1.274018 * sin(2*D - Mpr)
+ 0.658309 * sin(2*D)
+ 0.213616 * sin(2*Mpr)
- e * 0.185596 * sin(M)
- 0.114336 * sin(2*F)
+ 0.058793 * sin(2*D - 2*Mpr)
+ e * 0.057212 * sin(2*D - M - Mpr)
+ 0.053320 * sin(2*D + Mpr)
+ e * 0.045874 * sin(2*D - M)
@tpolecat
tpolecat / gist:5672105
Last active December 17, 2015 21:08
making scala stm look like haskell stm
package util
import scalaz.effect.IO
import scalaz._
import Scalaz._
import scala.concurrent.stm.{ retry => stmRetry, _ }
object X {
type STM[+A] = ReaderT[IO, InTxn, A]
scala> import Ordering.Implicits._
import Ordering.Implicits._
scala> :pa
// Entering paste mode (ctrl-D to finish)
case class A(n:Int, s:String)
object A {
implicit val ord = Ordering.by(unapply)
}
class A(n:Int) {
println(n)
}
cookie:tmp rnorris$ javap -classpath . A
Compiled from "test.scala"
public class A extends java.lang.Object{
public A(int);
}
@tpolecat
tpolecat / gist:5633028
Last active December 17, 2015 15:39
Ideas re: IO and Future
// Some thoughts on IO and Futures
object Future {
// A future must have the option of performing IO during its computation; this
// is one of the primary uses of Futures. So we construct with an IO[A]. Construction
// is itself an effect because it forks execution of `a`.
def ioFuture[A](a: IO[A]): IO[Future[A]]
// Unit, but it has to be eager, so not super useful. What if it's not really a monad at all?
object Marrrk {
trait AccessibilityNodeInfo {
def getChildCount: Int
def getChild(n: Int): AccessibilityNodeInfo
def getClassName: String
def performAction(a: Any): Boolean
}
object AccessibilityNodeInfo {
def children(n: AccessibilityNodeInfo): List[AccessibilityNodeInfo] =
(0 until n.getChildCount).toList.map(n.getChild)
def linearize(n: AccessibilityNodeInfo): List[AccessibilityNodeInfo] =
n :: children(n).flatMap(linearize)
def getCertainClass(ani: AccessibilityNodeInfo, className: String, occurrence: Int): Option[AccessibilityNodeInfo] =
linearize(ani).filter(_.getClassName == className).lift(occurrence)