Skip to content

Instantly share code, notes, and snippets.

@Grab(group='org.gparallelizer', module='gparallelizer', version='0.8.4')
import org.gparallelizer.Asynchronizer
output={msg,i,j->
println "${msg}:${i}:${j}"
}
echo={msg,i->println"$msg:$i"
for(int j=0;j<10;j++){
@wfaler
wfaler / BowlerProject.scala
Created January 16, 2011 22:40
Bowler SBT Project File
import sbt._
class BowlerProject(info: ProjectInfo) extends DefaultWebProject(info){
val bowler = "org.bowlerframework" %% "core" % "0.5.1"
val slf4jVersion = "1.6.0"
val sfl4jnop = "org.slf4j" % "slf4j-nop" % slf4jVersion % "runtime"
// allows you to use an embedded/in-JVM jetty-server to run unit-tests.
@woodie
woodie / Test.java
Created January 20, 2011 18:28
Hello Mirah
// Generated from test.mirah
public class Test extends java.lang.Object {
public static void main(java.lang.String[] argv) {
int __xform_tmp_1 = 0;
int __xform_tmp_2 = 0;
int i = 0;
__xform_tmp_1 = 1;
__xform_tmp_2 = 5;
label1:
while ((__xform_tmp_1 <= __xform_tmp_2)) {
@chimerast
chimerast / StaticCallGraphScanner.java
Created March 24, 2011 03:53
scala-library.jarをJavassistで走査して並列化されているメソッドを探します
package org.karatachi.javassist;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Set;
@yuroyoro
yuroyoro / DynamicTest.scala
Created March 26, 2011 06:51
scala2.9.0.RC1でのDynamicのテスト
[0]ozaki@mbp $ scala -Xexperimental [~/sandbox/scala/work][0]
Picked up _JAVA_OPTIONS: -Dfile.encoding=UTF-8
Welcome to Scala version 2.9.0.RC1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_22).
Type in expressions to have them evaluated.
Type :help for more information.
scala> trait DI extends Dynamic {
| def applyDynamic(name:String)(args:Any*):Any = println("Hello, %s %s" format( name, args.mkString("[", ", ", "]")))
| }
defined trait DI
@jorgeortiz85
jorgeortiz85 / PrivateMethodCaller.scala
Created April 7, 2011 15:41
Calling private methods in Scala
// Usage:
// p(instance)('privateMethod)(arg1, arg2, arg3)
class PrivateMethodCaller(x: AnyRef, methodName: String) {
def apply(_args: Any*): Any = {
val args = _args.map(_.asInstanceOf[AnyRef])
def _parents: Stream[Class[_]] = Stream(x.getClass) #::: _parents.map(_.getSuperclass)
val parents = _parents.takeWhile(_ != null).toList
val methods = parents.flatMap(_.getDeclaredMethods)
val method = methods.find(_.getName == methodName).getOrElse(throw new IllegalArgumentException("Method " + methodName + " not found"))
@halcat0x15a
halcat0x15a / gist:955212
Created May 4, 2011 13:31
clojureでscala.Function*を作る。
(defmacro sfn [params expr]
`(proxy [~(symbol (str "scala.Function" (count params)))] []
(apply ~params
~expr)))
@jorgeortiz85
jorgeortiz85 / FoldUnion.scala
Created June 9, 2011 17:11
Folding over Scala union types
type ¬[A] = A => Nothing
type ∨[T, U] = ¬[¬[T] with ¬[U]]
type ¬¬[A] = ¬[¬[A]]
type |∨|[T, U] = { type λ[X] = ¬¬[X] <:< (T ∨ U) }
class FoldUnion[T](t: T) {
def boxClass(x: java.lang.Class[_]): java.lang.Class[_] = x.toString match {
case "byte" => manifest[java.lang.Byte].erasure
case "char" => manifest[java.lang.Character].erasure
case "short" => manifest[java.lang.Short].erasure
@halcat0x15a
halcat0x15a / JValue.scala
Created July 6, 2011 11:34
Real World Haskellを参考にJSONを表現してみた。
package json
sealed abstract class JValue[+A](value: A)
case class JString(value: String) extends JValue(value) {
override def toString = "\"" + value + "\""
}
// see https://github.com/gseitz/Lensed
object Lensed {
import scalaz._
import Scalaz._
case class Address(street: String)
case class Person(name: String, address: Address)