Skip to content

Instantly share code, notes, and snippets.

View mads-hartmann's full-sized avatar

Mads Hartmann mads-hartmann

View GitHub Profile
@mads-hartmann
mads-hartmann / Path intergral
Created March 31, 2010 17:56
Coding is a social activity - This was coded by me and a friend some lazy afternoon while drinking beer. This is a script which calculates the path integral for a function (does so horrible wrong now though).
import java.math._
def calculatePoints(xvals: List[Double], func: Double=> (Double,Double) ) = xvals.map{ x => func(x)}
def calculateLengthOfPoints(points: List[(Double,Double)], length: Double): Double = {
def distance(p1: (Double,Double), p2: (Double,Double)) =
Math.sqrt(Math.pow(p2._1-p1._1,2)+Math.pow(p2._2-p1._2,2))
points match {
case Nil => length
case point::rest if rest == Nil => calculateLengthOfPoints(rest, length)
package code.comet
import scala.xml.{NodeSeq, Text}
import net.liftweb._
import http._
import actor._
import http.js._
import JsCmds._
import JE._
import java.util.Date
@mads-hartmann
mads-hartmann / TemplateDSL.scala
Created July 27, 2010 11:37
My attempt at creating a DSL for one of my projects. Something gone wrong though.
/*==============================================================================================
| All the classes in this file are used to built the Tempalte DSL. That means
| stuff like:
|
| injectContentsOfFile "path/to/file" into "myfile.txt" atPoint "MyPoint"
|
| HOWEVER currently I have to write it like this:
|
| injectContentsOfFile("src/test/resources/user_inject_Model_Point.txt").into("src/test/resources/model.txt").at("Point")
|
package com.sidewayscoding
import sbt._
import org.lifty.engine._
// the processor
class Processor extends SBTTemplateProcessor {
def templates = MyTemplate :: Nil
}
import sbt._
class SampleSBTProcessor(info: ProjectInfo) extends ProcessorProject(info) {
val scalatools_snapshots = ScalaToolsSnapshots
val lifty_engine = "org.lifty" %% "lifty-engine" % "0.6.1"
}
<%@ var name:String %>
Hello ${name}
object MyOtherTemplate extends Template with Create {
def name = "goodbye"
def description = "Creates a file with a greeting and farewell in it"
def arguments = Argument("word") :: Nil
def files = Nil
<%@ var name:String %>
Hello ${name}
//#inject point: farewell
<%@ var word:String %>
So Long, and Thanks for All the ${word}
import sbt._
class Project(info: ProjectInfo) extends DefaultProject(info)
{
lazy val sctags = compileWithSctags
protected def compileWithSctags = task {
val compilerConfig = new MainCompileConfig {
override def baseCompileOptions = CompileOption("-Xplugin:sctags_2.8.0.Beta1-RC2-1.0.jar") :: super.baseCompileOptions.toList