Skip to content

Instantly share code, notes, and snippets.

Avatar

Junichi Kato j5ik2o

View GitHub Profile
@j5ik2o
j5ik2o / gist:948435
Created Apr 29, 2011
filterを命令型と関数型で比較
View gist:948435
import collection.mutable.ListBuffer
// 命令型で書いた場合
val filtered = new ListBuffer[Int]
val numbers = List(1,2,3,4,5)
for(n <- numbers){
if (n % 2 == 0){
filtered += n
}
}
@j5ik2o
j5ik2o / gist:948467
Created Apr 29, 2011
findを命令型と関数型で比較
View gist:948467
case class Car(name: String, color: String)
def find(name: String, cars: List[Car]): Option[Car] = {
for (car <- cars) {
if (car.name == name) {
return Some(car)
}
}
None
}
@j5ik2o
j5ik2o / fizzBuzz.md
Created Apr 29, 2011
FizzBuzzを命令型と関数型で比較
View fizzBuzz.md

命令型で記述。

for (n <- 1 to 100) {
  if (n % 15 == 0) {
    println("FizzBuzz")
  } else if (n % 3 == 0) {
    println("Fizz")
  } else if (n % 5 == 0) {
    println("Buzz")
  } else {
@j5ik2o
j5ik2o / gist:950158
Created May 1, 2011
sbt-ideaの設定方法
View gist:950158
// 1. $PROJECT_ROOT/project/build/MyProject.scalaを作る。IdeaProjectをミックスインする。
import sbt._
class MyProject(info: ProjectInfo) extends DefaultProject(info) with IdeaProject{
}
// 2. $PROJECT_ROOT/project/plugins/Plugins.scalaを以下のように作る。
import sbt._
View gist:950451
pom.xmlの中身
<?xml version='1.0' encoding='UTF-8'?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>jp.tricreo.scala</groupId>
<artifactId>scala-ddd-base_2.8.1</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>
...
@j5ik2o
j5ik2o / gist:950506
Created May 1, 2011
sbtでversionが-SNAPSHOTの場合にpublishToをsnapshotに切り替える方法
View gist:950506
import sbt._
class MyProject(info: ProjectInfo) extends DefaultProject(info) {
override def managedStyle = ManagedStyle.Maven
// publishing
lazy val publishTo = if (version.toString.endsWith("-SNAPSHOT")){
println("Selected Snapshot")
Resolver.sftp("Tricreo Repo", "maven.tricreo.jp", "/var/www/maven.tricreo.jp/snapshot")
@j5ik2o
j5ik2o / gist:970362
Created May 13, 2011
JavaでRangeオブジェクト的ななにか
View gist:970362
package util;
import java.io.Serializable;
import java.util.Iterator;
public class Range implements Iterable<Integer>, Serializable, Cloneable {
private static class RangeIterator implements Iterator<Integer> {
final int start;
@j5ik2o
j5ik2o / gist:1037873
Created Jun 21, 2011
列挙型っぽいもの
View gist:1037873
import collection.mutable.ListBuffer
/**列挙型定数を表すトレイト。
*
* @author j5ik2o
*/
trait EnumEntry extends Serializable with Ordered[EnumEntry] {
/**列挙定数の序数 (列挙宣言での位置)。 */
private[util] var ordinalNo: Int = _
@j5ik2o
j5ik2o / maven3.rb
Created Jun 26, 2011
HomebrewでMaven2とMaven3を共存させるためのFormula(Maven3)
View maven3.rb
require 'formula'
class Maven3 < Formula
url 'http://www.apache.org/dist/maven/binaries/apache-maven-3.0.3-bin.tar.gz'
homepage 'http://maven.apache.org/'
md5 '507828d328eb3735103c0492443ef0f0'
def install
# Remove windows files
rm_f Dir["bin/*.bat"]
@j5ik2o
j5ik2o / maven2.rb
Created Jun 26, 2011
HomebrewでMaven2とMaven3を共存させるためのFormula(Maven2)
View maven2.rb
require 'formula'
class Maven2 < Formula
url 'http://www.apache.org/dist/maven/binaries/apache-maven-2.2.1-bin.tar.gz'
homepage 'http://maven.apache.org/'
md5 '3f829ed854cbacdaca8f809e4954c916'
def install
rm_f Dir["bin/*.bat"]