Skip to content

Instantly share code, notes, and snippets.

View mather's full-sized avatar
🐻
friendly bear

Eisuke Kuwahata mather

🐻
friendly bear
View GitHub Profile
@mather
mather / 0_reuse_code.js
Created December 19, 2013 06:59
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
$ brew install pari
@mather
mather / Enum.scala
Last active January 4, 2016 09:19
scala.EnumerationをJavaから使う場合
/*
* scalac Enum.scala
*/
/**
* Define Signal Enumeration
*/
object Signal extends Enumeration {
val Green = Value //=> Val(0, "Green")
@mather
mather / file0.scala
Created January 29, 2014 12:03
traitのmix-inと依存性注入について(備忘録) ref: http://qiita.com/mather314/items/d0165374f657e42c35e0
trait Greeter {
def greetTo(to: String): String
}
class HelloGreeter(name: String) extends Greeter {
def greetTo(to: String) = s"${name} says 'Hello ${to}!'"
}
new HelloGreeter("Alice").greetTo("Bob") //=> Alice says 'Hello Bob!'
@mather
mather / Main.java
Created January 30, 2014 02:24
Scalaの列挙型をJavaから参照してみる ref: http://qiita.com/mather314/items/9c0e58578597e264c41d
public class Main {
public static void main(String[] args) {
// Signal class
System.out.println(Signal.class.toString());
// Signal$ class (Signal.type @ Scala)
System.out.println(Signal$.class.toString());
// Signal singleton object
Signal$ obj = Signal$.MODULE$;
@mather
mather / gist:8778065
Created February 3, 2014 02:27
Scalaで単体とコレクションを透過的に扱う
sealed abstract class MailList {
// コレクションとして扱うための抽象メソッド
def +(mailbox: Mailbox): MailList
// 別の型に変換するなどの処理
def publish: String = this match {
case Mailbox(str) => str
case MailboxList(list) => list.map(_.publish).mkString(",")
}
}
@mather
mather / file0.scala
Created February 5, 2014 05:48
Parser CombinatorでIPアドレスのチェック ref: http://qiita.com/mather314/items/dfa76148270f10bbad95
import java.net.{InetAddress,UnknownHostException}
import util.parsing.combinator.RegexParsers
object IpParsers extends RegexParsers {
def ipAddress: Parser[String] = """[0-9a-fA-F:\.]+""".r.withFilter { str =>
try {
val addr = InetAddress.getByName(str)
true
} catch {
case e: UnknownHostException => false
require 'formula'
class Jhcal < Formula
homepage 'http://www2.tokai.or.jp/y_okamon/myfreesoft/jhcal/jhcal.html'
url 'http://www2.tokai.or.jp/y_okamon/myfreesoft/jhcal/jhcal-2.0.tar.gz'
sha1 'ae09d530c3e89da8624245f95378a7991b597101'
def install
system "make"
bin.install "jhcal"
@mather
mather / A.java
Last active August 29, 2015 13:57
Scalaでは定数を含むインターフェースの継承クラスから定数を取得できない…
public interface A {
public static final String C = "hoge";
}
class MyException(message: String = null, cause: Throwable = null) extends RuntimeException(message, cause) {
def this(cause: Throwable) = this(Option(cause).map(_.toString).getOrElse(null), cause)
}