Skip to content

Instantly share code, notes, and snippets.

class Matrix extends Function2[Int, Int, Float] {
import Matrix.{ width, height }
private val e = new Array[Float](width * height)
def apply(row : Int, col : Int) = e(row * width + col)
def update(row : Int, col : Int, value : Float) { e(row * width + col) = value }
def initializeWith(f : (Int, Int) => Float) = {
for {
row <- 0 until height
@kxbmap
kxbmap / gist:653279
Created October 29, 2010 10:15
NEWT Window
import javax.media.opengl.{ GLAutoDrawable, GLProfile, GLCapabilities, GLEventListener }
import com.jogamp.newt.event.{ WindowAdapter, WindowEvent }
import com.jogamp.newt.opengl.GLWindow
import com.jogamp.opengl.util.FPSAnimator
object NewtSample {
def main(args : Array[String]){
GLProfile.initSingleton()
run()
}
#!/bin/sh
exec scala -deprecation `cygpath -m $0` "$@"
!#
object CreateProject {
import scala.util.control.Exception._
def usage() {
println("create_project <name> <pkg> [--scala-version <version>] " +
"[--android] " +
@kxbmap
kxbmap / KeyValue.scala
Created March 20, 2011 19:28
ポリモーフィズムで再帰的なXMLを生成する
package com.example.kvxml2
import _root_.scala.xml.{Elem, MetaData, Node, NodeSeq, Null, Text, TopScope, UnprefixedAttribute}
sealed abstract class Value {
def nodes: NodeSeq
}
case class StringValue(str: String) extends Value {
@kxbmap
kxbmap / KeyValue.scala
Created March 20, 2011 19:34
case class + パターンマッチングで再帰的なXMLを生成する
package com.example.kvxml
import _root_.scala.xml.{Elem, MetaData, Node, NodeSeq, Null, Text, TopScope, UnprefixedAttribute}
sealed abstract class Value
case class StringValue(str: String) extends Value
case class ValueSeq(seq: Seq[Value]) extends Value
case class KeyValue(key: String, attributes: Map[String, String], value: Value) extends Value {
def this(key: String, value: Value) = this(key, Map.empty, value)
@kxbmap
kxbmap / MongoEnumNameMapField.scala
Created March 24, 2011 09:33
LiftでMongoDBにEnumeration#ValueをキーにしたMapを格納する net.liftweb.mongodb.Metaがprivate[mongodb]なのでLiftのパッケージ。。
package net.liftweb.mongodb.record.field
import _root_.net.liftweb.common.{Failure, Empty, Box, Full}
import _root_.net.liftweb.json.JsonAST.{JValue, JObject, JField, JNothing, JNull}
import _root_.net.liftweb.json.JsonParser
import _root_.net.liftweb.record.{Field, MandatoryTypedField, FieldHelpers}
import _root_.net.liftweb.mongodb.record.MongoRecord
import _root_.net.liftweb.util.Helpers.tryo
import _root_.com.mongodb.{BasicDBObject, DBObject}
package com.example.hellojocl
import java.nio.FloatBuffer
import util.Random
import com.jogamp.opencl.{CLBuffer, CLContext}
class HelloJOCL(ctx: CLContext) {
import HelloJOCL._
@kxbmap
kxbmap / gist:921241
Created April 15, 2011 06:24
Scala2.8.1でList[java.util.Date].min
scala> trait DateOrdering extends scala.math.Ordering[java.util.Date] {
| def compare(x: java.util.Date, y: java.util.Date) = x.compareTo(y)
| }
defined trait DateOrdering
scala> implicit object Date extends DateOrdering
defined module Date
scala> List(new java.util.Date()).min
res6: java.util.Date = Fri Apr 15 15:16:18 JST 2011
package sample.plugin.google
import com.intellij.openapi.actionSystem.{PlatformDataKeys, AnAction, AnActionEvent}
import com.intellij.ide.BrowserUtil
import java.io.UnsupportedEncodingException
import java.net.URLEncoder
import scala.util.control.Exception._
class GoogleSearchAction extends AnAction {
@kxbmap
kxbmap / Sample
Created December 10, 2011 06:22
Scalazのminimum/maximumならOptionが返るから安心
object Sample extends App {
val seq = Seq(1, 2, 3)
val empty = Seq[Int]()
println(seq.max) // -> 3
// println(empty.max) // -> java.lang.UnsupportedOperationException: empty.max
import scalaz._, Scalaz._